#include <iostream>
#include <vector>

using namespace std;

const int MOD = 1000000007;

long long modPow(long long a, long long p){
	if(p == 0) return 1;
	long long res = modPow(a, p/2);
	res = (res * res) % MOD;
	if(p%2 == 1) res = (res * a) % MOD;
	return res;
}

pair<long long, long long> solve(const vector<int>& h){
	if(h.empty()) return make_pair(1, 1);
	int minH = h[0];
	for(auto& t : h) minH = min(t, minH);
	if(minH > 1){
		vector<int> nh = h;
		for(auto& t : nh) t -= minH - 1;
		auto res = solve(nh);
		long long p2 = modPow(2, minH - 1);
		res.first = (res.first + (2 * p2 + MOD - 2) % MOD * res.second) % MOD;
		res.second = (res.second * p2) % MOD;
		return res;
	} else {
		for(int i=0;i<h.size();i++){
			if(h[i] == 1){
				vector<int> h1, h2;
				for(int j=0;j<i;j++) h1.push_back(h[j]);
				for(int j=i+1;j<h.size();j++) h2.push_back(h[j]);
				auto res1 = solve(h1);
				auto res2 = solve(h2);
				pair<long long, long long> res;
				res.first = 2 * res1.first * res2.first % MOD;
				res.second = res1.second * res2.second % MOD;
				return res;
			}
		}
	}
	return make_pair(0, 0);
}

int main(){
	int N;
	while(cin >> N){
		vector<int> h(N);
		for(auto& t : h) cin >> t;
		cout << solve(h).first << endl;
	}
}
### Prompt

Generate a cpp solution to 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 <iostream>
#include <vector>

using namespace std;

const int MOD = 1000000007;

long long modPow(long long a, long long p){
	if(p == 0) return 1;
	long long res = modPow(a, p/2);
	res = (res * res) % MOD;
	if(p%2 == 1) res = (res * a) % MOD;
	return res;
}

pair<long long, long long> solve(const vector<int>& h){
	if(h.empty()) return make_pair(1, 1);
	int minH = h[0];
	for(auto& t : h) minH = min(t, minH);
	if(minH > 1){
		vector<int> nh = h;
		for(auto& t : nh) t -= minH - 1;
		auto res = solve(nh);
		long long p2 = modPow(2, minH - 1);
		res.first = (res.first + (2 * p2 + MOD - 2) % MOD * res.second) % MOD;
		res.second = (res.second * p2) % MOD;
		return res;
	} else {
		for(int i=0;i<h.size();i++){
			if(h[i] == 1){
				vector<int> h1, h2;
				for(int j=0;j<i;j++) h1.push_back(h[j]);
				for(int j=i+1;j<h.size();j++) h2.push_back(h[j]);
				auto res1 = solve(h1);
				auto res2 = solve(h2);
				pair<long long, long long> res;
				res.first = 2 * res1.first * res2.first % MOD;
				res.second = res1.second * res2.second % MOD;
				return res;
			}
		}
	}
	return make_pair(0, 0);
}

int main(){
	int N;
	while(cin >> N){
		vector<int> h(N);
		for(auto& t : h) cin >> t;
		cout << solve(h).first << endl;
	}
}
```