#E. ARC108E - Random IS

    Type: Default 3000ms 256MiB

ARC108E - Random IS

You cannot submit for this problem because the contest is ended. You can click "Open in Problem Set" to view this problem in normal mode.

Time Limit: 3 sec / Memory Limit: 1024 MB

Score : 700 points

Problem Statement

There are N isu - chairs in Japanese - arranged from left to right. The i-th chair from the left has the ID number ai. Here, it is guaranteed that ai 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:

  1. We say a chair x to be nice if (and only if) the choice of marked chairs is still good when x gets marked. Let k be the current number of nice chairs.
  2. If k=0, remove the unmarked chairs and terminate the procedure. Otherwise, choose one from the k 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 P/Q, an irreducible fraction. Additionally, let M=109+7. Then, we can prove that there uniquely exists an integer R between 0 and M1 (inclusive) such that PQ×R(modM), and that value equals P×Q1(modM), where Q1 is the modular multiplicative inverse of Q. Find R.

Constraints

  • All values in input are integers.
  • 1N2000
  • 1aiN
  • ai are distinct.

Input

Input is given from Standard Input in the following format:

N
a1 a2  aN

Output

Print R.


Sample Input 1

3
3 1 2

Sample Output 1

666666673
  • If Chair 1 (the chair with the ID number 1) gets marked first, two chairs will remain at the end: Chair 1 and 2.
  • If Chair 2 gets marked first, two chairs will remain at the end: Chair 1 and 2.
  • If Chair 3 gets marked first, one chair will remain at the end: Chair 3.
  • Since chairs are chosen with equal probability, the expected value of the number of chairs at the end is 35. We have 53×666666673(modM), so R=666666673.

Sample Input 2

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

Sample Output 2

297703424
</span>

军训训练赛1

Not Attended
Status
Done
Rule
IOI
Problem
7
Start at
2023-8-20 8:00
End at
2023-8-20 11:00
Duration
3 hour(s)
Host
Partic.
12