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
#include <bits/stdc++.h>
#define ll long long

using namespace std;

const int maxn = 110;
const int base = 1e9+7;

int n,a[maxn];
ll f[maxn][maxn];
map<int,int> cnt;
vector<int> h;

ll pw(int a,int n) {
    if (n==0) return 1ll;
    if (n==1) return a;
    ll tmp = pw(a,n/2);
    tmp = (tmp*tmp)%base;
    if (n%2==0) return tmp;
    return (tmp*a)%base;
}

int main() {
  //  freopen("in.txt","r",stdin);
    ios_base::sync_with_stdio(0); cin.tie(0);
    cin>>n;
    for (int i=1;i<=n;i++) {
        cin>>a[i];
        if (cnt[a[i]]!=0) continue;
        h.push_back(a[i]);
        cnt[a[i]]=1;
    }
    cnt.clear();
    h.push_back(0);
    sort(h.begin(),h.end());
    h.erase(unique(h.begin(),h.end()),h.end());
    for (int j=0;j<h.size();j++) cnt[h[j]]=j;
    for (int j=0;j<h.size();j++)
        if (h[j] == 0) f[1][j] = pw(2,a[1]);
        else if (h[j] <= a[1]) f[1][j] = pw(2,a[1] - h[j]+1);
    for (int i=2;i<=n;i++) {
        if (a[i] < a[i-1]) {
            int mi = cnt[a[i]];
            for (int j=0;j<h.size();j++)
                if (h[j] <= a[i])
                    f[i][j] = (f[i-1][j] + f[i-1][mi])%base;
        } else {
            int mi = cnt[a[i-1]];
            for (int j=0;j<h.size();j++) {
                if (h[j] <= a[i-1]) f[i][j] = ((f[i-1][j] + f[i-1][mi])%base * pw(2,a[i] - a[i-1])) % base;
                else if (h[j] <= a[i]) f[i][j] = (pw(2,a[i] - h[j]+1) * f[i-1][mi]) % base;
            }
        }
    }
    cout<<f[n][0]<<endl;

}
