#agc026d. [agc026_d]Histogram Coloring

[agc026_d]Histogram Coloring

Problem Statement

Let us consider a grid of squares with 10910^9 rows and NN columns. Let (i,j)(i, j) be the square at the ii-th column (1leqileqN)(1 \\leq i \\leq N) from the left and jj-th row (1leqjleq109)(1 \\leq j \\leq 10^9) from the bottom.

Snuke has cut out some part of the grid so that, for each i=1,2,...,Ni = 1, 2, ..., N, the bottom-most hih_i squares are remaining in the ii-th column from the left. Now, he will paint the remaining squares in red and blue. Find the number of the ways to paint the squares so that the following condition is satisfied:

  • Every remaining square is painted either red or blue.
  • For all 1leqileqN11 \\leq i \\leq N-1 and 1leqjleqmin(hi,hi+1)11 \\leq j \\leq min(h_i, h_{i+1})-1, there are exactly two squares painted red and two squares painted blue among the following four squares: (i,j),(i,j+1),(i+1,j)(i, j), (i, j+1), (i+1, j) and (i+1,j+1)(i+1, j+1).

Since the number of ways can be extremely large, print the count modulo 109+710^9+7.

Constraints

  • 1leqNleq1001 \\leq N \\leq 100
  • 1leqhileq1091 \\leq h_i \\leq 10^9

Input

Input is given from Standard Input in the following format:

NN h1h_1 h2h_2 ...... hNh_N

Output

Print the number of the ways to paint the squares, modulo 109+710^9+7.


Sample Input 1

9
2 3 5 4 1 2 4 2 1

Sample Output 1

12800

One of the ways to paint the squares is shown below:


  #```