Lottery
문제
Jack spends a lot of time and money playing the lottery.
The lottery machine consists of parallel ramps (as shown on the figure). Each ramp is divided into sections of equal lengths. Under the ramps are baskets, each labeled with an integer.
The drawing works as follows. First some ramp sections from among the are removed. For each section, a -sided die (with the sides numbered ) is rolled and if the result is at most , the section is removed. After that, a ball is released from the top-left corner of the machine, above the topmost ramp. If the ball ends up in a basket, the player's prize is the amount written on the basket.
[이미지 1][이미지 2]
You try to explain to Jack that in general, he always loses money in such games. To prove your point, you want to compute the expected average value of the prize of this game.
It can be shown that the expected value can be expressed as where and are integers and is an irreducible fraction. Compute the value where is such an integer that .
입력
The first line contains space-separated integers and (), the dimensions of the lottery machine. The second line contains space-separated integers and (, ), the parameters of the die rolls.
The third line contains space-separated integers ( for each ), the values of the baskets from left to right.
출력
Output a single integer: the expected value of Jack's prize, in the format described above.
힌트
To format your output in this task, you need to compute such that (in our case, ). This number is called the inverse of modulo ; it can be shown that if and is prime, then can be computed as .
예제
예제 1
2 2 1 2 10 100
500000031
예제 2
2 4 2 5 1 2 3 4
483520005
예제 3
3 3 0 1 1 2 3
0
예제 4
3 3 1 1 1 2 3
1
예제 5
8 6 17536540 365964399 49 8 28 51 32 24
214402328