p03299 AtCoder Grand Contest 026 - Histogram Coloring
Let us consider a grid of squares with 10^9 rows and N columns. Let (i, j) be the square at the i-th column (1 \leq i \leq N) from the left and j-th row (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, ..., N, the bottom-most h_i squares are remaining in the i-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 1 \leq i \leq N-1 and 1 \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) and (i+1, j+1).



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

Constraints

* 1 \leq N \leq 100
* 1 \leq h_i \leq 10^9

Input

Input is given from Standard Input in the following format:


N
h_1 h_2 ... h_N


Output

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

Examples

Input

9
2 3 5 4 1 2 4 2 1


Output

12800


Input

2
2 2


Output

6


Input

5
2 1 2 1 2


Output

256


Input

9
27 18 28 18 28 45 90 45 23


Output

844733013
```python
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
import math
import bisect
import random
from itertools import permutations, accumulate, combinations, product
import sys
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, floor
from operator import mul
from functools import reduce


sys.setrecursionlimit(2147483647)
INF = 10 ** 13
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split()
def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8')
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]
mod = 10 ** 9 + 7

n = I()
H = LI() + [1]
dp = [0] * (n + 1)
ret = pow(2, H[0], mod)
for kk in range(n + 1):
    if H[0] >= H[kk]:
        dp[kk] = pow(2, H[0] - H[kk], mod) * 2
    else:
        dp[kk] = 2


for k in range(1, n):
    new_dp = [0] * (n + 1)
    for i in range(n + 1):
        if H[i] <= H[k]:
            if H[k - 1] <= H[i]:
                new_dp[i] = dp[i] * 2 * pow(2, H[k] - H[i], mod)
            elif H[k - 1] > H[k]:
                new_dp[i] = dp[i] - dp[k] + dp[k] * 2
            else:
                new_dp[i] = (dp[i] - dp[k - 1] + dp[k - 1] * 2) * pow(2, H[k] - H[k - 1], mod)
        else:
            new_dp[i] = dp[k] * 2
        new_dp[i] %= mod
    dp = new_dp


print(dp[-1])

```