Lottery

시간 제한2초메모리 제한1024 MB

요약
N행 M열 경사로의 각 구간이 확률 A/B로 제거될 때, 공이 도달하는 바구니 값의 기댓값을 구한다.
난이도

어려움10점 중 8점

유형
동적 계획법, 확률, 누적 합, 수학
정답자
아직 제출이 없습니다

문제

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 N⋅MN \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.

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 mod (109+7)pr \bmod (10^9 + 7) where rr is such an integer that qr mod (109+7)=1qr \bmod (10^9 + 7) = 1.

입력

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

The third line contains MM space-separated integers C_1,C_2,…,C_MC\_1, C\_2, \ldots, C\_M (0≤C_i≤1090 \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 qr≡1(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=qK−2 mod Kr = q^{K - 2} \bmod K.

예제5

  1. 예제 1

    입력
    2 2
    1 2
    10 100
    
    예상 출력
    500000031
    
  2. 예제 2

    입력
    2 4
    2 5
    1 2 3 4
    
    예상 출력
    483520005
    
  3. 예제 3

    입력
    3 3
    0 1
    1 2 3
    
    예상 출력
    0
    
  4. 예제 4

    입력
    3 3
    1 1
    1 2 3
    
    예상 출력
    1
    
  5. 예제 5

    입력
    8 6
    17536540 365964399
    49 8 28 51 32 24
    
    예상 출력
    214402328