#C. ARC104E - Random LIS

    Type: Default 1000ms 256MiB

ARC104E - Random LIS

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.

Score : 700 points

Problem Statement

Given is an integer sequence of length N: A1,A2,,AN.

An integer sequence X, which is also of length N, will be chosen randomly by independently choosing Xi from a uniform distribution on the integers 1,2,,Ai for each i(1iN).

Compute the expected value of the length of the longest increasing subsequence of this sequence X, modulo 1000000007.

More formally, under the constraints of the problem, we can prove that the expected value can be represented as a rational number, that is, an irreducible fraction QP, and there uniquely exists an integer R such that R×QP(mod1000000007) and 0R<1000000007, so print this integer R.

Notes

A subsequence of a sequence X is a sequence obtained by extracting some of the elements of X and arrange them without changing the order. The longest increasing subsequence of a sequence X is the sequence of the greatest length among the strictly increasing subsequences of X.

Constraints

  • 1N6
  • 1Ai109
  • All values in input are integers.

Input

Input is given from Standard Input in the following format:

N
A1 A2  AN

Output

Print the expected value modulo 1000000007.


Sample Input 1

3
1 2 3

Sample Output 1

2

X becomes one of the following, with probability 1/6 for each:

  • X=(1,1,1), for which the length of the longest increasing subsequence is 1;
  • X=(1,1,2), for which the length of the longest increasing subsequence is 2;
  • X=(1,1,3), for which the length of the longest increasing subsequence is 2;
  • X=(1,2,1), for which the length of the longest increasing subsequence is 2;
  • X=(1,2,2), for which the length of the longest increasing subsequence is 2;
  • X=(1,2,3), for which the length of the longest increasing subsequence is 3.

Thus, the expected value of the length of the longest increasing subsequence is (1+2+2+2+2+3)/62(mod1000000007).


Sample Input 2

3
2 1 2

Sample Output 2

500000005

X becomes one of the following, with probability 1/4 for each:

  • X=(1,1,1), for which the length of the longest increasing subsequence is 1;
  • X=(1,1,2), for which the length of the longest increasing subsequence is 2;
  • X=(2,1,1), for which the length of the longest increasing subsequence is 1;
  • X=(2,1,2), for which the length of the longest increasing subsequence is 2.

Thus, the expected value of the length of the longest increasing subsequence is (1+2+1+2)/4=3/2. Since 2×5000000053(mod1000000007), we should print 500000005.


Sample Input 3

6
8 6 5 10 9 14

Sample Output 3

959563502

ARC104

Not Attended
Status
Done
Rule
IOI
Problem
5
Start at
2023-6-30 8:15
End at
2023-6-30 10:15
Duration
2 hour(s)
Host
Partic.
14