Sugar Sweet II
Time limit2sMemory limit2048 MB
Each child gains w_i when event i fires with fewer sugar than child b_i, events in random order; output each child's expected final sugar mod 1e9+7.
- Level
Hard9 of 10
- Topics
- Probability, Dynamic programming, Divide and conquer
- Solved
- No attempts yet
Statement
Sugar is sweet.
There are children asking for sugar. Prof. Chen gives sugar to the children. The -th child initially has bags of sugar.
There are events, happening in uniformly random order. The -th event is:
- If the -th child has strictly fewer bags of sugar than the -th child, the -th child gets extra bags of sugar. Otherwise, nothing happens.
Because the events happen in random order, Randias, Prof. Chen's assistant, wants the expected number of bags each child has after all events happen.
It can be shown that the answer is an irreducible fraction , where and are integers and . Output the integer . That is, output the integer with and .
Input
The first line contains (), the number of test cases. Each test case is given as follows.
The first line contains (), the number of children. The second line contains integers (). The third line contains integers (). The fourth line contains integers ().
The sum of over all test cases does not exceed .
Output
For each test case, print integers on one line: the expected number of bags each child has at the end, modulo as described above.