Lottery | 프로그래밍의 벗 PivotOJ
PivotOJ

Lottery

시간 제한: 2000ms메모리 제한: 1024MB출처: EIO 2020-21 finalBOJ 29903
이 문제는 본문 이미지 일부가 표시되지 않습니다. 텍스트만으로 풀이가 어려울 수 있습니다.

문제

Jack spends a lot of time and money playing the lottery.

The lottery machine consists of NN parallel ramps (as shown on the figure). Each ramp is divided into MM sections of equal lengths. Under the ramps are MM baskets, each labeled with an integer.

The drawing works as follows. First some ramp sections from among the NMN \cdot M are removed. For each section, a BB-sided die (with the sides numbered 1,,B1, \ldots, B) is rolled and if the result is at most AA, 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 pq\frac{p}{q} where pp and qq are integers and pq\frac{p}{q} is an irreducible fraction. Compute the value pr(109+7)pr \bmod (10^9 + 7) where rr is such an integer that qr(109+7)=1qr \bmod (10^9 + 7) = 1.

입력

The first line contains space-separated integers NN and MM (2N,M51052 \le N, M \le 5 \cdot 10^5), the dimensions of the lottery machine. The second line contains space-separated integers AA and BB (0AB<109+70 \le A \le B < 10^9 + 7, B0B \ne 0), the parameters of the die rolls.

The third line contains MM space-separated integers C1,C2,,CMC_1, C_2, \ldots, C_M (0Ci1090 \le C_i \le 10^9 for each ii), 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 rr such that qr1(modK)qr \equiv 1 \pmod{K} (in our case, K=109+7K = 10^9 + 7). This number is called the inverse of qq modulo KK; it can be shown that if q≢0(modK)q \not\equiv 0 \pmod{K} and KK is prime, then rr can be computed as r=qK2Kr = q^{K - 2} \bmod K.

예제

예제 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
코드를 제출하려면 로그인하세요.