Just as the squirrel counterattack starts you wake up to the noise of your alarm clock ringing beside your bed. You feel sweat rolling down your back and trembling plagues your hands as a deep chill permeates throughout your body. What a weird dream!
To shake off the lingering aftereffects (you can't look at squirrels the same way anymore — they give off a threatening aura) you decide to visit your favourite competitive programming site (DMOJ of course) and join a contest from your favourite contest series (AAC of course) to do the last problem:
There are
If
, an edge is added between node and all the nodes present within the multisets numbered where . Then, node is added to all of these multisets. Output the value of the graph.If
, output the expected value of the graph if a node was chosen uniformly at random and an edge was added between it and all of the nodes present within the multisets numbered where . Afterwards, all of these multisets are cleared of nodes.
Constraints
Subtask 1 [10%]
Subtask 2 [40%]
There will only be queries of type
Subtask 3 [50%]
No additional constraints. This batch will only run if subtask
Input Specification
The first line will contain four space separated integers
The next
The next
Output Specification
Output
For queries of type
Sample Input
10 10 10 1
8 9
8 8 5
10 10 6
2 2 7
3 6 2
4 6 0
1 8 7
3 3 2
5 10 0
1 8 6
1 10 2
Sample Output
12
12
12
12
400000017
18
18
800000036
24
24
Comments