atcoder#ARC104F. [ARC104F] Visibility Sequence

[ARC104F] Visibility Sequence

Score : 10001000 points

Problem Statement

There are NN buildings under construction arranged in a row, numbered 1,2,,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 1iN1 \leq i \leq N, let us define PiP_i as follows:

  • If there is an integer j(1j<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

  • 1N1001 \leq N \leq 100
  • 1Xi1051 \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 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.

3
3 2 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).

3
1 1 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.

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