Expected Value
Time limit3sMemory limit16 MB
Repeatedly pick a random adjacent pair, replace the left value by its difference with the right, drop the right. Find the expected final value modulo 1e9+7.
- Level
Hard8 of 10
- Topics
- Dynamic programming, Probability, Combinatorics, Math
- Solved
- No attempts yet
Problem
Here is a game played with sequence . On each turn, the player chooses some position uniformly at random, replaces the element with , and then removes the element from the sequence. This continues until there is only one element left. What is the expected value of the last element?
Input
The first line of input contains a single integer ().
The second line of input contains integers ().
Output
If the answer is such that and are coprime, output a single integer which is . It is guaranteed that .
Hint
Pay attention to the non-standard memory limit.