Sugar Sweet II
시간 제한2초메모리 제한2048 MB
n개의 이벤트가 무작위 순서로 일어나며, i번 아이가 b_i번 아이보다 사탕이 적으면 w_i개를 받는다. 모든 이벤트가 끝난 뒤 각 아이가 가질 사탕 수의 기댓값을 1e9+7로 나눈 나머지로 구한다.
문제
Sugar is sweet.
There are children asking for sugar. Prof. Chen gives out sugar to the children. The -th child initially has bags of sugar. There are events happening in uniformly randomized order. The -th event is:
- If the -th child has strictly less bags of sugar than the -th child, then the -th child will get extra bags of sugar. Otherwise, nothing happens.
Now, since the events happen in random order, Randias, which is the assistant of Prof. Chen, wants to know the expected number of bags of sugar each child will have after all the events happen.
It can be shown that the answer can be expressed as an irreducible fraction where and are integers and . Output the integer equal to . In other words, output such an integer that and .
입력
Each test contains multiple test cases. The first line contains a single interger () denoting the number of test cases. For each test case:
The first line contains a single integer () denoting the number of children.
The second line contains integers (): the initial number of bags of sugar each child has.
The third line contains integers ().
The fourth line contains integers ().
It is guaranteed that the sum of over all test cases does not exceed .
출력
For each test case, output integers in a line: the expected number of bags of sugar each child will get. Output the answers as integers modulo , as described above.