#P5131. 荷取融合
荷取融合
Description
It is known that the original equipment has mark slots. In each mark slot, there are infinitely many copies of one kind of mark. The value of the mark in the -th slot is .
Kawashiro Nitori uses a mechanical arm to extract marks from the slots. Each time it extracts, the arm grabs downward and takes one mark from the slot directly below it. After that, the arm either moves to the right or stays in place (if it moves, it can move any number of slots). At the beginning, the arm can start at any position, but at any moment it must be above some mark slot.
Kawashiro Nitori will perform grabs. After all grabs, your total reward equals the product of the values of the extracted marks.
Assuming all of Kawashiro Nitori’s operations are random, what is the expected value of the reward you can obtain?
Since the answer may not be an integer, you only need to output the result modulo .
Input Format
The first line contains two integers , representing the number of mark slots and the number of grabs.
The second line contains positive integers , representing the value of the mark in each slot.
Output Format
Output one integer, representing the expected reward after grabs.
3 2
3 1 2
16050685
6 3
1 1 4 5 1 4
16509294
Hint
Sample Explanation:
At the start, the mechanical arm can stay above any of the three slots.
The sequence of slots from which marks are grabbed can be one of the following six types: . The rewards for each plan are , respectively. The average is , which equals under .
Constraints:

Translated by ChatGPT 5
京公网安备 11011102002149号