← Home
write a go solution for Description:
Tenzing has an array a of length n and an integer v.

Tenzing will perform the following operation m times:

1. Choose an integer i such that 1<=i<=n uniformly at random.
2. For all j such that i<=j<=n, set a_j:=a_j+v.

Tenzing wants to know the expected value of prod_i=1^na_i after performing the m operations, modulo 10^9+7.

Formally, let M=10^9+7. It can be shown that the answer can be expressed as an irreducible fraction p/q, where p and q are integers and qnotequiv0pmodM. Output the integer equal to p*q^-1bmodM. In other words, output the integer x that 0<=x<M and x*qequivppmodM.

Input Format:
The first line of input contains three integers n, m and v (1<=n<=5000, 1<=m,v<=10^9).

The second line of input contains n integers a_1,a_2,ldots,a_n (1<=a_i<=10^9).

Output Format:
Output the expected value of prod_i=1^na_i modulo 10^9+7.

Note:
There are three types of a after performing all the m operations :

1. a_1=2,a_2=12 with 1/4 probability.

2. a_1=a_2=12 with 1/4 probability.

3. a_1=7,a_2=12 with 1/2 probability.

So the expected value of a_1*a_2 is 1/4*(24+144)+1/2*84=84.. Output only the code with no comments, explanation, or additional text.