Histogram Sequence 2

아직 제출이 없습니다시간 제한1초메모리 제한1024 MB

문제

A 2-dimensional grid can be represented as a set of pairs of positive integers. Each cell can be numbered as in the figure below:

Suppose you are given a histogram where the height of each column is h_1,h_2,,h_Nh\_1, h\_2, \cdots, h\_N. Its area can be represented as a set containing cells (i,1),(i,2),,(i,h_i)(i, 1), (i, 2), \cdots, (i, h\_i) for i=1,2,,Ni = 1, 2, \cdots, N. (If h_i=0h\_i = 0, it means the histogram's area does not contain any cell from the ii-th column.)

You may choose NN integers x_1,x_2,,x_Nx\_1, x\_2, \cdots, x\_N with 0x_i<h_i0 \le x\_i < h\_i and subtract a sub-histogram with heights x_1,x_2,,x_Nx\_1, x\_2, \cdots, x\_N. After removing such a sub-histogram, the remaining area can be written as: _i=1N(i,j):x_i<jh_i.\bigcup\_{i=1}^N \\{ (i, j) : x\_i < j \le h\_i \\}.

For example, the following figure shows an example of h_1=4h\_1 = 4, h_2=5h\_2 = 5, h_3=4h\_3 = 4, h_4=4h\_4 = 4 and x_1=1x\_1 = 1, x_2=2x\_2 = 2, x_3=3x\_3 = 3, x_4=2x\_4 = 2.

The remaining area is called connected if for every pair of cells ((r_1,c_1),(r_2,c_2))((r\_1, c\_1), (r\_2, c\_2)) in the remaining area, one can move from (r_1,c_1)(r\_1, c\_1) to (r_2,c_2)(r\_2, c\_2) using only the following moves without leaving the remaining area:

  • (r,c)(r+1,c)(r, c) \to (r+1, c)
  • (r,c)(r1,c)(r, c) \to (r-1, c)
  • (r,c)(r,c+1)(r, c) \to (r, c+1)
  • (r,c)(r,c1)(r, c) \to (r, c-1)

Compute the number of ways to choose (x_1,x_2,,x_N)(x\_1, x\_2, \cdots, x\_N) such that the remaining area is connected.

입력

The first line contains a single integer, NN. The second line contains NN integers - h_1,h_2,,h_Nh\_1, h\_2, \cdots, h\_N in order.

출력

Output the number of ways to choose (x_1,x_2,,x_N)(x\_1, x\_2, \cdots, x\_N) such that the remaining area is connected, modulo 109+710^9 + 7.

제한

  • 1N250,0001 \le N \le 250\\,000
  • 1h_i1091 \le h\_i \le 10^9