atcoder#DWACON6THPRELIMSB. Fusing Slimes
Fusing Slimes
Score : points
Problem Statement
There are slimes standing on a number line. The -th slime from the left is at position .
It is guaruanteed that .
Niwango will perform operations. The -th operation consists of the following procedures:
- Choose an integer between and (inclusive) with equal probability.
- Move the -th slime from the left, to the position of the neighboring slime to the right.
- Fuse the two slimes at the same position into one slime.
Find the total distance traveled by the slimes multiplied by (we can show that this value is an integer), modulo . If a slime is born by a fuse and that slime moves, we count it as just one slime.
Constraints
- is an integer.
Subtasks
- points will be awarded for passing the test cases satisfying .
Input
Input is given from Standard Input in the following format:
Output
Print the answer.
3
1 2 3
5
- With probability , the leftmost slime is chosen in the first operation, in which case the total distance traveled is .
- With probability , the middle slime is chosen in the first operation, in which case the total distance traveled is .
- The answer is the expected total distance traveled, , multiplied by , which is .
12
161735902 211047202 430302156 450968417 628894325 707723857 731963982 822804784 880895728 923078537 971407775 982631932
750927044
- Find the expected value multiplied by , modulo .