#include<bits/stdc++.h>
#define llong long long
#define mkpr make_pair
#define riterator reverse_iterator
#define pll pair<llong,llong>
using namespace std;

inline int read()
{
	int x = 0,f = 1; char ch = getchar();
	for(;!isdigit(ch);ch=getchar()) {if(ch=='-') f = -1;}
	for(; isdigit(ch);ch=getchar()) {x = x*10+ch-48;}
	return x*f;
}

const int mxN = 100;
const int INF = 1e9;
const int P = 1e9+7;
int a[mxN+3];
int n;

llong quickpow(llong x,llong y)
{
	llong cur = x,ret = 1ll;
	for(int i=0; y; i++)
	{
		if(y&(1ll<<i)) {y-=(1ll<<i); ret = ret*cur%P;}
		cur = cur*cur%P;
	}
	return ret;
}

pll dfs(int l,int r,int h)
{
//	printf("l=%d r=%d h=%d\n",l,r,h);
	int h2 = INF; for(int i=l; i<=r; i++) h2 = min(h2,a[i]);
	pll ret(0ll,1ll); int mncnt = 0ll,segcnt = 0ll; llong prod1 = 1ll;
	for(int i=l,j=l; i<=r+1; i++)
	{
		if(a[i]==h2||i==r+1)
		{
			if(j<=i-1)
			{
				pll tmp = dfs(j,i-1,h2);
				ret.second = ret.second*tmp.second%P;
				prod1 = prod1*(tmp.first+tmp.second*2ll)%P;
				segcnt++;
			}
			if(i<=r)
			{
				mncnt++;
			}
			j = i+1;
		}
	}
	ret.first = (prod1*quickpow(2ll,mncnt)-ret.second*2ll%P+P)%P;
	ret.second = ret.second*quickpow(2ll,h2-h)%P;
//	printf("(%lld,%lld)\n",ret.first,ret.second);
	return ret;
}

int main()
{
	scanf("%d",&n);
	for(int i=1; i<=n; i++) scanf("%lld",&a[i]);
	pll ans = dfs(1,n,0);
	printf("%lld\n",(ans.first+ans.second)%P);
	return 0;
}
### Prompt

In cpp, your task is to solve the following problem:

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

### Response

```cpp
#include<bits/stdc++.h>
#define llong long long
#define mkpr make_pair
#define riterator reverse_iterator
#define pll pair<llong,llong>
using namespace std;

inline int read()
{
	int x = 0,f = 1; char ch = getchar();
	for(;!isdigit(ch);ch=getchar()) {if(ch=='-') f = -1;}
	for(; isdigit(ch);ch=getchar()) {x = x*10+ch-48;}
	return x*f;
}

const int mxN = 100;
const int INF = 1e9;
const int P = 1e9+7;
int a[mxN+3];
int n;

llong quickpow(llong x,llong y)
{
	llong cur = x,ret = 1ll;
	for(int i=0; y; i++)
	{
		if(y&(1ll<<i)) {y-=(1ll<<i); ret = ret*cur%P;}
		cur = cur*cur%P;
	}
	return ret;
}

pll dfs(int l,int r,int h)
{
//	printf("l=%d r=%d h=%d\n",l,r,h);
	int h2 = INF; for(int i=l; i<=r; i++) h2 = min(h2,a[i]);
	pll ret(0ll,1ll); int mncnt = 0ll,segcnt = 0ll; llong prod1 = 1ll;
	for(int i=l,j=l; i<=r+1; i++)
	{
		if(a[i]==h2||i==r+1)
		{
			if(j<=i-1)
			{
				pll tmp = dfs(j,i-1,h2);
				ret.second = ret.second*tmp.second%P;
				prod1 = prod1*(tmp.first+tmp.second*2ll)%P;
				segcnt++;
			}
			if(i<=r)
			{
				mncnt++;
			}
			j = i+1;
		}
	}
	ret.first = (prod1*quickpow(2ll,mncnt)-ret.second*2ll%P+P)%P;
	ret.second = ret.second*quickpow(2ll,h2-h)%P;
//	printf("(%lld,%lld)\n",ret.first,ret.second);
	return ret;
}

int main()
{
	scanf("%d",&n);
	for(int i=1; i<=n; i++) scanf("%lld",&a[i]);
	pll ans = dfs(1,n,0);
	printf("%lld\n",(ans.first+ans.second)%P);
	return 0;
}
```