#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>

#define endl '\n'
#define pb push_back
#define fr first
#define sc second
#define ll long long int
#define ld long double
#define lsb(idx) idx&(-idx)
#define bin(x) bitset<32>(x).to_string()
#define all(A) A.begin(), A.end()
#define de(x) cout << #x << " = " << x << endl;

using namespace std;
using namespace __gnu_pbds;

template<class T> using oset = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template<class T> using matrix = vector<vector<T>>;
// find_by_order(x) -> x-th element in the set
// order_of_key(x)  -> how many elements are less than x
// insert(x)		-> inserts x into the set

const ll MOD = 1e9 + 7;
const int MAXN = 3e5;
const int MAXL = 20;

int A[MAXN + 5], lg2[MAXN + 5], sparse[MAXN + 5][MAXL + 1];

int my_min(int x, int y){
	return (A[x] < A[y] ? x : y);
}

int get_min(int l, int r){
	int j = lg2[r - l + 1];
	return my_min(sparse[l][j], sparse[r - (1 << j) + 1][j]);
}

void init(){
	lg2[1] = 0;
	for(int i = 2; i <= MAXN; i ++) lg2[i] = lg2[i / 2] + 1;
}

ll sum(ll a, ll b){
	return (a + b) % MOD;
}

ll mult(ll a, ll b){
	return (a * b) % MOD;
}

ll dfs(int l, int r, int mask = 0){
	if(l > r) return 1;
	int idx = get_min(l, r);
	ll L = dfs(l, idx - 1, mask | 1);
	ll R = dfs(idx + 1, r, mask | 2);
	ll ret = (L * R) % MOD;
	if(mask & 1) ret = (ret + L) % MOD;
	if(mask & 2) ret = (ret + R) % MOD;
	if(mask == 3) ret = (ret - 1 + MOD) % MOD;
	return ret;
}

void s(){
	int n; cin >> n;
	for(int i = 1; i <= n; i ++){
		cin >> A[i];
		sparse[i][0] = i;
	}
	for(int l = 1; l < MAXL; l ++){
		for(int i = 1; i + (1 << (l - 1)) <= n; i ++){
			sparse[i][l] = my_min(sparse[i][l - 1], sparse[i + (1 << (l - 1))][l - 1]);
		}
	}
	cout << dfs(1, n) << endl;
}

int main(){
	// ios_base::sync_with_stdio(false); cin.tie(NULL);
	// freopen("filename.in" , "r", stdin); 
	// freopen("filename.out", "w", stdout);
	init();
	// int t; cin >> t; while(t --) s();
	s();
}
/**

*/
