#arc104f. [arc104_f]Visibility Sequence

[arc104_f]Visibility Sequence

Problem Statement

There are NN buildings under construction arranged in a row, numbered 1,2,ldots,N1, 2, \\ldots, N from left to right.

Given is an integer sequence XX of length NN. The height of Building ii, HiH_i, can be one of the integers between 11 and XiX_i (inclusive).

For each ii such that 1leqileqN1 \\leq i \\leq N, let us define PiP_i as follows:

  • If there is an integer j(1leqj<i)j (1 \\leq j < i) such that Hj>HiH_j > H_i, PiP_i is the maximum such jj. Otherwise, PiP_i is \-1\-1.

Considering all possible combinations of the buildings' heights, find the number of integer sequences that PP can be, modulo 10000000071000000007.

Constraints

  • 1leqNleq1001 \\leq N \\leq 100
  • 1leqXileq1051 \\leq X_i \\leq 10^5
  • All values in input are integers.

Input

Input is given from Standard Input in the following format:

NN X1X_1 X2X_2 cdots\\cdots XNX_N

Output

Print the number of integer sequences that PP can be when all possible combinations of the buildings' heights are considered, modulo 10000000071000000007.


Sample Input 1

3
3 2 1

Sample Output 1

4

We have six candidates for HH, as follows:

  • H=(1,1,1)H = (1, 1, 1), for which PP is (1,1,1)(-1, -1, -1);
  • H=(1,2,1)H = (1, 2, 1), for which PP is (1,1,2)(-1, -1, 2);
  • H=(2,1,1)H = (2, 1, 1), for which PP is (1,1,1)(-1, 1, 1);
  • H=(2,2,1)H = (2, 2, 1), for which PP is (1,1,2)(-1, -1, 2);
  • H=(3,1,1)H = (3, 1, 1), for which PP is (1,1,1)(-1, 1, 1);
  • H=(3,2,1)H = (3, 2, 1), for which PP is (1,1,2)(-1, 1, 2).

Thus, there are four integer sequences that PP can be: (1,1,1),(1,1,2),(1,1,1)(-1, -1, -1), (-1, -1, 2), (-1, 1, 1), and (1,1,2)(-1, 1, 2).


Sample Input 2

3
1 1 2

Sample Output 2

1

We have two candidates for HH, as follows:

  • H=(1,1,1)H = (1, 1, 1), for which PP is (1,1,1)(-1, -1, -1);
  • H=(1,1,2)H = (1, 1, 2), for which PP is (1,1,1)(-1, -1, -1).

Thus, there is one integer sequence that PP can be.


Sample Input 3

5
2 2 2 2 2

Sample Output 3

16

Sample Input 4

13
3 1 4 1 5 9 2 6 5 3 5 8 9

Sample Output 4

31155