atcoder#ARC108E. [ARC108E] Random IS
[ARC108E] Random IS
Score : points
Problem Statement
There are isu - chairs in Japanese - arranged from left to right. The -th chair from the left has the ID number . Here, it is guaranteed that are distinct.
Snuke has decided to mark some of the chairs and throw away the rest. Initially, no chair is marked. We call a choice of marked chairs good when the IDs of the marked chairs are monotonically increasing from left to right.
Snuke has decided to do the following procedure to mark chairs:
- We say a chair to be nice if (and only if) the choice of marked chairs is still good when gets marked. Let be the current number of nice chairs.
- If , remove the unmarked chairs and terminate the procedure. Otherwise, choose one from the nice chairs with equal probability, mark it, and go back to Step 1.
It can be proved that the expected value of the number of chairs that remain at the end of the procedure is a rational number. Let this value be , an irreducible fraction. Additionally, let . Then, we can prove that there uniquely exists an integer between and (inclusive) such that , and that value equals , where is the modular multiplicative inverse of . Find .
Constraints
- All values in input are integers.
- are distinct.
Input
Input is given from Standard Input in the following format:
Output
Print .
3
3 1 2
666666673
- If Chair (the chair with the ID number ) gets marked first, two chairs will remain at the end: Chair and .
- If Chair gets marked first, two chairs will remain at the end: Chair and .
- If Chair gets marked first, one chair will remain at the end: Chair .
- Since chairs are chosen with equal probability, the expected value of the number of chairs at the end is . We have , so .
30
26 16 28 30 23 11 29 18 22 15 20 13 27 9 21 7 5 25 4 19 8 3 1 24 10 14 17 12 2 6
297703424