#include <bits/stdc++.h>
#include <iostream>
using namespace std;
#define print(v,r) f(i,0,r) cout<<v[i]<<" "; cout<<endl;
#define Get(x,y) scanf("%I64d%I64d",&x,&y);
#define f_(i,a,b) for(int i=a;i>=b;i--)
#define Gett(x,y) scanf("%d%d",&x,&y);
#define f(i,a,b) for(ll i=a;i<b;i++)
#define get(x) scanf("%I64d",&x);
#define gett(x) scanf("%d",&x);
#define ops(x) cout<<x<<" !"<<endl;
#define maxm(a,b) a=max(a,b);
#define minm(a,b) a=min(a,b);
#define mp make_pair
#define ll long long
#define pb push_back
#define add(x,y) x=(x+y)%mod;
#define S second
#define F first

const int N=505,mod=1e9+7;

int n,a[N],dp[N][N][N];

void make(int l,int r){
	f(i,1,N)
		add(dp[l][r][i],dp[l][r][i-1]);
}

int main(){
	cin>>n;
	f(i,1,n+1) cin>>a[i];
	f(i,1,n+2)
		f(j,0,n+1)
			dp[i][i-1][j]=1;
	f(r,1,n+1)
		f_(l,r,1){
			f(i,l,r+1){
				if(i==l) dp[l][r][a[i]]=dp[l+1][r][n];
				else dp[l][r][a[i]]=dp[l][i-1][a[i]-1];
				if(i==1 && r-l==n-1) return cout<<dp[l][r][a[i]],0;
			}
			make(l,r);
		}
	cout<<dp[1][n][n];
}


//So take me up take me higher
//There's a world not far from here
//We can dance in desire
//Or we can burn in love tonight

#pragma GCC optimize("Ofast,unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4.2")

#include<bits/stdc++.h>
using namespace std;

#define all(x) (x).begin(),(x).end()

inline void opting() {
    ios_base::sync_with_stdio(false);
    cout.tie(0);
    cin.tie(0);
}

long long inp() {
    long long x;
    cin >> x;
    return x;
}

void make_unique(vector<long long> &vec, bool sorted = false) {
    if(!sorted)
        sort(all(vec));
    vec.resize(unique(all(vec)) - vec.begin());
}

void file_edit(bool reader = true, bool writer = false) {
    if(reader)
        freopen("Test_input.txt","r",stdin);
    if(writer)
        freopen("Test_output.txt","w",stdout);
}

const long long SQRT = 350 + 10, lg = 18 + 2, inlim = 2147483647;
const long long maxn = 505, delta = 1e9 + 7, inf = 1e9 + 420;

long long dp[maxn][maxn];
vector<long long> a;
long long n;

inline void calc_dp(const long long &s, const long long &e){//[s, e]
    dp[s][e] = dp[s + 1][e];
    if(a[s] < a[s + 1])
        dp[s][e] += dp[s + 1][e];
    for(long long i = s + 1; i <= e; i++)
        if(a[s] < a[i + 1]){
            dp[s][e] = (dp[s][e] + (dp[i + 1][e] * dp[s + 1][i]) ) % delta;
            //cout << "based on "<<s + 1 <<' ' <<i<<" and "<< i + 1 << ' ' << e<<endl;
        }
    //cout <<s << ' ' << e <<" is "<<dp[s][e] << endl;
}

void driver(){
    for(long long i = 0; i < maxn - 1; i++)
        dp[i][i] = 1;

    for(long long l = 1; l <= n; l++)
        for(long long i = 0; i + l < n; i++)
            calc_dp(i, i + l);
}
int main() {
    opting();
    //file_edit();

    n = inp();
    for(long long i = 0; i < n; i++)
        a.push_back(inp());

    driver();
    if(n==1)
        cout << 1;
    else
        cout << dp[1][n - 1]<<endl;
}


//So take me up take me higher
//There's a world not far from here
//We can dance in desire
//Or we can burn in love tonight

#pragma GCC optimize("Ofast,unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4.2")

#include<bits/stdc++.h>
using namespace std;

#define all(x) (x).begin(),(x).end()

inline void opting() {
    ios_base::sync_with_stdio(false);
    cout.tie(0);
    cin.tie(0);
}

long long inp() {
    long long x;
    cin >> x;
    return x;
}

void make_unique(vector<long long> &vec, bool sorted = false) {
    if(!sorted)
        sort(all(vec));
    vec.resize(unique(all(vec)) - vec.begin());
}

void file_edit(bool reader = true, bool writer = false) {
    if(reader)
        freopen("Test_input.txt","r",stdin);
    if(writer)
        freopen("Test_output.txt","w",stdout);
}

const long long SQRT = 350 + 10, lg = 18 + 2, inlim = 2147483647;
const long long maxn = 505, delta = 1e9 + 7, inf = 1e9 + 420;

long long dp[maxn][maxn];
vector<long long> a;
long long n;

inline void calc_dp(const long long &s, const long long &e){//[s, e]
    dp[s][e] = dp[s + 1][e];
    if(a[s] < a[s + 1])
        dp[s][e] += dp[s + 1][e];
    for(long long i = s + 1; i <= e; i++)
        if(a[s] < a[i + 1]){
            dp[s][e] = (dp[s][e] + (dp[i + 1][e] * dp[s + 1][i]) ) % delta;
            //cout << "based on "<<s + 1 <<' ' <<i<<" and "<< i + 1 << ' ' << e<<endl;
        }
    //cout <<s << ' ' << e <<" is "<<dp[s][e] << endl;
}

void driver(){
    for(long long i = 0; i < maxn - 1; i++)
        dp[i][i] = 1;

    for(long long l = 1; l <= n; l++)
        for(long long i = 0; i + l < n; i++)
            calc_dp(i, i + l);
}
int main() {
    opting();
    //file_edit();

    n = inp();
    for(long long i = 0; i < n; i++)
        a.push_back(inp());

    driver();
    cout << dp[1][n - 1]<<endl;
}


#include<bits/stdc++.h>
#define MOD 1000000007
using namespace std;
using ll=long long;

main()
{
	int n;
	cin>>n;

	vector<int> v(n);
	for(int i=0;i<n;i++)
	cin>>v[i];

	if(n==1)
	{
		cout<<1;
		return 0;
	}

	vector<vector<ll>> dp(n,vector<ll> (n));

	for(int i=0;i<n;i++)
	{
		dp[i][i]=1;

		if(i)
		dp[i][i-1]=1;
	}

	for(int l=2;l<=n;l++)
	{
		for(int i=0;i<=n-l;i++)
		{
			int j=i+l-1;

			for(int k=i+1;k<=j;k++)
			{
				if(v[i]<v[k])
				{
					dp[i][j]=(dp[i][j]+(dp[i+1][k-1]*dp[k][j])%MOD)%MOD;
				}
			}
		}
	}

	cout<<dp[0][n-1];
}


#include<bits/stdc++.h>
#define MOD 1000000007
using namespace std;
using ll=long long;

main()
{
	int n;
	cin>>n;

	vector<int> v(n);
	for(int i=0;i<n;i++)
	cin>>v[i];

	if(n==1)
	{
		cout<<1;
		return 0;
	}

	vector<vector<ll>> dp(n,vector<ll> (n));

	for(int i=0;i<n;i++)
	{
		dp[i][i]=1;

		if(i)
		dp[i][i-1]=1;
	}

	for(int l=2;l<=n;l++)
	{
		for(int i=0;i<=n-l;i++)
		{
			int j=i+l-1;

			dp[i][j]=dp[i+1][j];

			for(int k=i+2;k<=j;k++)
			{
				if(v[i+1]<v[k])
				{
					dp[i][j]=(dp[i][j]+(dp[i+1][k-1]*dp[k-1][j])%MOD)%MOD;
				}
			}
		}
	}

	cout<<dp[0][n-1];
}


#include<bits/stdc++.h>
#define MOD 1000000007
using namespace std;
using ll=long long;

main()
{
	int n;
	cin>>n;

	vector<int> v(n);
	for(int i=0;i<n;i++)
	cin>>v[i];

	if(n==1)
	{
		cout<<1;
		return 0;
	}

	vector<vector<ll>> dp(n,vector<ll> (n));

	for(int i=0;i<n;i++)
	{
		dp[i][i]=1;

		if(i)
		dp[i][i-1]=1;
	}

	for(int l=2;l<=n;l++)
	{
		for(int i=0;i<=n-l;i++)
		{
			int j=i+l-1;

			dp[i][j]=dp[i+1][j];

			for(int k=i+1;k<=j;k++)
			{
				if(v[i+1]<v[k])
				{
					dp[i][j]=(dp[i][j]+(dp[i+1][k-1]*dp[k][j])%MOD)%MOD;
				}
			}
		}
	}

	cout<<dp[0][n-1];
}


#define main fakemain
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
typedef pair<int,int> pii;
typedef long long ll;
typedef double ld;
typedef vector<int> vi;
#define fi first
#define se second
#define fe first
#define FO(x) {freopen(#x".in","r",stdin);freopen(#x".out","w",stdout);}
#define Edg int M=0,fst[SZ],vb[SZ],nxt[SZ];void ad_de(int a,int b){++M;nxt[M]=fst[a];fst[a]=M;vb[M]=b;}void adde(int a,int b){ad_de(a,b);ad_de(b,a);}
#define Edgc int M=0,fst[SZ],vb[SZ],nxt[SZ],vc[SZ];void ad_de(int a,int b,int c){++M;nxt[M]=fst[a];fst[a]=M;vb[M]=b;vc[M]=c;}void adde(int a,int b,int c){ad_de(a,b,c);ad_de(b,a,c);}
#define es(x,e) (int e=fst[x];e;e=nxt[e])
#define esb(x,e,b) (int e=fst[x],b=vb[e];e;e=nxt[e],b=vb[e])
#define SZ 666666

int n,b[SZ],u[505][505],g[505][505];
const int MOD=1e9+7;
void main()
{
#ifdef ONLINE_JUDGE //don't mix cin/scanf, cout/printf!
	cin.tie(0); cout.tie(0);
	ios::sync_with_stdio(0);
#endif
	cin>>n;
	for(int i=1;i<=n;++i)
		cin>>b[i];
	for(int l=n;l>=1;--l)
	{
		for(int r=1;r<=n;++r)
		{
			if(l!=r)
				g[l][r]=u[l+1][r];
			else g[l][r]=1;
			u[l][r]=g[l][r];
			for(int s=l;s<r;++s)
				if(b[l]<b[s+1])
					u[l][r]=(u[l][r]+(ll)u[s+1][r]*g[l][s])%MOD;
		}
	}
	cout<<g[1][n]<<"\n";
}

#undef main
#ifndef ONLINE_JUDGE
void rmv_() {remove("IN_TEMP_F_UlllOpB");remove("OUT_TEMP_F_UlllOpB");} /*edit if you want to don't want your temps removed*/ string to_str__booster__(int x) {char buf[100];sprintf(buf,"%d",x);return buf;} vector<string> clean__booster___(string u){u.push_back('\n');vector<string> w;string c;for(auto t:u){if(t=='\n'||t=='\r'){while(c.size()&&c.back()==' ') c.pop_back();if(c.size()) w.push_back(c);c.clear();}else c.push_back(t);}return w;}int to_num__booster__(string s){int w=atoi(s.c_str());char buf[10];sprintf(buf,"%d",w);if(buf==s) return w;return -1;}int main(int argc,char**argv){if(argc==2&&(string)argv[1]=="r") {fakemain();return 0;}vector<string> code;{std::ifstream t(__FILE__);std::stringstream buffer;buffer << t.rdbuf();t.close(); code=clean__booster___(buffer.str());}int num_samples=0;map<pair<int,int>,string> samples;{string cs="";pair<int,int> id(-1,-1);for(auto s:code){if(s.substr(0,4)=="*o* "){if(id.second!=-1)samples[id]=cs;id=make_pair(-1,-1),cs="";string g=s.substr(4);string si="Sample Input ";string so="Sample Output ";if(g.back()==':'&&g.substr(0,si.size())==si){int w=to_num__booster__(g.substr(si.size(),g.size()-si.size()-1));if(w>=1) id=make_pair(w,0);}if(g.back()==':'&&g.substr(0,so.size())==so){int w=to_num__booster__(g.substr(so.size(),g.size()-so.size()-1));if(w>=1) id=make_pair(w,1);}}else cs=cs+s+"\n";}while(samples.count(make_pair(num_samples+1,0))&&samples.count(make_pair(num_samples+1,1)))++num_samples;}if(!num_samples){fakemain();return 0;}int w; int cap=1,sil=0; if(argc==2) {w=to_num__booster__(argv[1]); cerr<<w<<"... "; cap=2;} else {cerr<<num_samples<<" samples. autofeed: ";cerr.flush();string u;getline(cin,u);if(u=="a"){cerr<<"testing all samples..."<<endl;for(int i=1;i<=num_samples;++i) {cerr<<"testing sample ";int rt=system(((string)"\""+argv[0]+"\" "+to_str__booster__(i)).c_str()); if(rt) cerr<<endl<<"WA/RE (return value "<<rt<<")\n",exit(-1);}cerr<<"all samples passed!"<<endl;exit(0);}while(1){if(u.size()&&u.back()=='r')u.pop_back(),cap=0;else if(u.size()&&u.back()=='s')u.pop_back(),sil=1,cap=0;else break;}w=to_num__booster__(u);}string in,out;rmv_();if(w>=1&&w<=num_samples){in=samples[make_pair(w,0)];out=samples[make_pair(w,1)];ofstream o("IN_TEMP_F_UlllOpB");o<<in; o.close();freopen("IN_TEMP_F_UlllOpB","r",stdin);if(cap){if(cap!=2) cerr<<"============= testcase "<<w<<" (captured) ============="<<endl;freopen("OUT_TEMP_F_UlllOpB","w",stdout);}else{cerr<<"================== testcase "<<w<<" ==================="<<endl;}}else{cap=0; cerr<<"=============== normal run ================"<<endl;}time_t start_time=clock(); fakemain(); time_t end_time=clock(); bool force_stop=false;if(w>=1&&w<=num_samples){string out_str;if(cap){fclose(stdout);std::ifstream t("OUT_TEMP_F_UlllOpB");std::stringstream buffer;buffer << t.rdbuf();t.close();out_str=buffer.str();if(cap!=2) cerr<<out_str;}if(sil);else{if(cap!=2) cerr<<endl<<"================================================="<<endl<<"sample output:"<<endl<<out<<endl;if(cap){if(clean__booster___(out)==clean__booster___(out_str))cerr<<"compare passed ("<<int((end_time - start_time)*1000.0/CLOCKS_PER_SEC+0.5)<<"ms)!"<<endl;else {cerr<<"compare failed ("<<int((end_time - start_time)*1000.0/CLOCKS_PER_SEC+0.5)<<"ms)!"<<endl; force_stop=true; if(cap==2) {cerr<<"=============== your output ==============="<<endl<<out_str<<endl<<"============== sample output =============="<<endl<<out<<endl;}}}}}fclose(stdin);rmv_(); if(force_stop) exit(-1);}
#else
int main(){fakemain();}
#endif
/*
*o* Sample Input 1:
3
1 2 3
*o* Sample Output 1:
2
*o* Sample Input 2:
3
1 3 2
*o* Sample Output 2:
1
*o* This chunk of comment is used for auto-testing. Please don't modify.
*/


#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
const ll mod = 1e9 + 7;
int n;
int b[501];
ll dp[501][501];
ll calc(int l, int r){
    if(l > r) return dp[l][r] = 1;
    if(dp[l][r] != -1) return dp[l][r];
    ll res = calc(l + 1, r);
    //cout << l << ',' << r << " = " << "1+" << l + 1 << ',' << r << '\n';
    for(int m = l; m < r; m++)if(b[l] < b[m + 1]){
        res = (res + calc(l + 1, m) * calc(m + 1, r)) % mod;
        //cout << l << ',' << m << " + " << m + 1 << ',' << r << '\n';
    }
    //cout << '\n';
    return dp[l][r] = res;
}
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    cin >> n;
    for(int i = 1; i <= n; i++)
        cin >> b[i];
    if(n == 1){
        cout << 1;
        return 0;
    }
    for(int i = 1; i <= n; i++)
        for(int j = 1; j <= n; j++)
        dp[i][j] = -1;
    cout << calc(2, n);
    return 0;
}


#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
const ll mod = 1e9 + 7;
int n;
int b[501];
ll dp[501][501];
ll calc(int l, int r){
    if(dp[l][r] != -1) return dp[l][r];
    if(l == r) return dp[l][r] = 1;
    ll res = calc(l + 1, r);
    for(int m = l ; m < r; m++)if(b[l] < b[m + 1])
        res = (res + calc(l, m) * calc(m + 1, r)) % mod;
    return dp[l][r] = res;
}
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    cin >> n;
    for(int i = 1; i <= n; i++)
        cin >> b[i];
    if(n == 1){
        cout << 1;
        return 0;
    }
    for(int i = 1; i <= n; i++)
        for(int j = 1; j <= n; j++)
        dp[i][j] = -1;
    cout << calc(2, n);
    return 0;
}


#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
const ll mod = 1e9 + 7;
int n;
int b[501];
ll dp[501][501];
ll calc(int l, int r){
    if(dp[l][r] != -1) return dp[l][r];
    if(l == r) return dp[l][r] = 1;
    ll res = 0;
    for(int m = l ; m < r; m++)if(b[l] < b[m + 1])
        res = (res + calc(l, m) * calc(m + 1, r)) % mod;
    return dp[l][r] = res;
}
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    cin >> n;
    for(int i = 1; i <= n; i++)
        cin >> b[i];
    for(int i = 1; i <= n; i++)
        for(int j = 1; j <= n; j++)
        dp[i][j] = -1;
    cout << calc(1, n);
    return 0;
}


#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
const ll mod = 1e9 + 7;
int n;
int b[501];
ll dp[501][501];
ll calc(int l, int r){
    if(dp[l][r] != -1) return dp[l][r];
    if(l >= r) return dp[l][r] = 1;
    ll res = calc(l + 1, r);
    for(int m = l ; m < r; m++)if(b[l] < b[m + 1])
        res = (res + calc(l + 1, m) * calc(m + 1, r)) % mod;
    return dp[l][r] = res;
}
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    cin >> n;
    for(int i = 1; i <= n; i++)
        cin >> b[i];
    for(int i = 1; i <= n; i++)
        for(int j = 1; j <= n; j++)
        dp[i][j] = -1;
    cout << calc(2, n);
    return 0;
}


#include <bits/stdc++.h>
#define mod 1000000007
using namespace std;

const int NMAX = 500;
int dp[NMAX + 10][NMAX + 10];
int lista[NMAX + 10][NMAX + 10];

int b[NMAX + 10];

int main()
{
	int n;
	cin >> n;
	for (int i = 1; i <= n; i++)
		cin >> b[i];

	for (int i = 1; i <= n; i++)
		lista[i][i] = dp[i][i] = 1;

	for (int l = 2; l <= n; l++) {
		for (int i = 1; i + l - 1 <= n; i++) {
			int j = i + l - 1;
			dp[i][j] = lista[i + 1][j];
			lista[i][j] = dp[i][j];
			for (int k = i; k < j; k++)
				lista[i][j] = (lista[i][j] + 1LL * dp[i][k] * lista[k + 1][j] * (b[i] < b[k + 1])) % mod;
		}
	}

	cout << dp[1][n] << '\n';

	return 0;
}


#include <bits/stdc++.h>
using namespace std;

#pragma GCC optimize("O2,no-stack-protector,unroll-loops,fast-math")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//#pragma GCC optimize("Os")

#define F first
#define S second
#define pb push_back
#define SZ(x) (ll)(x.size())
#define all(x) x.begin(),x.end()
#define MP make_pair

typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> pll;

//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

const ll maxn=5e2+10, maxm=1e3+10, lg=21, mod=1e9+7, inf=1e18;

ll n,b[maxn],dp[maxn][maxn];

int main(){
	ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);

	for(int i=1;i<maxn;i++) dp[i][i]=dp[i][i-1]=1;
	cin>>n;
	for(int i=1;i<=n;i++) cin>>b[i];
	for(int t=2;t<=n-1;t++)for(int l=2,r=2+t-1;r<=n;l++,r++)for(int m=l;m<=r;m++)if(m==r || b[m+1]>b[l]) dp[l][r]+=dp[l+1][m]*dp[m+1][r]%mod, dp[l][r]%=mod;
	cout<<dp[2][n];

	return 0;
}


//
// Created by Ильдар Ялалов on 14.01.2020.
//
//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int inf_int = 1e9 + 100;
const ll inf_ll = 8e18;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef long double dbl;
typedef unsigned int uint;
#define pb push_back
#define eb emplace_back
const double pi = 3.1415926535898;
#define dout if(debug) cout
#define fi first
#define se second
#define sp setprecision
#define sz(a) (int(a.size()))
#define mp make_pair
#define all(a) a.begin(),a.end()

#ifdef zxc

#include "debug.h"

#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#define debug_arr(...) 42
#endif

bool debug = 0;
const int MAXN = (1e6) + 100;
const int LOG = 21;
const int mod = 1e9 + 7;
const int MX = (3e6 + 10);

template<uint MD>
struct ModInt {
    using M = ModInt;
    uint v;

    ModInt() : v{0} {}

    ModInt(ll _v) : v{normS(_v % MD + MD)} {}

    explicit operator bool() const { return v != 0; }

    static uint normS(uint x) { return (x < MD) ? x : x - MD; };

    static M make(uint x) {
        M m;
        m.v = x;
        return m;
    }

    static M inv(const M &x) { return x.pow(MD - 2); }

    M operator+(const M &r) const { return make(normS(v + r.v)); }

    M operator-(const M &r) const { return make(normS(v + MD - r.v)); }

    M operator*(const M &r) const { return make(ull(v) * r.v % MD); }

    M operator/(const M &r) const { return *this * inv(r); }

    M &operator+=(const M &r) { return *this = *this + r; }

    M &operator-=(const M &r) { return *this = *this - r; }

    M &operator*=(const M &r) { return *this = *this * r; }

    M &operator/=(const M &r) { return *this = *this / r; }

    M pow(ll n) const {
        M x = *this, r = 1;
        while (n) {
            if (n & 1) r *= x;
            x *= x;
            n >>= 1;
        }
        return r;
    }
};

using Mint = ModInt<mod>;

int a[512];
Mint dp1[512][512];
Mint dp2[512][512];

void solve() {
    int n;
    cin >> n;
    for (int i = 1; i <= n; ++i) {
        cin >> a[i];
    }

    for (int i = 1; i <= n; ++i) {
        dp1[i][i] = 1;
        dp2[i][i] = 1;
    }

    for (int len = 2; len <= n; ++len) {
        for (int l = 1; l + len - 1 <= n; ++l) {
            int r = l + len - 1;
            dp1[l][r] = dp2[l + 1][r];
            dp2[l][r] += dp1[l][r];
            for (int m = l + 1; m <= r; ++m) {
                if (a[l] < a[m]) {
                    dp2[l][r] += dp1[l][m - 1] * dp2[m][r];
                }
            }
        }
    }

    cout << dp1[1][n].v << "\n";
}

// CHECK LIMITS (n <= 10^5)
// CHECK CORNER CASES ( n==1)
signed main() {

#ifdef zxc
    freopen("../output.txt", "r", stdin);
    // freopen("../output1.txt", "w", stdout);
#else
#endif //zxc
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cout.setf(ios::fixed);
    cout.precision(15);

    int t = 1;
    while (t--)
        solve();

    debug(1.0 * clock() / CLOCKS_PER_SEC);
}


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

using namespace __gnu_pbds;
using namespace std;

#define pb push_back
#define f first
#define s second
#define mp make_pair
#define SZ(x) ((int)(x.size()))
#define FOI(i, a, n) for(int i = int(a); i <= int(n); i++)
#define FOD(i, a, n) for(int i = int(a); i >= int(n); i--)
#define IN(x, y) ((y).find(x) != (y).end())
#define ALL(t) t.begin(),t.end()
#define MSET(tabl,i) memset(tabl, i, sizeof(tabl))
#define PSET(x,y) fixed<<setprecision(y)<<lf(x)
#define DBG(c) cout << #c << " = " << c << endl;
#define RTIME ((double)clock()/(double)CLOCKS_PER_SEC)
#define sync ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);

typedef long long ll;
typedef long double lf;
typedef pair < int, int > pii;
typedef pair < ll, ll > pll;
typedef vector < int > vi;
typedef vector<vi> vvi;
typedef complex<double> base;

#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
    template <typename Arg1>
    void __f(const char* name, Arg1&& arg1){
        cout << name << " : " << arg1 << std::endl;
        //use cerr if u want to display at the bottom
    }
    template <typename Arg1, typename... Args>
    void __f(const char* names, Arg1&& arg1, Args&&... args){
        const char* comma = strchr(names + 1, ','); cout.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
    }
#else
#define trace(...)
#endif

const int N = 5e5 + 5;
const int lgN = 1e6+5;
const int te = 3e8+1;
const ll MOD = 1e9 + 7;
const lf pi = 3.141592653589793238462643383;
const ll IMAX = 1e18;
const double PI = 3.141592653589793;

template<class T>
using max_pq = priority_queue<T>;
template<class T>
using min_pq = priority_queue<T,vector<T>,greater<T>>;
template<class T>
using OST = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

ll x,y;
template<class T> T gcd(T a,T b){ if(a==0) {x=0,y=1; return b;}T gc=gcd(b%a,a);T temp;temp=x;x=y-(b/a)*temp;y=temp;return gc;}

//(a^x)%m
ll po(ll a, ll x,ll m){ if(x==0){return 1;}ll ans=1;ll k=1;  while(k<=x) {if(x&k){ans=((ans*a)%m);} k<<=1; a*=a; a%=m; }return ans; }

ll a[505];
ll dp[505][505];

int main()
{
    sync
    int n;
    cin>>n;
    FOI(i,1,n)
    {
        cin>>a[i];
    }
    FOI(i,1,n)
        dp[i][i] = 1;
    FOI(i,2,n)
    {
        FOI(j,1,n+1-i)
        {
            dp[j][i+j-1] = dp[j+1][i+j-1];
            FOI(k, j+2, (j+i-1))
            {
                if(a[j+1] < a[k])
                {
                    dp[j][i+j-1] = (dp[j][i+j-1] + (dp[j+1][k-1] * dp[k-1][i+j-1])%MOD)%MOD;
                }
            }
        }
    }
    cout<<dp[1][n]<<endl;
}


#include <bits/stdc++.h>
using namespace std;

#define int long long
const int MN = 505, MOD = 1000 * 1000 * 1000 + 7;
int a[MN], dp[MN][MN];

int32_t main() {
	int n;
	cin >> n;
	for (int i = 0; i < n; i++)
		cin >> a[i];
	for (int i = 1; i <= n; i++)
		dp[i][i] = 1;
//	for (int i = 1; i < n; i++)
//		dp[i][i + 1] = 1;
	for (int s = 1; s < n; s++)
		for (int l = 1; l < n; l++) {
			int r = l + s;
			if (r > n)
				continue;
			dp[l][r] = dp[l + 1][r];
//			cerr << l <<  ' ' << r << ' ' << dp[l][r] << endl;
			for (int i = l + 1; i < r; i++)
				if (a[i] > a[l]) {
					(dp[l][r] += dp[l + 1][i] * dp[i][r] % MOD) %= MOD;
				}
		}
	cout << dp[1][n];
}


#include <bits/stdc++.h>
using namespace std;
#define int long long
const int MN = 505, MOD = 1000 * 1000 * 1000 + 7;
int a[MN], dp[MN][MN];
int32_t main() {
	int n;
	cin >> n;
	for (int i = 0; i < n; i++)
		cin >> a[i], dp[i + 1][i + 1] = 1;
	for (int s = 1; s < n; s++)
		for (int l = 1; l <= n - s; l++) {
			int r = l + s;
			dp[l][r] = dp[l + 1][r];
			for (int i = l + 1; i < r; i++)
				if (a[i] > a[l])
					(dp[l][r] += dp[l + 1][i] * dp[i][r] % MOD) %= MOD;
		}
	cout << dp[1][n];
}


#include <bits/stdc++.h>

using namespace std;
long long n;
long long a[505];
long long dp[505][505];
long long du=1e9+7;
long long tinh(long long l,long long r)
{
    if (dp[l][r]!=-1) return dp[l][r];
    dp[l][r]=0;
    if (l==r) dp[l][r]=1;
    else dp[l][r]=tinh(l+1,r);
    for (long long i=l+1;i<r;i++)
    if (a[l+1]<a[i+1])
    {
        dp[l][r]=(dp[l][r]+tinh(l+1,i)*tinh(i,r))%du;
    }
    return dp[l][r];
}
int main()
{
    cin>>n;
    for (long long i=1;i<=n;i++) cin>>a[i];
    memset(dp,-1,sizeof(dp));
    cout<<tinh(1,n);
    return 0;
}
//road_to_star


#include <cstdio>
#include <cstring>
#include <iostream>
using namespace std;

typedef long long ll;
const int MAXN = 550;
const int MOD = 1e9 + 7;
int a[MAXN], dp[MAXN][MAXN][2];

int DFS(int l, int r, int typ){
//	printf("l:%d r:%d typ:%d\n", l, r, typ);
	if(l == r) return 1;
	if(dp[l][r][typ] != -1) return dp[l][r][typ];
	if(typ == 0){
		int rnt = 0;
		for(int i = l + 1; i <= r; ++ i)
			if(a[l] < a[i])
				rnt += (ll) DFS(l, i - 1, 1) * DFS(i, r, 0) % MOD,
				rnt %= MOD;
		rnt += DFS(l, r, 1), rnt %= MOD;
		return dp[l][r][typ] = rnt;
	}
	else{
		int rnt = 0;
		for(int i = l + 1; i <= r; ++ i)
			if(a[l + 1] < a[i])
				rnt += (ll) DFS(l + 1, i - 1, 1) * DFS(i, r, 0) % MOD,
				rnt %= MOD;
		rnt += DFS(l + 1, r, 1), rnt %= MOD;
		return dp[l][r][typ] = rnt;
	}
}

int main(){
	memset(dp, -1, sizeof(dp));
	int n; scanf("%d", &n);
	for(int i = 1; i <= n; ++ i) scanf("%d", &a[i]);
	printf("%d\n", DFS(1, n, 1));
	return 0;
}


#include <cstdio>
#include <cstring>
#include <iostream>
using namespace std;

typedef long long ll;
const int MAXN = 550;
const int MOD = 1e9 + 7;
int a[MAXN];

int DFS(int l, int r, int typ){
//	printf("l:%d r:%d typ:%d\n", l, r, typ);
	if(l == r) return 1;
	if(typ == 0){
		int rnt = 0;
		for(int i = l + 1; i <= r; ++ i)
			if(a[l] < a[i])
				rnt += (ll) DFS(l, i - 1, 1) * DFS(i, r, 0) % MOD,
				rnt %= MOD;
		rnt += DFS(l, r, 1), rnt %= MOD;
		return rnt;
	}
	else{
		int rnt = 0;
		for(int i = l + 1; i <= r; ++ i)
			if(a[l + 1] < a[i])
				rnt += (ll) DFS(l + 1, i - 1, 1) * DFS(i, r, 0) % MOD,
				rnt %= MOD;
		rnt += DFS(l + 1, r, 1), rnt %= MOD;
		return rnt;
	}
}

int main(){
	int n; scanf("%d", &n);
	for(int i = 1; i <= n; ++ i) scanf("%d", &a[i]);
	printf("%d\n", DFS(1, n, 1));
	return 0;
}


#ifdef LOCAL
#pragma warning(disable:4996)
#pragma warning(disable:4244)
#pragma warning(disable:4554)
#define gets gets_s

#endif
#include<map>
#include<set>
#include<cmath>
#include<stack>
#include<queue>
#include<cmath>
#include<vector>
#include<string>
#include<cctype>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<bitset>
#define ll long long
#define cl(a,x) memset((a),(x),sizeof(a))
#define lson 2*i
#define rson 2*i+1
#define sf scanf
#define ull unsigned long long
#define lowbit(x) (x)&(-x)
#define pii pair<int,int>
#define ti tree[i]
ll q_pow(ll x, ll n, ll mod) { ll ret = 1; while (n) { if (n & 1) ret = x * ret%mod; x = x * x%mod; n >>= 1; }return ret; }
ll __gcd(ll x, ll y) { if (!y) return x; return __gcd(y, x%y); }
int dx[] = { -1,1,0,0 };
int dy[] = { 0,0,-1,1 };
using namespace std;
const ll INF = 0x3f3f3f3f;
const int mod = 1e9 + 7;
const int maxn = 500 + 50;

ll dp[maxn][maxn];
int val[maxn];

ll dfs(int le, int ri) {
	if (dp[le][ri] != -1) return dp[le][ri];
	dp[le][ri] = 0;
	if (le == ri) return dp[le][ri] = 1;
	dp[le][ri] = dfs(le + 1, ri);
	for (int i = le + 1; i < ri; i++) {
		if(val[le + 1] < val[i+ 1])
			dp[le][ri] = (dp[le][ri] + dfs(le + 1, i)*dfs(i + 1, ri) % mod) % mod;
	}
	return dp[le][ri];
}

signed main(int argc, char *argv[]) {
	if (argc == 2 && strcmp("-debug", argv[1]) == 0) {
		freopen("in.txt", "r", stdin);
		freopen("out.txt", "w", stdout);
	}

	int n;
	cl(dp, -1LL);
	cin >> n;
	for (int i = 1; i <= n; i++) {
		cin >> val[i];
	}
	dfs(1, n);
	cout << dp[1][n] << endl;

	return 0;
}


#ifdef LOCAL
#pragma warning(disable:4996)
#pragma warning(disable:4244)
#pragma warning(disable:4554)
#define gets gets_s

#endif
#include<map>
#include<set>
#include<cmath>
#include<stack>
#include<queue>
#include<cmath>
#include<vector>
#include<string>
#include<cctype>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<bitset>
#define ll long long
#define cl(a,x) memset((a),(x),sizeof(a))
#define lson 2*i
#define rson 2*i+1
#define sf scanf
#define ull unsigned long long
#define lowbit(x) (x)&(-x)
#define pii pair<int,int>
#define ti tree[i]
ll q_pow(ll x, ll n, ll mod) { ll ret = 1; while (n) { if (n & 1) ret = x * ret%mod; x = x * x%mod; n >>= 1; }return ret; }
ll __gcd(ll x, ll y) { if (!y) return x; return __gcd(y, x%y); }
int dx[] = { -1,1,0,0 };
int dy[] = { 0,0,-1,1 };
using namespace std;
const ll INF = 0x3f3f3f3f;
const int mod = 1e9 + 7;
const int maxn = 500 + 50;

ll dp[maxn][maxn];
int val[maxn];

ll dfs(int le, int ri) {
	if (dp[le][ri] != -1) return dp[le][ri];
	dp[le][ri] = 0;
	if (le == ri) return dp[le][ri] = 1;
	for (int i = le + 1; i <= ri; i++) {
		if(val[le + 1] < val[i+ 1] || i == ri)
			dp[le][ri] = (dp[le][ri] + dfs(le + 1, i)*dfs(i, ri) % mod) % mod;
	}
	return dp[le][ri];
}

signed main(int argc, char *argv[]) {
	if (argc == 2 && strcmp("-debug", argv[1]) == 0) {
		freopen("in.txt", "r", stdin);
		freopen("out.txt", "w", stdout);
	}

	int n;
	cl(dp, -1LL);
	cin >> n;
	for (int i = 1; i <= n; i++) {
		cin >> val[i];
	}
	dfs(1, n);
	cout << dp[1][n] << endl;

	return 0;
}


#include <bits/stdc++.h>

#define ll long long
#define sz(x) ((int) (x).size())
#define all(x) (x).begin(), (x).end()
#define vi vector<int>
#define pii pair<int, int>
#define rep(i, a, b) for(int i = (a); i < (b); i++)
using namespace std;
template<typename T>
using minpq = priority_queue<T, vector<T>, greater<T>>;

// b1 = 1
// select increasing subsequence, dp

const int N = 505, M = 1e9 + 7;
int n, b[N];
ll dp[N][N];

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin >> n;
    rep(i, 0, n) {
        cin >> b[i];
    }
    rep(len, 1, n + 1) {
        rep(i, 0, n - len + 1) {
            if(len == 1) {
                dp[len][i] = 1;
            }else {
                dp[len][i] = dp[len - 1][i + 1];
                rep(k, i + 2, i + len) {
                    if(b[k] > b[i + 1]) {
                        dp[len][i] = (dp[len][i] + dp[k - i - 1][i + 1] * dp[i + len - k][k]) % M;
                    }
                }
            }
        }
    }
    cout << dp[n][0] << '\n';
}


#include <bits/stdc++.h>

#define ll long long
#define sz(x) ((int) (x).size())
#define all(x) (x).begin(), (x).end()
#define vi vector<int>
#define pii pair<int, int>
#define rep(i, a, b) for(int i = (a); i < (b); i++)
using namespace std;
template<typename T>
using minpq = priority_queue<T, vector<T>, greater<T>>;

// b1 = 1
// select increasing subsequence, dp

const int N = 505, M = 1e9 + 7;
int n, b[N];
ll dp[N][N];

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin >> n;
    rep(i, 0, n) {
        cin >> b[i];
    }
    rep(len, 0, n) {
        rep(i, 0, n - len + 1) {
            if(len == 0) {
                dp[len][i] = 1;
            }else {
                dp[len][i] = dp[len - 1][i + 1];
                rep(k, i + 1, i + len) {
                    if(b[k] > b[i]) {
                        dp[len][i] = (dp[len][i] + dp[k - i - 1][i + 1] * dp[i + len - k][k]) % M;
                    }
                }
            }
            // cout << dp[len][i] << ' ';
        }
        // cout << endl;
    }
    cout << dp[n - 1][1] << '\n';
}


#include <bits/stdc++.h>

#define ll long long
#define sz(x) ((int) (x).size())
#define all(x) (x).begin(), (x).end()
#define vi vector<int>
#define pii pair<int, int>
#define rep(i, a, b) for(int i = (a); i < (b); i++)
using namespace std;
template<typename T>
using minpq = priority_queue<T, vector<T>, greater<T>>;

// b1 = 1
// select increasing subsequence, dp

const int N = 505, M = 1e9 + 7;
int n, b[N];
ll dp[N][N];

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin >> n;
    rep(i, 0, n) {
        cin >> b[i];
    }
    rep(len, 1, n + 1) {
        rep(i, 0, n - len + 1) {
            if(len == 1) {
                dp[len][i] = 1;
            }else {
                dp[len][i] = dp[len - 1][i + 1];
                rep(k, i + 2, i + len) {
                    if(b[k] > b[i + 1]) {
                        dp[len][i] = (dp[len][i] + dp[k - i - 1][i + 1] * dp[k][i + len - k]) % M;
                    }
                }
            }
        }
    }
    cout << dp[n][0] << '\n';
}


#define main fakemain
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
typedef pair<int,int> pii;
typedef long long ll;
typedef double ld;
typedef vector<int> vi;
#define fi first
#define se second
#define fe first
#define FO(x) {freopen(#x".in","r",stdin);freopen(#x".out","w",stdout);}
#define Edg int M=0,fst[SZ],vb[SZ],nxt[SZ];void ad_de(int a,int b){++M;nxt[M]=fst[a];fst[a]=M;vb[M]=b;}void adde(int a,int b){ad_de(a,b);ad_de(b,a);}
#define Edgc int M=0,fst[SZ],vb[SZ],nxt[SZ],vc[SZ];void ad_de(int a,int b,int c){++M;nxt[M]=fst[a];fst[a]=M;vb[M]=b;vc[M]=c;}void adde(int a,int b,int c){ad_de(a,b,c);ad_de(b,a,c);}
#define es(x,e) (int e=fst[x];e;e=nxt[e])
#define esb(x,e,b) (int e=fst[x],b=vb[e];e;e=nxt[e],b=vb[e])
#define SZ 666666

int n,b[SZ],u[505][505],g[505][505];
const int MOD=1e9+7;
void main()
{
#ifdef ONLINE_JUDGE //don't mix cin/scanf, cout/printf!
	cin.tie(0); cout.tie(0);
	ios::sync_with_stdio(0);
#endif
	cin>>n;
	for(int i=1;i<=n;++i)
		cin>>b[i];
	for(int l=n;l>=1;--l)
	{
		for(int r=1;r<=n;++r)
		{
			if(l!=r)
				g[l][r]=u[l+1][r];
			else g[l][r]=1;
			u[l][r]=g[l][r];
			for(int s=l;s<r;++s)
				if(b[l]<b[s+1])
					u[l][r]=(u[l][r]+(ll)u[s+1][r]*g[l][s])%MOD;
		}
	}
	cout<<g[1][n]<<"\n";
}

#undef main
#ifndef ONLINE_JUDGE
void rmv_() {remove("IN_TEMP_F_UlllOpB");remove("OUT_TEMP_F_UlllOpB");} /*edit if you want to don't want your temps removed*/ string to_str__booster__(int x) {char buf[100];sprintf(buf,"%d",x);return buf;} vector<string> clean__booster___(string u){u.push_back('\n');vector<string> w;string c;for(auto t:u){if(t=='\n'||t=='\r'){while(c.size()&&c.back()==' ') c.pop_back();if(c.size()) w.push_back(c);c.clear();}else c.push_back(t);}return w;}int to_num__booster__(string s){int w=atoi(s.c_str());char buf[10];sprintf(buf,"%d",w);if(buf==s) return w;return -1;}int main(int argc,char**argv){if(argc==2&&(string)argv[1]=="r") {fakemain();return 0;}vector<string> code;{std::ifstream t(__FILE__);std::stringstream buffer;buffer << t.rdbuf();t.close(); code=clean__booster___(buffer.str());}int num_samples=0;map<pair<int,int>,string> samples;{string cs="";pair<int,int> id(-1,-1);for(auto s:code){if(s.substr(0,4)=="*o* "){if(id.second!=-1)samples[id]=cs;id=make_pair(-1,-1),cs="";string g=s.substr(4);string si="Sample Input ";string so="Sample Output ";if(g.back()==':'&&g.substr(0,si.size())==si){int w=to_num__booster__(g.substr(si.size(),g.size()-si.size()-1));if(w>=1) id=make_pair(w,0);}if(g.back()==':'&&g.substr(0,so.size())==so){int w=to_num__booster__(g.substr(so.size(),g.size()-so.size()-1));if(w>=1) id=make_pair(w,1);}}else cs=cs+s+"\n";}while(samples.count(make_pair(num_samples+1,0))&&samples.count(make_pair(num_samples+1,1)))++num_samples;}if(!num_samples){fakemain();return 0;}int w; int cap=1,sil=0; if(argc==2) {w=to_num__booster__(argv[1]); cerr<<w<<"... "; cap=2;} else {cerr<<num_samples<<" samples. autofeed: ";cerr.flush();string u;getline(cin,u);if(u=="a"){cerr<<"testing all samples..."<<endl;for(int i=1;i<=num_samples;++i) {cerr<<"testing sample ";int rt=system(((string)"\""+argv[0]+"\" "+to_str__booster__(i)).c_str()); if(rt) cerr<<endl<<"WA/RE (return value "<<rt<<")\n",exit(-1);}cerr<<"all samples passed!"<<endl;exit(0);}while(1){if(u.size()&&u.back()=='r')u.pop_back(),cap=0;else if(u.size()&&u.back()=='s')u.pop_back(),sil=1,cap=0;else break;}w=to_num__booster__(u);}string in,out;rmv_();if(w>=1&&w<=num_samples){in=samples[make_pair(w,0)];out=samples[make_pair(w,1)];ofstream o("IN_TEMP_F_UlllOpB");o<<in; o.close();freopen("IN_TEMP_F_UlllOpB","r",stdin);if(cap){if(cap!=2) cerr<<"============= testcase "<<w<<" (captured) ============="<<endl;freopen("OUT_TEMP_F_UlllOpB","w",stdout);}else{cerr<<"================== testcase "<<w<<" ==================="<<endl;}}else{cap=0; cerr<<"=============== normal run ================"<<endl;}time_t start_time=clock(); fakemain(); time_t end_time=clock(); bool force_stop=false;if(w>=1&&w<=num_samples){string out_str;if(cap){fclose(stdout);std::ifstream t("OUT_TEMP_F_UlllOpB");std::stringstream buffer;buffer << t.rdbuf();t.close();out_str=buffer.str();if(cap!=2) cerr<<out_str;}if(sil);else{if(cap!=2) cerr<<endl<<"================================================="<<endl<<"sample output:"<<endl<<out<<endl;if(cap){if(clean__booster___(out)==clean__booster___(out_str))cerr<<"compare passed ("<<int((end_time - start_time)*1000.0/CLOCKS_PER_SEC+0.5)<<"ms)!"<<endl;else {cerr<<"compare failed ("<<int((end_time - start_time)*1000.0/CLOCKS_PER_SEC+0.5)<<"ms)!"<<endl; force_stop=true; if(cap==2) {cerr<<"=============== your output ==============="<<endl<<out_str<<endl<<"============== sample output =============="<<endl<<out<<endl;}}}}}fclose(stdin);rmv_(); if(force_stop) exit(-1);}
#else
int main(){fakemain();}
#endif
/*
*o* Sample Input 1:
3
1 2 3
*o* Sample Output 1:
2
*o* Sample Input 2:
3
1 3 2
*o* Sample Output 2:
1
*o* This chunk of comment is used for auto-testing. Please don't modify.
*/


//#include <GOD>
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb push_back
#define len length
#define FAST_IO ios_base::sync_with_stdio(false); cin.tie(NULL);
#define frei freopen("input.txt","r",stdin)
#define freo freopen("output.txt","w",stdout)

const ll inf=1e18;
const ll mod=1e9+7;
const ll maxn=5e2+10,maxl=2e6+10;

ll n;
ll b[maxn],dp1[maxn][maxn],dp2[maxn][maxn];

int main(){
	FAST_IO;
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>b[i];
	}
	b[n]=inf;
	for(int i=0;i<=n;i++){
		dp2[i][0]=1;
	}
	for(int i=n-1;i>=0;i--){
		for(int j=1;j<=n-1-i+1;j++){
			dp1[i][j]=dp2[i+1][j-1];
			for(int k=1;k<j;k++){
				if(b[i+k]>=b[i]){
					dp2[i][j]+=(dp1[i][k])*(dp2[i+k][j-k])%mod;
					dp2[i][j]%=mod;
				}
			}
			dp2[i][j]+=dp1[i][j];
			dp2[i][j]%=mod;
//			cout<<dp1[i][j]<<' '<<dp2[i][j]<<endl;
		}
	}
	/*for(int i=0;i<n;i++){
		cout<<dp1[i][n-1-i+1]<<endl;
	}*/
	cout<<dp1[0][n]<<endl;
}


//Be Name Khoda, Besmellah Rahmane Rahim, In The Name Of God;
//#include<bits/stweight++.h>
#include<iostream>
#include<vector>
#include<algorithm>
#include<cmath>
#include<set>
#include<queue>
#include<deque>
#include<map>
#include<stack>
#include<bitset>
#include<list>
#include<cassert>
#include<numeric>
#include<stdio.h>
#include<string.h>
#include<iomanip>
#include<unordered_map>
#include<unordered_set>
#include<fstream>

using namespace std;

const int N = 1e3 + 5;
const int mod = 1e9 + 7;
long long dp[N][N];
long long a[N];

int main()
{
    int n;
    cin >> n;
    for (int i = 0; i < n; i++)
    {
        cin >> a[i];
    }
    for (int i = 0; i <= n; i++)
    {
        dp[i][i] = 1;
    }
    for (int l = 1; l < n; l++)
    {
        for (int s = 0; s + l <= n; s++)
        {
            for (int i = s; i <= s + l; i++)
            {
                if (i == s + l || a[i] > a[s])
                {
                    dp[s][s + l] += dp[s + 1][i] * dp[i][s + l];
                    dp[s][s + l] %= mod;
                }
            }
        }
    }
    cout << dp[1][n] << endl;
}


#pragma GCC optimize("Ofast")

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

using namespace std;
using namespace __gnu_pbds;

typedef long long ll;

typedef
tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> orderedSet;

#define pb push_back
#define F first
#define S second
#define all(a) (a).begin(), (a).end()

#define for1(i0, l0, r0) for (int i0 = l0; i0 < r0; ++i0)
#define for2(i0, l0, r0) for (int i0 = l0; i0 <= r0; ++i0)
#define forn(i0, n0) for (int i0 = 0; i0 < n0; ++i0)
#define forn1(i0, n0) for (int i0 = 1; i0 < n0; ++i0)
#define forr(i0, n0) for (int i0 = n0; i0 >= 0; --i0)
#define forr1(i0, r0, l0) for (int i0 = r0; i0 > l0; --i0)
#define forr2(i0, r0, l0) for (int i0 = r0; i0 >= l0; --i0)

#define Sort(a) sort(all(a))
#define Reverse(a) reverse(all(a))
#define relaxMax(a, b) a = max(a, b)
#define relaxMin(a, b) a = min(a, b)

typedef long double ld;
#define ui unsigned int
#define ull unsigned long long

typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
typedef pair<string, string> pss;

typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<double> vd;
typedef vector<ld> vld;
typedef vector<bool> vb;
typedef vector<string> vs;

typedef vector<pii> vpii;
typedef vector<pll> vpll;
typedef vector<pdd> vpdd;

typedef vector<vi> vvi;
typedef vector<vd> vvd;
typedef vector<vll> vvll;
typedef vector<vb> vvb;

#define vpss vector<pss>
#define vvs vector<vs>
#define vvpii vector<vpii>
#define vvpll vector<vpll>
#define vpt vector<pt>
#define vvvi vector<vvi>
#define vsi vector<set<int>>
#define ss second
#define ff first

#define printvi(arr) for (int x0 : arr) cout << x0 << ' '; cout << '\n';
#define printvll(arr) for (ll x0 : arr) cout << x0 << ' '; cout << '\n';
#define printpair(pair0) cout << pair0.F << ' ' << pair0.S << '\n';
#define printvp(arr) for (auto pair0 : arr) printpair(pair0);
#define initArray(arr, N0, X0) memset(arr, X0, N0 * sizeof(int))
//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

void init() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    //cout.precision(16);
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
}

const int mod = 1e9 + 7;

void solve() {
    int n;
    cin >> n;
    vi a(n);
    forn(i, n) cin >> a[i];
    vvll dp(n, vll(n));
    forn(i, n) {
        dp[i][i] = 1;
        if (i + 1 < n) dp[i + 1][i] = 1;
    }
    for2(l, 2, n) {
        for (int i = 0, j = i + l - 1; j < n; ++i, j++) {
            dp[i][j] = dp[i + 1][j];
            for (int k = i + 1; k < j; k++) {
                if (a[k + 1] > a[i + 1]) {
                    dp[i][j] += dp[i + 1][k] * dp[k][j];
                    dp[i][j] %= mod;
                }
            }
        }
    }
    cout << dp[0][n - 1] << '\n';
}

bool multitest = false;

int main() {
    init();
    int t = 1;
    if (multitest) cin >> t;
    forn(i, t) solve();
}


#include <bits/stdc++.h>
using namespace std;

#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define Max(x,y,z) max(x,max(y,z))
#define Min(x,y,z) min(x,min(y,z))
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define trace1(x)                cerr<<#x<<": "<<x<<endl
#define trace2(x, y)             cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define trace3(x, y, z)          cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define trace4(a, b, c, d)       cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
#define trace5(a, b, c, d, e)    cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl
#define trace6(a, b, c, d, e, f) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<<f<<endl

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef pair<long long, long long> pll;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef pair<ll,ll> ii;
typedef vector<pair<ll,ll> > vii;
typedef vector<long long> vll;
typedef vector<vll> vvll;
typedef pair<ll,pair<ll,ll> > iii;
#define PI 3.141592653589793
#define mod (ll)(1000*1000*1000+7)
//# define N 300005
template<typename T> T gcd(T a,T b) { if(a==0) return b; return gcd(b%a,a); }
template<typename T> T pow(T a,T b, ll m){T ans=1; while(b>0){ if(b%2==1) ans=((ans%m)*(a%m))%m; b/=2; a=((a%m)*(a%m))%m; } return ans%m; }
# define INF (ll)1e18
# define LN 20
typedef pair<ll,pair<ll,ll> > pii;
# define INF1 (ll)1e10
# define maxn 500005
# define offset 2000005
#define N 100005
const ld eps = 1e-10L;

/*************************************************
struct Coupon {
	ll l;
	ll r;
	ll id;

	Coupon(ll l, ll r, ll id): l(l), r(r), id(id) {} // Initialization

	bool operator<(const Coupon& c) { // Sorting
		return l < c.l;
	}
};

**************************************************/
ll a[505];
ll dp[505][505];

ll dfs(ll l,ll r)
{
	//trace4(l,r,a[l],a[r]);
	ll ans=0;
	if(l==r)
		return 1;
	if(dp[l][r]!=-1)
		return dp[l][r];
	for(ll i=l+1;i<=r;i++)
	{
		if(i!=r && a[l+1]>=a[i+1])
			continue;
		ans+=(dfs(l+1,i)*dfs(i,r))%mod;
		ans%=mod;
	}
	return dp[l][r]=(ans%mod);
}

int main()
{
	ll n;
	cin >> n;
	for(ll i=1;i<=n;i++)
		cin >> a[i];
	memset(dp,-1,sizeof dp);
	cout << dfs(1,n);
}


//HovalHaq!
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int Mx = 512, M = 1000 * 1000 * 1000 + 7;
int F[Mx][Mx];

int32_t main() {
	int n; cin >> n;
	if(n == 1) return cout << 1, 0;
	vector<int> A(n);
	for(int i = 0; i < n; i++)
		cin >> A[i];
	for(int i = 1; i < n; i++)
		F[i][i] = 1;
	for(int l = 1; l < n; l++)
		for(int i = 0; i + l < n; i++) {
			F[i][i + l] = F[i + 1][i + l];
			for(int j = i + 1; j <= i + l; j++)
				if(A[i] < A[j])
					F[i][i + l] = (F[i][i + l] + F[i + 1][j] * F[j][i + l]) % M;
		}
	cout << F[1][n - 1];
}


//HovalHaq!
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int Mx = 512, M = 1000 * 1000 * 1000 + 7;
int F[Mx][Mx];

int32_t main() {
	int n; cin >> n;
	vector<int> A(n);
	for(int i = 0; i < n; i++)
		cin >> A[i];
	for(int i = 0; i < n; i++)
		F[i][i] = 1;
	for(int l = 1; l < n; l++)
		for(int i = 0; i + l < n; i++) {
			F[i][i + l] = F[i + 1][i + l];
			for(int j = i + 1; j <= i + l; j++)
				if(A[i] < A[j])
					F[i][i + l] = (F[i][i + l] + F[i + 1][j] * F[j][i + l]) % M;
		}
	cout << F[1][n - 1];
}


//HovalHaq!
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int Mx = 512, M = 1000 * 1000 * 1000 + 7;
int F[Mx][Mx];

int32_t main() {
	int n; cin >> n;
	if(n == 1) return cout << 1, 0;
	vector<int> A(n);
	for(int i = 0; i < n; i++)
		cin >> A[i];
	for(int i = 1; i < n; i++)
		F[i][i - 1] = 1;
	for(int l = 1; l < n; l++)
		for(int i = 0; i + l < n; i++) {
			F[i][i + l] = F[i + 1][i + l];
			for(int j = i + 1; j <= i + l; j++)
				if(A[i] < A[j])
					F[i][i + l] = (F[i][i + l] + F[i + 1][j] * F[j][i + l]) % M;
		}
	cout << F[1][n - 1];
}


//HovalHaq!
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int Mx = 512, M = 1000 * 1000 * 1000 + 7;
int F[Mx][Mx];

int32_t main() {
	int n; cin >> n;
	vector<int> A(n);
	for(int i = 0; i < n; i++)
		cin >> A[i];
	for(int i = 0; i < n; i++)
		F[i][i] = F[i + 1][i] = 1;
	for(int l = 1; l < n; l++)
		for(int i = 0; i + l < n; i++) {
			F[i][i + l] = F[i + 1][i + l];
			for(int j = i + 1; j <= i + l; j++)
				if(A[i] < A[j])
					F[i][i + l] = (F[i][i + l] + F[i + 1][j - 1] * F[j][i + l]) % M;
		}
//	for(int i = 0; i < n; i++) {
//		for(int j = 0; j < n; j++)
//			cout << F[i][j] << " ";
//		cout << "\n";
//	}
	cout << F[1][n - 1];
}


#include<bits/stdc++.h>
using namespace std;

const int N = 500 + 10, mod = 1e9 + 7;
int n, a[N], dp[N][N][N], idx[N];

int sum(int &a, int &b) {
	return ((1LL * a + b) % mod + mod) % mod;
}

int mul(int &a, int &b) {
	return ((1LL * a * b) % mod + mod) % mod;
}

int main() {
	ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
	cin >> n;
	for (int i = 0; i < n; i++)
		cin >> a[i];
	for (int i = 0; i < n; i++)
		idx[a[i]] = i;
	for (int i = 0; i <= n; i++)
		for (int j = 0; j <= n; j++)
			dp[i][i][j] = 1;
	for (int l = 1; l <= n; l++)
		for (int i = 0; i + l <= n; i++) {
			int j = i + l;
			for (int k = 1; k <= n; k++) {
				if (i <= idx[k] && idx[k] < j)
					dp[i][j][k] = mul(dp[i][idx[k]][k], dp[idx[k] + 1][j][n]);
				dp[i][j][k] = sum(dp[i][j][k - 1], dp[i][j][k]);
			}
		}
	return cout << dp[0][n][1] << "\n", 0;
}


#include<bits/stdc++.h>
using namespace std;

const int N = 500 + 10, mod = 1e9 + 7;
int n, a[N], dp[N][N];

int sum(int a, int b) {
	return ((1LL * a + b) % mod + mod) % mod;
}

int mul(int a, int b) {
	return ((1LL * a * b) % mod + mod) % mod;
}

int main() {
	ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
	cin >> n;
	for (int i = 0; i < n; i++)
		cin >> a[i];
	for (int i = 0; i < n; i++)
		dp[i][i] = dp[i][i + 1] = 1;
	for (int l = 2; l <= n; l++)
		for (int i = 0; i + l <= n; i++) {
			int j = i + l;
			dp[i][j] = dp[i + 1][j];
			for (int k = i + 1; k < j; k++)
				if (a[k] > a[i])
					dp[i][j] = sum(dp[i][j], mul(dp[i + 1][k], dp[k][j]));
		}
	return cout << dp[1][n] << "\n", 0;
}


#include<bits/stdc++.h>
using namespace std;

const int N = 500 + 10, mod = 1e9 + 7;
int n, a[N], dp[N][N];

int sum(int a, int b) {
	return ((1LL * a + b) % mod + mod) % mod;
}

int mul(int a, int b) {
	return ((1LL * a * b) % mod + mod) % mod;
}

int main() {
	ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
	cin >> n;
	for (int i = 0; i < n; i++)
		cin >> a[i];
	for (int i = 0; i < n; i++)
		dp[i][i] = dp[i][i + 1] = 1;
	dp[n][n] = 1;
	for (int l = 2; l <= n; l++)
		for (int i = 0; i + l <= n; i++) {
			int j = i + l;
			dp[i][j] = dp[i + 1][j];
			for (int k = i + 1; k < j; k++)
				if (a[k] > a[i])
					dp[i][j] = sum(dp[i][j], mul(dp[i + 1][k], dp[k][j]));
		}
	return cout << dp[1][n] << "\n", 0;
}


#include<bits/stdc++.h>
using namespace std;

const int N = 500 + 10, mod = 1e9 + 7;
int n, a[N], dp[N][N][N], ps[N][N][N], idx[N];

int sum(int a, int b) {
	return ((1LL * a + b) % mod + mod) % mod;
}

int mul(int a, int b) {
	return ((1LL * a * b) % mod + mod) % mod;
}

int main() {
	ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
	cin >> n;
	for (int i = 0; i < n; i++)
		cin >> a[i];
	for (int i = 0; i < n; i++)
		idx[a[i]] = i;
	for (int i = 0; i <= n; i++) {
		dp[i][i][0] = 1;
		for (int j = 0; j <= n; j++)
			ps[i][i][j] = 1;
	}
	for (int l = 1; l <= n; l++)
		for (int i = 0; i + l <= n; i++) {
			int j = i + l;
			for (int k = 1; k <= n; k++) {
				if (i <= idx[k] && idx[k] < j)
					dp[i][j][k] = mul(ps[i][idx[k]][k], ps[idx[k] + 1][j][n]);
				ps[i][j][k] = sum(ps[i][j][k - 1], dp[i][j][k]);
			}
		}
	return cout << dp[0][n][1] << "\n", 0;
}


#include<bits/stdc++.h>
using namespace std;

const int N = 500 + 10, mod = 1e9 + 7;
int n, a[N], dp[N][N][N], ps[N][N][N], idx[N];

int sum(int &a, int &b) {
	return ((1LL * a + b) % mod + mod) % mod;
}

int mul(int &a, int &b) {
	return ((1LL * a * b) % mod + mod) % mod;
}

int main() {
	ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
	cin >> n;
	for (int i = 0; i < n; i++)
		cin >> a[i];
	for (int i = 0; i < n; i++)
		idx[a[i]] = i;
	for (int i = 0; i <= n; i++) {
		dp[i][i][0] = 1;
		for (int j = 0; j <= n; j++)
			ps[i][i][j] = 1;
	}
	for (int l = 1; l <= n; l++)
		for (int i = 0; i + l <= n; i++) {
			int j = i + l;
			for (int k = 1; k <= n; k++) {
				if (i <= idx[k] && idx[k] < j)
					dp[i][j][k] = mul(ps[i][idx[k]][k], ps[idx[k] + 1][j][n]);
				ps[i][j][k] = sum(ps[i][j][k - 1], dp[i][j][k]);
			}
		}
	return cout << dp[0][n][1] << "\n", 0;
}


#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update>
#define ld long double
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define all(a) a.begin(),a.end()
#define sz(a) (ll)(a.size())
const int M=502;
const ll mod=1e9+7;
ll dp[M][M];
int b[M];
ll solve(int l,int r)
{
	if(dp[l][r]!=-1)
		return dp[l][r];
	if(l>=r)
		return dp[l][r]=1;
	ll res=0;
	for(int j=l;j<=r;j++)
	{
		if(b[j+1]>b[l] || j==r)
			res=(res+(solve(l+1,j)*solve(j+1,r)))%mod;
	}
	return dp[l][r]=res;
}
int main()
{
	ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	int n;
	cin>>n;
	if(n==1)
	{
		cout<<"1\n";
		return 0;
	}
	memset(dp,-1,sizeof(dp));
	for(int i=1;i<=n;i++)
		cin>>b[i];
	cout<<solve(2,n)<<"\n";
	return 0;
}


/// In The Name Of God

#include <bits/stdc++.h>

#define f first
#define s second

#define pb push_back
#define pp pop_back
#define mp make_pair

#define sz(x) (int)x.size()
#define sqr(x) ((x) * 1ll * (x))
#define all(x) x.begin(), x.end()

#define rep(i, l, r) for (int i = (l); i <= (r); i++)
#define per(i, l, r) for (int i = (l); i >= (r); i--)

#define Kazakhstan ios_base :: sync_with_stdio(0), cin.tie(0), cout.tie(0);

#define nl '\n'
#define ioi exit(0);

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;

const int N = (int)500 + 7;
const int inf = (int)1e9 + 7;
const int mod = (int)1e9 + 7;
const ll linf = (ll)1e18 + 7;

const int dx[] = {-1, 0, 1, 0, 1, -1, -1, 1};
const int dy[] = {0, 1, 0, -1, 1, -1, 1, -1};

using namespace std;

int n;
int a[N];

int dp[N][N][2];
int calc(int l = 1, int r = n, bool root = 1) {
	if (l >= r) return 1;
	if (~dp[l][r][root]) return dp[l][r][root];
	int res = 0;
	if (root) {
		rep(i, l + 1, r) {
			if (i == r || a[l + 1] < a[i + 1]) {
				res += calc(l + 1, i, 1) * 1ll * calc(i + 1, r, 0) % mod;
				res %= mod;
			}
		}
	} else {
		rep(i, l, r) {
			if (i == r || a[l] < a[i + 1]) res += calc(l, i, 1) * 1ll * calc(i + 1, r, 0) % mod;
			res %= mod;
		}
	}
	return dp[l][r][root] = res;
}
int main() {
	#ifdef wws
		freopen ("in.txt", "r", stdin);
	#endif
	cin >> n;
	rep(i, 1, n) cin >> a[i];
	memset(dp, -1, sizeof(dp));
	cout << calc(1, n, 1) << nl;
	ioi
}


#include <bits/stdc++.h>

#define F first
#define S second
#define PB push_back
#define PF push_front
#define MP make_pair

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;

const int maxn = 500 + 5;
const int mod = 1e9 + 7;

int a[maxn];
int dp[maxn][maxn], pd[maxn][maxn];

int main(){
	ios_base::sync_with_stdio(false);
	int n;
	cin >> n;
	for (int i = 1; i <= n; i++)
		cin >> a[i];
	for (int len = 1; len <= n; len++){
		for (int i = 1; i + len <= n + 1; i++){
			int j = i + len;
			if (len == 1){
				dp[i][j] = 1;
				pd[i][j] = 1;
				continue;
			}
			ll tmp = 1;
			pd[i][j] = dp[i + 1][j];
			/*
			for (int k = i + 2; k <= j; k++){
				if (a[k] >= a[i + 1]){
					pd[i][j] = (pd[i][j] + 1ll * pd[i + 1][k] * dp[k][j]) % mod;
				}
			}
			*/
			for (int k = i + 1; k <= j; k++){
				if (a[k] >= a[i]){
					dp[i][j] = (dp[i][j] + 1ll * pd[i][k] * dp[k][j]) % mod;
				}
			}
			dp[i][j] = (dp[i][j] + pd[i][j]) % mod;
		}
	}
	cout << pd[1][n + 1] << endl;
}


#include <bits/stdc++.h>
using namespace std;
const int N = 500 + 5, mod = 1e9 + 7;
int st[N][N], md[N][N], a[N], n;
int main() {
	cin >> n;
	for (int i = 0; i < n; i++)
		cin >> a[i];
	for (int i = 0; i < n; i++)
		st[i][i + 1] = md[i][i + 1] = 1;
	for (int ln = 2; ln <= n; ln++) {
		for (int i = 0; i + ln <= n; i++) {
			int j = i + ln;
			st[i][j] = md[i][j] = md[i + 1][j];
			for (int fr = i + 1; fr < j; fr++)
				md[i][j] = (md[i][j] + 1ll * st[i][fr] * md[fr][j] * (a[i] < a[fr]) % mod) % mod;
		}
	}
	cout << st[0][n];
}


#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize ("Ofast")
#pragma GCC target ("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>
using namespace std;

#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
	cout << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
	const char* comma = strchr(names + 1, ',');cout.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...)
#endif

#define ll long long
#define ld long double
#define pb push_back
#define F first
#define S second
#define I insert
#define pll pair<ll,ll>
#define vll vector<ll>
#define vpll vector< pll >
const ll MAX=505;ll M=1e9+7;
ll n;vll v;
ll dp[MAX][MAX][2];
int main() {
	ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);cout<<setprecision(25);
	cin>>n;
	for(ll i=0;i<n;i++){
		ll a;
		cin>>a;v.pb(a);
	}
	for(ll j=0;j<n;j++){
		for(ll i=0;i<n;i++){
			for(ll re=0;re<2;re++){
				ll l=i;ll r=i+j;
				if(l==r){dp[l][r][re] = 1;continue;}
				ll k;ll res;
				if(r!=n-1)res=v[r+1];
				ll ans=0;
				for(k=l+1;k<=r;k++){
					ll cur=1;
					if(re==1){
						if(v[k]>res)continue;
					}
					ll ls=dp[k][r][0];
					(cur*=ls)%=M;
					if(i!=l+1)ls=dp[l][k-1][1];else ls=1;
					(cur*=ls)%=M;
					(ans+=cur);if(ans>M)ans-=M;
				}
				dp[l][r][re]=ans;
			}
		}
	}
	cout<<dp[0][n-1][0];
	return 0;
}


#include <bits/stdc++.h>
using namespace std;

#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
	cout << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
	const char* comma = strchr(names + 1, ',');cout.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...)
#endif

#define ll long long
#define ld long double
#define pb push_back
#define F first
#define S second
#define I insert
#define pll pair<ll,ll>
#define vll vector<ll>
#define vpll vector< pll >
const ll MAX=505;ll M=1e9+7;
ll n;vll v;
ll dp[MAX][MAX][2];
ll solve(ll l,ll r,ll re){
	if(l==r)return 1;
	if(dp[l][r][re]!=-1)return dp[l][r][re];
	ll i,j,k;ll res;
	if(r!=n-1)res=v[r+1];
	ll ans=0;
	for(i=l+1;i<=r;i++){
		ll cur=1;
		if(re==1){
			if(v[i]>res)continue;
		}
		ll ls=solve(i,r,0);
		(cur*=ls)%=M;
		if(i!=l+1)ls=solve(l,i-1,1);else ls=1;
		(cur*=ls)%=M;
		(ans+=cur)%=M;
	}
	// trace(l,r,re,ans);
	return dp[l][r][re]=ans;
}
int main() {
	ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);cout<<setprecision(25);
	cin>>n;
	for(ll i=0;i<n;i++){
		ll a;
		cin>>a;v.pb(a);
	}
	for(ll i=0;i<MAX;i++){
		for(ll j=0;j<MAX;j++){
			dp[i][j][1]=dp[i][j][0]=-1;
		}
	}
	cout<<(solve(0,n-1,0));
	return 0;
}


#include <bits/stdc++.h>
using namespace std;

#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
	cout << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
	const char* comma = strchr(names + 1, ',');cout.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...)
#endif

#define ll long long
#define ld long double
#define pb push_back
#define F first
#define S second
#define I insert
#define pll pair<ll,ll>
#define vll vector<ll>
#define vpll vector< pll >
const ll MAX=505;ll M=1e9+7;
ll n;vll v;
ll dp[MAX][MAX][2];
ll solve(ll l,ll r,ll re){
	if(l==r)return 1;
	if(dp[l][r][re]!=-1)return dp[l][r][re];
	ll i,j,k;ll res;
	if(r!=n-1)res=v[r+1];
	ll ans=0;
	for(i=l+1;i<=r;i++){
		ll cur=1;
		if(re==1){
			if(v[i]>res)continue;
		}
		ll ls=solve(i,r,0);
		(cur*=ls)%=M;
		if(i!=l+1)ls=solve(l,i-1,1);else ls=1;
		(cur*=ls)%=M;
		(ans+=cur);if(ans>M)ans-=M;
	}
	// trace(l,r,re,ans);
	return dp[l][r][re]=ans;
}
int main() {
	ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);cout<<setprecision(25);
	cin>>n;
	for(ll i=0;i<n;i++){
		ll a;
		cin>>a;v.pb(a);
	}
	for(ll i=0;i<MAX;i++){
		for(ll j=0;j<MAX;j++){
			dp[i][j][1]=dp[i][j][0]=-1;
		}
	}
	cout<<(solve(0,n-1,0));
	return 0;
}


#include <bits/stdc++.h>
using namespace std;

#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
	cout << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
	const char* comma = strchr(names + 1, ',');cout.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...)
#endif

#define ll long long
#define ld long double
#define pb push_back
#define F first
#define S second
#define I insert
#define pll pair<ll,ll>
#define vll vector<ll>
#define vpll vector< pll >
const ll MAX=505;ll M=1e9+7;
ll n;vll v;
ll dp[MAX][MAX][2];
int main() {
	ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);cout<<setprecision(25);
	cin>>n;
	for(ll i=0;i<n;i++){
		ll a;
		cin>>a;v.pb(a);
	}
	for(ll j=0;j<n;j++){
		for(ll i=0;i<n;i++){
			ll l=i;ll r=i+j;if(r>=n)break;
			for(ll re=0;re<2;re++){

				if(l==r){dp[l][r][re] = 1;continue;}
				ll k;ll res;
				if(r!=n-1)res=v[r+1];
				ll ans=0;
				for(k=l+1;k<=r;k++){
					ll cur=1;
					if(re==1){
						if(v[k]>res)continue;
					}
					ll ls=dp[k][r][0];
					(cur*=ls)%=M;
					if(i!=l+1)ls=dp[l][k-1][1];else ls=1;
					(cur*=ls)%=M;
					(ans+=cur);if(ans>M)ans-=M;
				}
				dp[l][r][re]=ans;
			}
		}
	}
	cout<<dp[0][n-1][0];
	return 0;
}


#include <bits/stdc++.h>
using namespace std;

#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
	cout << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
	const char* comma = strchr(names + 1, ',');cout.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...)
#endif

#define ll long long
#define ld long double
#define pb push_back
#define F first
#define S second
#define I insert
#define pll pair<ll,ll>
#define vll vector<ll>
#define vpll vector< pll >
const ll MAX=505;ll M=1e9+7;
ll n;vll v;
ll dp[MAX][MAX][2];
int main() {
	ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);cout<<setprecision(25);
	cin>>n;
	for(ll i=0;i<n;i++){
		ll a;
		cin>>a;v.pb(a);
	}
	for(ll j=0;j<n;j++){
		for(ll i=0;i<n;i++){
			ll l=i;ll r=i+j;if(r>=n)break;
			for(ll re=0;re<2;re++){
				if(l==r){dp[l][r][re] = 1;continue;}
				ll k;ll res;
				if(r!=n-1)res=v[r+1];
				ll ans=0;
				for(k=l+1;k<=r;k++){
					if(re==1){
						if(v[k]>res)continue;
					}
					ll ls=dp[k][r][0];
					if(i!=l+1)ls*=dp[l][k-1][1];
					(ls)%=M;
					(ans+=ls);if(ans>M)ans-=M;
				}
				dp[l][r][re]=ans;
			}
		}
	}
	cout<<dp[0][n-1][0];
	return 0;
}


#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize ("Ofast")
#pragma GCC target ("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>
using namespace std;

#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
	cout << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
	const char* comma = strchr(names + 1, ',');cout.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...)
#endif

#define ll long long
#define ld long double
#define pb push_back
#define F first
#define S second
#define I insert
#define pll pair<ll,ll>
#define vll vector<ll>
#define vpll vector< pll >
const ll MAX=505;ll M=1e9+7;
ll n;vll v;
ll dp[MAX][MAX][2];
int main() {
	ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);cout<<setprecision(25);
	cin>>n;
	for(ll i=0;i<n;i++){
		ll a;
		cin>>a;v.pb(a);
	}
	for(ll j=0;j<n;j++){
		for(ll i=0;i<n;i++){
			ll l=i;ll r=i+j;if(r>=n)break;
			for(ll re=0;re<2;re++){

				if(l==r){dp[l][r][re] = 1;continue;}
				ll k;ll res;
				if(r!=n-1)res=v[r+1];
				ll ans=0;
				for(k=l+1;k<=r;k++){
					ll cur=1;
					if(re==1){
						if(v[k]>res)continue;
					}
					ll ls=dp[k][r][0];
					(cur*=ls)%=M;
					if(i!=l+1)ls=dp[l][k-1][1];else ls=1;
					(cur*=ls)%=M;
					(ans+=cur);if(ans>M)ans-=M;
				}
				dp[l][r][re]=ans;
			}
		}
	}
	cout<<dp[0][n-1][0];
	return 0;
}


#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize ("Ofast")
#pragma GCC target ("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>
using namespace std;

#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
	cout << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
	const char* comma = strchr(names + 1, ',');cout.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...)
#endif

#define ll long long
#define ld long double
#define pb push_back
#define F first
#define S second
#define I insert
#define pll pair<ll,ll>
#define vll vector<ll>
#define vpll vector< pll >
const ll MAX=505;ll M=1e9+7;
ll n;vll v;
ll dp[MAX][MAX][2];
ll solve(ll l,ll r,ll re){
	if(l==r)return 1;
	if(dp[l][r][re]!=-1)return dp[l][r][re];
	ll i,j,k;ll res;
	if(r!=n-1)res=v[r+1];
	ll ans=0;
	for(i=l+1;i<=r;i++){
		ll cur=1;
		if(re==1){
			if(v[i]>res)continue;
		}
		ll ls=solve(i,r,0);
		(cur*=ls)%=M;
		if(i!=l+1)ls=solve(l,i-1,1);else ls=1;
		(cur*=ls)%=M;
		(ans+=cur);if(ans>M)ans-=M;
	}
	// trace(l,r,re,ans);
	return dp[l][r][re]=ans;
}
int main() {
	ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);cout<<setprecision(25);
	cin>>n;
	for(ll i=0;i<n;i++){
		ll a;
		cin>>a;v.pb(a);
	}
	for(ll i=0;i<MAX;i++){
		for(ll j=0;j<MAX;j++){
			dp[i][j][1]=dp[i][j][0]=-1;
		}
	}
	cout<<(solve(0,n-1,0));
	return 0;
}


/* be name khoda */

// #define long_enable
#include <iostream>
#include <algorithm>
#include <cstring>
#include <numeric>
#include <vector>
#include <fstream>
#include <set>
#include <map>
using namespace std;

#ifdef long_enable
typedef long long int ll;
#else
typedef int ll;
#endif

typedef pair<ll, ll> pii;
typedef pair<pii, ll> ppi;
typedef pair<ll, pii> pip;
typedef vector<ll> vi;
typedef vector<pii> vpii;

#define forifrom(i, s, n) for (ll i = s; i < n; ++i)
#define forirto(i, n, e) for (ll i = (n) - 1; i >= e; --i)
#define fori(i, n) forifrom (i, 0, n)
#define forir(i, n) forirto (i, n, 0)

#define F first
#define S second
#define pb push_back
#define eb emplace_back
#define all(x) (x).begin(), (x).end()
#define smin(a, b) a = min(a, (b))
#define smax(a, b) a = max(a, (b))

#define debug(x) cout << #x << " -> " << (x) << endl
#define debug2(x, y) cout << #x << ' ' << #y << " -> " << (x) << ' ' << (y) << endl
#define debug3(x, y, z) cout << #x << ' ' << #y << ' ' << #z << " -> " << (x) << ' ' << (y) << ' ' << (z) << endl
#define debug4(x, y, z, t) cout << #x << ' ' << #y << ' ' << #z << ' ' << #t << " -> " << (x) << ' ' << (y) << ' ' << (z) << ' ' << (t) << endl
#define debuga(x, n) cout << #x << " -> "; fori (i1_da, n) { cout << (x)[i1_da] << ' '; } cout << endl
#define debugaa(x, n, m) cout << #x << " ->\n"; fori (i1_daa, n) { fori (i2_daa, m) { cout << (x)[i1_daa][i2_daa] << ' '; } cout << '\n'; } cout << endl

const ll MOD = 1000000007;
const ll INF = 2000000000;
const long long BIG = 1446803456761533460LL;

#define XL (x << 1)
#define XR (XL | 1)
#define MD ((l + r) >> 1)
#define Add(a, b) a = ((a) + (b)) % MOD
#define Mul(a, b) a = (1LL * (a) * (b)) % MOD

// -----------------------------------------------------------------------

const ll maxn = 504;

ll n, A[maxn], dp[maxn][maxn];

int main() {
    ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
    // ifstream cin(".in");

    cin >> n;
    fori (i, n) cin >> A[i];
    fori (i, n + 1) dp[i][i] = 1;
    forifrom (k, 1, n) {
        forifrom (l, 1, n - k + 1) {
            ll r = l + k;
            dp[l][r] = dp[l + 1][r];
            forifrom (t, l + 1, r) {
                if (A[t] > A[l]) {
                    dp[l][r] = (dp[l][r] + 1LL * dp[l + 1][t] * dp[t][r]) % MOD;
                }
            }
        }
    }
    cout << dp[1][n];

}


#include <bits/stdc++.h>
typedef long long int ll;
typedef long double ld;
#define pb push_back
#define pii pair < ll , ll >
#define F first
#define S second
#define endl '\n'
#define int long long
#define sync ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#pragma GCC optimize ("Ofast")
#pragma GCC optimize ("unroll-loops")
#define kill(x) return cout<<x<<'\n', 0;
using namespace std;
/// khodaya komak kon
/// ya navid navid
const int N=510,mod=1e9+7;
ll dp[N][N];
ll a[N];
int32_t main(){
    ll n;
    cin >> n;
    for (int i=1;i<=n;i++){
        cin >> a[i];
    }
    for (int i=1;i<=n+1;i++){
        dp[i][i+1]=1;
        dp[i][i]=1;
    }
    for (int l=n-1;l>1;l--){
        for (int r=l+2;r<=n+1;r++){
            for (int k=l+1;k<r;k++){
                if (a[l]<a[k])
                    dp[l][r]+=dp[l+1][k]*dp[k][r]%mod;
               // if (l==2 && r==4){
                 //   cout << l+1 << " " << k << " " << r << " " << dp[l+1][k] << " " << dp[k][r] << endl;
                //}
                dp[l][r]%=mod;
            }
            dp[l][r]+=dp[l+1][r];
            dp[l][r]%=mod;
        }
    }
    cout << dp[2][n+1];
}


#include <bits/stdc++.h>
typedef long long int ll;
typedef long double ld;
#define pb push_back
#define pii pair < ll , ll >
#define F first
#define S second
#define endl '\n'
#define int long long
#define sync ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#pragma GCC optimize ("Ofast")
#pragma GCC optimize ("unroll-loops")
#define kill(x) return cout<<x<<'\n', 0;
using namespace std;
/// khodaya komak kon
/// ya navid navid
const int N=510,mod=1e9+7;
ll dp[N][N];
ll a[N];
int32_t main(){
    ll n;
    cin >> n;
    for (int i=1;i<=n;i++){
        cin >> a[i];
    }
    for (int i=1;i<=n+1;i++){
        dp[i][i+1]=1;
        dp[i][i]=1;
    }
    for (int l=n-1;l>1;l--){
        for (int r=l+2;r<=n+1;r++){
            ll mi=1e9+100;
            ll id=0;
            for (int k=l;k<r;k++){
                if (a[k]<mi){
                    mi=a[k];
                    id=k;
                }
            }
            for (int k=id+1;k<=r;k++){
                dp[l][r]+=dp[l+1][k]*dp[k][r]%mod;
               // if (l==2 && r==4){
                 //   cout << l+1 << " " << k << " " << r << " " << dp[l+1][k] << " " << dp[k][r] << endl;
                //}
                dp[l][r]%=mod;
            }
        }
    }
    cout << dp[2][n+1];
}


#include <iostream>
#include <cstring>
using namespace std;
const int N=500+10;
typedef long long LL;
const LL MOD = 1e9 + 7;
int n;
LL dp[N][N],f[502],a[N];

LL solve(int l,int r) {
    if(dp[l][r]!=-1)return dp[l][r];
    if(l>=r)return 1;
    dp[l][r]=0;
    for(int i=l+1;i<=r;i++) {
        if(a[i]>a[l]) {
            dp[l][r] += solve(l,i-1) * solve(i,r) % MOD;
        }
    }
    return dp[l][r];
}
int main() {
    memset(dp,-1,sizeof(dp));
    scanf("%d",&n);
    for(int i=1;i<=n;i++) scanf("%d",&a[i]);
    cout<<solve(1,n)<<endl;
}


#include <iostream>
#include <cstring>
using namespace std;
const int N=500+10;
typedef long long LL;
const LL MOD = 1e9 + 7;
int n;
LL dp[N][N],f[502],a[N];

LL solve(int l,int r) {
    if(dp[l][r]!=-1)return dp[l][r];
    if(l>=r)return 1;
    if(l+1==r)return 1;

    dp[l][r]=solve(l+1,r);
    for(int i=l+2;i<=r;i++) {
        if(a[i]>a[l+1]) {
            dp[l][r] += solve(l,i-1) * solve(i-1,r) % MOD;
            dp[l][r] %= MOD;
        }
    }
    return dp[l][r];
}

int main() {
    memset(dp,-1,sizeof(dp));
    scanf("%d",&n);
    for(int i=1;i<=n;i++) scanf("%lld",&a[i]);
    cout<<solve(1,n)<<endl;
}


#include <iostream>
#include <cstring>
using namespace std;
const int N=500+10;
typedef long long LL;
const LL MOD = 1e9 + 7;
int n;
LL dp[N][N],f[502],a[N];

LL solve(int l,int r) {
    if(dp[l][r]!=-1)return dp[l][r];
    if(l>=r)return 1;
    dp[l][r]=0;
    for(int i=l+1;i<=r;i++) {
        if(a[i]>a[l]) {
            dp[l][r] += solve(l,i-1) * solve(i,r) % MOD;
            dp[l][r] %= MOD;
        }
    }
    return dp[l][r];
}
int main() {
    memset(dp,-1,sizeof(dp));
    scanf("%d",&n);
    for(int i=1;i<=n;i++) scanf("%d",&a[i]);
    cout<<solve(1,n)<<endl;
}


#include <iostream>
#include <cstring>
using namespace std;
const int N=500+10;
typedef long long LL;
const LL MOD = 1e9 + 7;
int n;

LL dp[N][N],f[502],a[N];
LL solve(int l,int r) {
    if(dp[l][r]!=-1)return dp[l][r];
    if(l>=r)return 1;
    if(l+1==r)return 1;

    dp[l][r]=solve(l+1,r);
    for(int i=l+2;i<=r;i++) {
        if(a[i]>a[l+1]) {
            // [l+1,i-1], first sub-tree
            // [i,r], others sub-tree
            dp[l][r] += solve(l+1,i-1) * solve(i-1,r) % MOD;
            dp[l][r] %= MOD;
        }
    }
    return dp[l][r];
}

int main() {
    memset(dp,-1,sizeof(dp));
    scanf("%d",&n);
    for(int i=1;i<=n;i++) scanf("%lld",&a[i]);
    cout<<solve(1,n)<<endl;
}


#include <bits/stdc++.h>
using namespace std;

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;

#define pb                    push_back
#define ll                    long long
#define ld                    long double
#define sz(x)                 (ll)x.size()
#define vll                   vector<long long>

#define infi                  INT_MAX
#define infl                  LONG_LONG_MAX
#define infd                  LDBL_MAX
#define f(i,a,b)              for(ll i=a;i<b;i++)
#define fi(i,a,b)             for(ll i=(b-1);i>=a;i--)
#define F                     first
#define S                     second
#define G(a,b)                get<a>(b)
#define MP                    make_pair
#define MT                    make_tuple
#define pll                   pair<ll,ll>
#define endl                  "\n"
#define ALL(v)                v.begin(),v.end()
#define nl                    cout<<"\n";
#define pr(x)                 cout<<x;
#define pr1(x)                cout<<x<<" ";
#define pr2(x,y)              cout<<x<<" "<<y;
#define pr3(x,y,z)            cout<<x<<" "<<y<<" "<<z;
#define pr4(x,y,z,w)          cout<<x<<" "<<y<<" "<<z<<" "<<w;
#define deb                   cout<<"***************************************************************************************\n";
#define moshi                 cout<<"moshi moshi ! \n";
#define hi                    cout<<"hi ! \n";
#define bye                   cout<<"bye bye ! \n";
#define kawai                 cout<<"O kawai koto ! \n";
#define o_set                 tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update>
#define number_of_set_bits  __builtin_popcountll
#define eb                    emplace_back
const ld PI=3.1415926535897932384626433;

auto clk=clock();
mt19937_64 rng(chrono::high_resolution_clock::now().time_since_epoch().count());

#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
    template <typename Arg1>
    void __f(const char* name, Arg1&& arg1){
        cout << name << " : " << arg1 <<"\n";
        //use cerr if u want to display at the bottom
    }
    template <typename Arg1, typename... Args>
    void __f(const char* names, Arg1&& arg1, Args&&... args){
        const char* comma = strchr(names + 1, ','); cout.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
    }
#else
#define trace(...)
#endif

//**********************************************************  Code begins  ***********************************************

const ll N=505,p=1e9+7;
ll dp[N][N],arr[N],n;

void solve()
{
  cin>>n;
  f(i,1,n+1) cin>>arr[i];
  if(n==1)
  {
	  cout<<"1\n";
	  return;
  }
  f(i,1,n+1) dp[i][i]=1;
  f(l,2,n+1)
  {
	  f(i,1,n+1)
	  {
		  ll j=i+l-1;
		  if(j>n) break;
		  ll res=0;
		  if(arr[i+1]>arr[i]) res=(res+dp[i+1][j])%p;
		  f(z,i+2,j+1)
		  {
			  if(arr[z]>arr[i])
			  {
				  ll temp=(dp[i+1][z-1]*dp[z][j])%p;
				  res=(res+temp)%p;
			  }
		  }
		  res=(res+dp[i+1][j])%p;
		  dp[i][j]=res;
	  }
  }
  cout<<dp[2][n]<<"\n";
}

int main()
{
    ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
    srand(chrono::high_resolution_clock::now().time_since_epoch().count());
    cout<<fixed<<setprecision(8);

    ll test_cases=1;
    //cin>>test_cases;

    f(i,1,test_cases+1)  solve();

    #ifdef rd
    cout<<endl<<endl<<endl<<endl<<"Time elapsed: "<<(double)(clock()-clk)/CLOCKS_PER_SEC<<endl;
    #endif

    return 0;
}


#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
//#include <atcoder/all>

#define F first
#define S second
#define int long long
#define ll long long
//#define int  unsigned long long
#define pb push_back
//#define double long double

using namespace std;
using namespace __gnu_pbds;

typedef  tree< int , null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const int N = 560;
const int K = 5;
const int mod = 1e9 + 7;
int a[N], dp1[N][N], dp2[N][N];
main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    int n;
    cin >> n;
    for (int i = 1; i <= n; i++) cin >> a[i];
    for (int i = 1; i <= n; i++){
        dp1[i][i] = 1;
        dp2[i][i] = 1;
    }
    for (int i = 1; i <= n; i++){
        for (int j = 1; j + i <= n; j++){
            int l = j;
            int r = j + i;
            dp1[l][r] = dp2[l + 1][r];
            for (int t = l + 1; t <= r; t++){
                if (a[t] > a[l]){
                    dp2[l][r] = (dp2[l][r] + dp1[l][t - 1] * dp2[t][r]) % mod;
                }
            }
            dp2[l][r] = (dp2[l][r] + dp1[l][r]) % mod;
        }
    }
    cout << dp1[1][n];
}


#include <bits/stdc++.h>
using namespace std;

#define int long long

const int N = 555, mod = 1e9 + 7;

int a[N], dp[N][N];

int f(int l, int r) {
	if(l >= r) {
		return 1;
	}
	if(~dp[l][r]) {
		return dp[l][r];
	}
	int res = 0;
	for(int i = l; i <= r; i++) {
		if(i == r || a[l] < a[i + 1]) {
			res += f(l + 1, i) * f(i + 1, r) % mod;
			res %= mod;
		}
	}
	return dp[l][r] = res;
}

int32_t main() {
	ios_base :: sync_with_stdio(0); cin.tie(0); cout.tie(0);
	int n; cin >> n;
	for(int i = 1; i <= n; i++) {
		cin >> a[i];
	}
	memset(dp, -1, sizeof dp);
	cout << f(2, n) << endl;

}


#include<bits/stdc++.h>
#define rep(i,a,n) for(int i=a;i<=n;i++)
#define per(i,a,n) for(int i=n;i>=a;i--)
#define pb push_back
#define mp make_pair
#define FI first
#define SE second
#define maxn 500
#define mod 1000000007
#define inf 0x3f3f3f3f
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef double db;

void add(int &x,int y) {x=x+y<mod?x+y:x+y-mod;}

int dp[maxn+5][maxn+5];
int a[maxn+5];

int main()
{
	int n; scanf("%d",&n);
	rep(i,1,n) scanf("%d",&a[i]);
	rep(i,1,n) dp[i][i]=1;
	rep(L,2,n) rep(l,1,n-L+1)
	{
		int r=l+L-1;
		dp[l][r]=dp[l+1][r];
		rep(i,l+2,r) if(a[l+1]<a[i]) add(dp[l][r],1ll*dp[l+1][i-1]*dp[i-1][r]%mod);
	}
	printf("%d\n",dp[1][n]);
	return 0;
}


#include <bits/stdc++.h>
#define MAX_SIZE 511
#define MOD 1000000007
typedef long long ll;
using namespace std;

ll dp[MAX_SIZE][MAX_SIZE][2];
int b[MAX_SIZE];
int n;

ll dfs(int l, int r, int dim) {
    if (l > r) return 1;
    if (l == r) return 1;
    if (dp[l][r][dim] != -1) return dp[l][r][dim];
    ll ans = 0;
    if (dim == 0) {
        ans = dfs(l + 1, r, 1);
    } else {
        int i;
        ans = dfs(l, r, 0);
        for (i = l; i < r; ++i) {
            if (b[i+1] > b[l]) {
                ans += dfs(l, i, 0) * dfs(i+1, r, 1);
                ans %= MOD;
            }
        }
    }
    return dp[l][r][dim] = ans;
}

int main() {
    int i, j;
    scanf("%d", &n);
    for (i = 1; i <= n; ++i) scanf("%d", &b[i]);
    for (i = 0; i <= n; ++i) {
        for (j = 0 ; j <= n; ++j) {
            dp[i][j][0] = dp[i][j][1] = -1;
        }
    }

    printf("%I64d\n", dfs(1, n, 0));
    return 0;
}


#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<string>
#include<queue>
#include<bitset>
#include<map>
#include<set>
#define ll long long
#define llu unsigned ll
#define ld long double
#define ui unsigned int
#define pr make_pair
#define pb push_back
#define ui unsigned int
#define lc (cnt<<1)
#define rc (cnt<<1|1)
#define len(x)  (t[(x)].r-t[(x)].l+1)
#define tmid ((l+r)>>1)
#define forhead(x) for(int i=head[(x)];i;i=nt[i])
#define max(x,y) ((x)>(y)?(x):(y))
#define min(x,y) ((x)>(y)?(y):(x))
using namespace std;
const int inf=0x3f3f3f3f;
const ll lnf=0x3f3f3f3f3f3f3f3f;
const double dnf=1e18;
const int mod=1e9+7;
const double eps=1e-8;
const double pi=acos(-1.0);
const int maxm=100100;
const int up=100000;
const int hashp=13331;
const int maxn=510;

ll dp[maxn][maxn],b[maxn];

ll dfs(int l,int r)
{
    if(dp[l][r]!=-1) return dp[l][r];
    if(l==r) return dp[l][r]=1;
    dp[l][r]=0;
    for(int k=l+1;k<=r;k++)
    {
        if(b[l+1]<b[k+1]||k==r)
            dp[l][r]=(dp[l][r]+dfs(l+1,k)*dfs(k,r))%mod;
    }
    return dp[l][r];
}

int main(void)
{
    memset(dp,-1,sizeof(dp));
    int n;
    scanf("%d",&n);
    for(int i=1;i<=n;i++)
        scanf("%lld",&b[i]);
    printf("%lld\n",dfs(1,n));
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define maxn 555
#define mod 1000000007
ll dp[maxn][maxn];
int b[maxn],n;
ll dfs(int l,int r)
{
    ll ans=0;
    if(l==r)return 1;
    if(dp[l][r]!=-1)return dp[l][r];
    for(int i=l+1; i<=r; i++)
    {
        if(i!=r&&b[l+1]>=b[i+1])continue;
        ans=(ans+dfs(l+1,i)*dfs(i,r)%mod)%mod;
    }
    return dp[l][r]=ans;
}
int main()
{
    memset(dp,-1,sizeof(dp));
    scanf("%d",&n);
    for(int i=1; i<=n; i++)
        scanf("%d",&b[i]);
    dfs(1,n);
    printf("%lld\n",dp[1][n]);
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define maxn 555
#define mod 1000000007
ll dp[maxn][maxn];
int b[maxn],n;
ll dfs(int l,int r)
{
    ll ans=0;
    if(l==r)return 1;
    if(dp[l][r]!=-1)return dp[l][r];
    for(int i=l+1; i<=r; i++)
    {
        if(i!=r&&b[l+1]>=b[i+1])continue;
        ans=(ans+dfs(l+1,i)*dfs(i,r)%mod)%mod;
    }
    return dp[l][r]=ans;
}
int main()
{
    memset(dp,-1,sizeof(dp));
    scanf("%d",&n);
    for(int i=1; i<=n; i++)
        scanf("%d",&b[i]);
    printf("%lld\n", dfs(1,n));
    return 0;
}


#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;

template<int m>
struct modint {

	unsigned x;

	modint() : x(0) {}

	modint(long long arg) {
		arg %= m;
		if (arg < 0) {
			x = arg + m;
		} else {
			x = arg;
		}
	}

	modint& operator+= (const modint& other) {
		x += other.x;
		if (x >= m) {
			x -= m;
		}
		return *this;
	}

	modint& operator*= (const modint& other) {
		x = (x * 1ull * other.x) % m;
		return *this;
	}

	modint& operator-= (const modint& other) {
		x += m - other.x;
		if (x >= m) {
			x -= m;
		}
		return *this;
	}

	modint operator+ (const modint& other) const {
		modint tmp = *this;
		tmp += other;
		return tmp;
	}

	modint operator- (const modint& other) const {
		modint tmp = *this;
		tmp -= other;
		return tmp;
	}

	modint operator* (const modint& other) const {
		modint tmp = *this;
		tmp *= other;
		return tmp;
	}

	explicit operator int () const {
		return x;
	}

	modint& operator++ () {
		++x;
		if (x == m) {
			x = 0;
		}
		return *this;
	}

	modint& operator-- () {
		if (x == 0) {
			x = m-1;
		} else {
			--x;
		}
		return *this;
	}

	modint operator++ (int) {
		modint tmp = *this;
		++*this;
		return tmp;
	}

	modint operator-- (int) {
		modint tmp = *this;
		--*this;
		return tmp;
	}

	bool operator== (const modint& other) const {
		return x == other.x;
	}

	bool operator!= (const modint& other) const {
		return x != other.x;
	}

	template<class T>
	modint operator^ (T arg) const {
		if (arg == 0) {
			return 1;
		}
		if (arg == 1) {
			return x;
		}
		auto t = *this ^ (arg >> 1);
		t *= t;
		if (arg & 1) {
			t *= *this;
		}
		return t;
	}

	template<class T>
	modint operator^= (T arg) {
		return *this = *this ^ arg;
	}

	modint inv() const {
		return *this ^ (m-2);
	}
};

const int MOD = 1'000'000'007;
typedef modint<MOD> mint;

int n;
int a[505];
mint dp[505][505];
mint curr[505];

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);
	cerr.tie(nullptr);

	cin >> n;
	for (int i=1; i<=n; i++)
		cin >> a[i];

	for (int l=n; l>=1; l--) {
		memset(curr, 0, sizeof(curr));
		curr[l+1] = 1;
		dp[l][l] = 1;
		dp[l][l+1] = 1;
		for (int j=l+2; j<=n; j++) {
			for (int k=l+1; k<j; k++) {
				if (a[k] < a[j])
					curr[j] += curr[k] * dp[k][j-1];
			}
			for (int k=l+1; k<=j; k++)
				dp[l][j] += curr[k] * dp[k][j];
		}
	}
	cout << (int)dp[1][n] << '\n';
}


#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <fstream>
#include <vector>
#include <string>
#include <cassert>
#include <iomanip>
#include <set>
#include <map>
#include <algorithm>
#include <math.h>
#include <ctime>
#include <cmath>
#include <stack>

using namespace std;

#define mp make_pair
#define sz size()
#define all(x) x.begin(), x.end()
#define forn(i,n) for(int i = 0; i<int(n); i++)
#define sqr(x) ((x)*(x))
typedef long long ll;
typedef long double ld;
typedef pair<int, int> ii;
const ll INF = 1e9;
const ld EPS = 1e-14;
#define y1 jkghsfgdspfgsd
#define EXIT cout<<"Impossible"; return 0;

//#define DEBUG
#ifdef DEBUG
    #define PR(x) cout<<#x<<" = "<<x<<" ";
    #define PL(x) cout<<#x<<" = "<<x<<endl;
#else
    #define PR(x) {}
    #define PL(x) {}
#endif

vector<int> a;
vector<vector<ll>> dp;
const ll mod = 1e9 + 7;

int main(){
#ifdef DEBUG
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif

    int n;
    cin >> n;
    a.resize(n);
    forn(i, n)  cin>>a[i];
    dp.assign(n, vector<ll>(n, 0));

    forn(i, n) dp[i][i] = 1;
    forn(i, n) if (i < n - 1) dp[i + 1][i] = 1;//для того, чтобы рассматривался случай dp[i+1][i+j].

    for (int j = 1; j<n; j++){
        for (int i = 0; i + j < n; i++){
            dp[i][i + j] += dp[i + 1][i+j];//случай, когда все
            for (int k = 1; k <= j; k++){
                if (a[i]<a[i+k])
                    dp[i][i + j] = (dp[i][i + j] + dp[i+1][i+k-1]*dp[i+k][i+j]) % mod;
            }
        }
    }

    cout << dp[1][n - 1];

#ifdef DEBUG
    cerr << "Time elapsed: " << (ld)clock() / CLOCKS_PER_SEC << " sec." << endl;
#endif
    return 0;
}


#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <fstream>
#include <vector>
#include <string>
#include <cassert>
#include <iomanip>
#include <set>
#include <map>
#include <algorithm>
#include <math.h>
#include <ctime>
#include <cmath>
#include <stack>

using namespace std;

#define mp make_pair
#define sz size()
#define all(x) x.begin(), x.end()
#define forn(i,n) for(int i = 0; i<int(n); i++)
#define sqr(x) ((x)*(x))
typedef long long ll;
typedef long double ld;
typedef pair<int, int> ii;
const ll INF = 1e9;
const ld EPS = 1e-14;
#define y1 jkghsfgdspfgsd
#define EXIT cout<<"Impossible"; return 0;

//#define DEBUG
#ifdef DEBUG
    #define PR(x) cout<<#x<<" = "<<x<<" ";
    #define PL(x) cout<<#x<<" = "<<x<<endl;
#else
    #define PR(x) {}
    #define PL(x) {}
#endif

vector<int> a;
vector<vector<ll>> dp;
const ll mod = 1e9 + 7;

int main(){
#ifdef DEBUG
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif

    int n;
    cin >> n;
    a.resize(n);
    forn(i, n)  cin>>a[i];
    dp.assign(n, vector<ll>(n, 0));

    forn(i, n) dp[i][i] = 1;
    forn(i, n) if (i < n - 1) dp[i + 1][i] = 1;

    for (int j = 1; j<n; j++){
        for (int i = 0; i + j < n; i++){
            dp[i][i + j] += dp[i + 1][i+j];
            for (int k = 1; k <= j; k++){
                if (a[i]<a[i+k])
                    dp[i][i + j] = (dp[i][i + j] + dp[i+1][i+k-1]*dp[i+k][i+j]) % mod;
            }
        }
    }

    cout << ((n == 1)? 1 :dp[1][n - 1]);

#ifdef DEBUG
    cerr << "Time elapsed: " << (ld)clock() / CLOCKS_PER_SEC << " sec." << endl;
#endif
    return 0;
}


#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <fstream>
#include <vector>
#include <string>
#include <cassert>
#include <iomanip>
#include <set>
#include <map>
#include <algorithm>
#include <math.h>
#include <ctime>
#include <cmath>
#include <stack>

using namespace std;

#define mp make_pair
#define sz size()
#define all(x) x.begin(), x.end()
#define forn(i,n) for(int i = 0; i<int(n); i++)
#define sqr(x) ((x)*(x))
typedef long long ll;
typedef long double ld;
typedef pair<int, int> ii;
const ll INF = 1e9;
const ld EPS = 1e-14;
#define y1 jkghsfgdspfgsd
#define EXIT cout<<"Impossible"; return 0;

//#define DEBUG
#ifdef DEBUG
    #define PR(x) cout<<#x<<" = "<<x<<" ";
    #define PL(x) cout<<#x<<" = "<<x<<endl;
#else
    #define PR(x) {}
    #define PL(x) {}
#endif

vector<int> a;
vector<vector<ll>> dp;
const ll mod = 1e9 + 7;

int main(){
#ifdef DEBUG
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif

    int n;
    cin >> n;
    a.resize(n);
    forn(i, n)  cin>>a[i];
    dp.assign(n, vector<ll>(n, 0));

    forn(i, n) dp[i][i] = 1;
    forn(i, n) if (i < n - 1) dp[i + 1][i] = 1;//для того, чтобы рассматривался случай dp[i+1][i+j].

    for (int j = 1; j<n; j++){
        for (int i = 0; i + j < n; i++){
            for (int k = 1; k <= j; k++){
                if (a[i]<a[i+k])
                    dp[i][i + j] = (dp[i][i + j] + dp[i+1][i+k-1]*dp[i+k][i+j]) % mod;
            }
            //dp[i][i + j] = (dp[i][i + j] + dp[i + 1][i + j])%mod;
        }
    }

    cout << dp[0][n - 1];

#ifdef DEBUG
    cerr << "Time elapsed: " << (ld)clock() / CLOCKS_PER_SEC << " sec." << endl;
#endif
    return 0;
}


#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <fstream>
#include <vector>
#include <string>
#include <cassert>
#include <iomanip>
#include <set>
#include <map>
#include <algorithm>
#include <math.h>
#include <ctime>
#include <cmath>
#include <stack>

using namespace std;

#define mp make_pair
#define sz size()
#define all(x) x.begin(), x.end()
#define forn(i,n) for(int i = 0; i<int(n); i++)
#define sqr(x) ((x)*(x))
typedef long long ll;
typedef long double ld;
typedef pair<int, int> ii;
const ll INF = 1e9;
const ld EPS = 1e-14;
#define y1 jkghsfgdspfgsd
#define EXIT cout<<"Impossible"; return 0;

//#define DEBUG
#ifdef DEBUG
    #define PR(x) cout<<#x<<" = "<<x<<" ";
    #define PL(x) cout<<#x<<" = "<<x<<endl;
#else
    #define PR(x) {}
    #define PL(x) {}
#endif

vector<int> a;
vector<vector<ll>> dp;
const ll mod = 1e9 + 7;

int main(){
#ifdef DEBUG
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif

    int n;
    cin >> n;
    a.resize(n);
    forn(i, n)  cin>>a[i];
    dp.assign(n, vector<ll>(n, 0));

    forn(i, n) dp[i][i] = 1;
    forn(i, n) if (i < n - 1) dp[i + 1][i] = 1;

    for (int j = 1; j<n; j++){
        for (int i = 0; i + j < n; i++){
            for (int k = 1; k <= j; k++){
                if (a[i]<a[i+k])
                    dp[i][i + j] = (dp[i][i + j] + dp[i+1][i+k-1]*dp[i+k][i+j]) % mod;
            }
            //dp[i][i + j] = (dp[i][i + j] + dp[i + 1][i + j])%mod;
        }
    }

    cout << dp[0][n - 1];

#ifdef DEBUG
    cerr << "Time elapsed: " << (ld)clock() / CLOCKS_PER_SEC << " sec." << endl;
#endif
    return 0;
}


#pragma comment (linker,"/stack:102400000,102400000")
#include <cstdio>
#include <map>
#include <vector>
#include <stack>
#include <queue>
#include <cstring>
#include <algorithm>
#include <string>
#include <cstdlib>
#include <iostream>
#include <cmath>
#include <set>
#include <ctime>

using namespace std;

#define ll long long
#define ull unsigned long long
#define ls (root << 1)
#define rs (root << 1 | 1)
#define lson l, mid, ls
#define rson mid + 1, r, rs
#define MID mid = ((l + r) >> 1)
#define PR pair<int, int>
#define MP make_pair
#define sqr(x) ((x) * (x))

int lowbit(int x) {return (x & -x);}
//int sgn(double x) {return (x > eps) - (x < -eps);}
template <class T_> T_ f_abs(T_ x) {return x < 0 ? -x : x;}
template <class T_> T_ f_max(T_ a, T_ b) {return a > b ? a : b;}
template <class T_> T_ f_min(T_ a, T_ b) {return a < b ? a : b;}
template <class T_> void chkmax(T_ &a, T_ b) {if(a == -1 || a < b) a = b;}
template <class T_> void chkmin(T_ &a, T_ b) {if(a == -1 || a > b) a = b;}
template <class T_> T_ gcd(T_ a, T_ b) {while(T_ t = a % b) a = b, b = t; return b;}
template <class T_> void f_swap(T_ &a, T_ &b) {T_ t = a; a = b; b = t;}

const double eps = 1e-9;
const int dx[] = {-1, 1, 0, 0, -1, -1, 1, 1}, dy[] = {0, 0, -1, 1, -1, 1, -1, 1};//UDLR
const int inf = 0x7fffffff;
const int mod = 1000000007;
const int N = 503;
int n, a[N];
ll dp[N][N];

void Init() {memset(dp, -1, sizeof(dp));}

void GetData() {
	for(int i = 1; i <= n; ++i)
		scanf("%d", &a[i]);
}

void Solve() {
	int i, j, k;
	dp[1][1] = 1;
	for(i = 2; i <= n; ++i) {
		dp[i][i] = 1;
		for(j = i; j > 1; --j) {
			dp[j - 1][i] = 0;
			for(k = j; k <= i; ++k) {
				if(k == i || a[j] < a[k + 1])
					dp[j - 1][i] = (dp[j - 1][i] + dp[j][k] * dp[k][i]) % mod;
			}
		}
	}
	printf("%I64d\n", dp[1][n]);
}

int main() {
	while(~scanf("%d", &n)) {
		Init();
		GetData();
		Solve();
	}
	return 0;
}


#include <iostream>

using namespace std;

const int MOD = 1e+9 + 7;
long long a[510], d[510][510], e[510][510];

long long E(int l, int r);

long long D(int l, int r)
{
    if (d[l][r] != -1)
        return d[l][r];
    if (l == r + 1)
    {
        d[l][r] = 1;
        return 1;
    }
    long long Res = E(l, r);
    for (int i = l + 1; i <= r; i++)
    {
        int tmp = (E(l, i - 1)*D(i, r)) % MOD;
        Res = (Res + tmp*(a[l] < a[i])) % MOD;
    }
    d[l][r] = Res;
    return Res;
}

long long E(int l, int r)
{
    if (e[l][r] != -1)
        return e[l][r];
    if (l == r)
    {
        e[l][r] = 1;
        return 1;
    }
    long long res = D(l + 1, r);
    e[l][r] = res;
    return e[l][r];
}

int main()
{
    int n;
    cin >> n;
    for (int i = 0; i < n; i++)
        cin >> a[i];
    memset(d, -1, 510 * 510 * 8);
    memset(e, -1, 510 * 510 * 8);
    cout << E(0, n - 1);
    return 0;
}


#include <iostream>

using namespace std;

const int MOD = 1e+9 + 7;
long long a[510], d[510][510], e[510][510];

long long E(int l, int r);

long long D(int l, int r)
{
    if (d[l][r] != -1)
        return d[l][r];
    if (l == r + 1)
    {
        d[l][r] = 1;
        return 1;
    }
    long long Res = E(l, r);
    for (int i = l + 1; i <= r; i++)
    {
        int tmp = (E(l, i - 1)*D(i, r)) % MOD;
        Res = (Res + tmp*(a[l] < a[i])) % MOD;
    }
    d[l][r] = Res;
    return Res;
}

long long E(int l, int r)
{
    if (e[l][r] != -1)
        return e[l][r];
    if (l == r)
    {
        e[l][r] = 1;
        return 1;
    }
    long long res = D(l + 1, r);
    e[l][r] = res;
    return e[l][r];
}

int main()
{
    int n;
    cin >> n;
    for (int i = 0; i < n; i++)
        cin >> a[i];
    memset(d, -1, 510 * 510 * 4);
    memset(e, -1, 510 * 510 * 4);
    cout << E(0, n - 1);
    return 0;
}


#pragma comment (linker, "/STACK:1000000000")

#include <iostream>
#include <ctime>
#include <time.h>
#include <string>
#include <map>
#include <cstring>
#include <cmath>
#include <cstdio>
#include <queue>
#include <vector>
#include <algorithm>
#include <set>
#include <bitset>
#include <cassert>

using namespace std;

const int maxn = 510;
const long long p = (int)1e9 + 7;

int v[maxn];
long long dp[maxn][maxn];
int n;

long long go(int l, int r) {
	if (dp[l][r] == -1) {
		if (l == r) {
			dp[l][r] = 1;
		} else {
			dp[l][r] = 0;

			if (v[l + 1] > v[l]) {
				dp[l][r] = go(l + 1, r);
			}

			for (int i = l + 1; i <= r; i++) {
				if (i != r) {
					if (v[i] > v[l]) {
						dp[l][r] += go(l + 1, i) * go(i + 1, r);
					}
				} else {
					dp[l][r] += go(l + 1, i);
				}
				dp[l][r] %= p;
			}
		}
	}

	return dp[l][r];
}

int main() {
	scanf("%d", &n);

	for (int i = 1; i <= n; i++) {
		scanf("%d", &v[i]);
	}

	if (n == 1) {
		cout << "1" << endl;
		return 0;
	}

	memset(dp, 255, sizeof dp);

	cout << go(2, n) << endl;

	return 0;
}


#pragma comment (linker, "/STACK:1000000000")

#include <iostream>
#include <ctime>
#include <time.h>
#include <string>
#include <map>
#include <cstring>
#include <cmath>
#include <cstdio>
#include <queue>
#include <vector>
#include <algorithm>
#include <set>
#include <bitset>
#include <cassert>

using namespace std;

const int maxn = 510;
const long long p = (int)1e9 + 7;

int v[maxn];
long long dp[maxn][maxn];
int n;

long long go(int l, int r) {
	if (dp[l][r] == -1) {
		if (l == r) {
			dp[l][r] = 1;
		} else {
			dp[l][r] = 0;

			if (v[l + 1] > v[l]) {
				dp[l][r] = go(l + 1, r);
			}

			for (int i = l + 1; i <= r; i++) {
				if (i != r) {
					if (v[i + 1] > v[l]) {
						dp[l][r] += go(l + 1, i) * go(i + 1, r);
					}
				} else {
					dp[l][r] += go(l + 1, i);
				}
				dp[l][r] %= p;
			}
		}
	}

	return dp[l][r];
}

int main() {
	scanf("%d", &n);

	for (int i = 1; i <= n; i++) {
		scanf("%d", &v[i]);
	}

	if (n == 1) {
		cout << "1" << endl;
		return 0;
	}

	memset(dp, 255, sizeof dp);

	cout << go(2, n) << endl;

	return 0;
}


#include <functional>
#include <algorithm>
#include <iostream>
#include <memory.h>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <bitset>
#include <string>
#include <cstdio>
#include <complex>
#include <vector>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <set>
#include <map>
#include <unordered_set>
using namespace std;

#define int64 long long
#define mp make_pair

const int inf = 1e9;
const int MOD = 1e9+7;

#ifdef _DEBUG
    const int N = 510;
#else
    const int N = 510;
#endif

int n, a[N], dp[N][N];

int solve(int l, int r)
{
    if (dp[l][r] != -1) return dp[l][r];
    if (l >= r)
    {
        dp[l][r] = 1;
        return dp[l][r];
    }
    dp[l][r] = solve(l + 1, r);
    for (int j = l + 1; j <= r; j++)
        if (a[j] > a[l]) dp[l][r] = (1ll * dp[l][r] + 1ll * solve(l + 1, j - 1) * solve(j + 1, r)) % MOD;
    return dp[l][r];
}

int main()
{
#ifdef _DEBUG
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    scanf("%d", &n);
    for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
    memset(dp, -1, sizeof(dp));
    cout << solve(2, n);
    return 0;
}


#include <functional>
#include <algorithm>
#include <iostream>
#include <memory.h>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <bitset>
#include <string>
#include <cstdio>
#include <complex>
#include <vector>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <set>
#include <map>
#include <unordered_set>
using namespace std;

#define int64 long long
#define mp make_pair

const int inf = 1e9;
const int MOD = 1e9+7;

#ifdef _DEBUG
    const int N = 510;
#else
    const int N = 510;
#endif

int n, a[N], dp[N][N];

int solve(int l, int r)
{
    if (dp[l][r] != -1) return dp[l][r];
    if (l >= r)
    {
        dp[l][r] = 1;
        return dp[l][r];
    }
    dp[l][r] = solve(l + 1, r);
    for (int j = l + 1; j <= r; j++)
        if (a[j] > a[l]) dp[l][r] = (1ll * dp[l][r] + 1ll * solve(l + 1, j - 1) * solve(j, r)) % MOD;
    return dp[l][r];
}

int main()
{
#ifdef _DEBUG
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    scanf("%d", &n);
    for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
    memset(dp, -1, sizeof(dp));
    cout << solve(2, n);
    return 0;
}


#include <functional>
#include <algorithm>
#include <iostream>
#include <memory.h>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <bitset>
#include <string>
#include <cstdio>
#include <complex>
#include <vector>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <set>
#include <map>
#include <unordered_set>
using namespace std;

#define int64 long long
#define mp make_pair

const int inf = 1e9;
const int MOD = 1e9+7;

#ifdef _DEBUG
    const int N = 510;
#else
    const int N = 510;
#endif

int n, a[N], dp[N][N];

int solve(int l, int r)
{
    if (dp[l][r] != -1) return dp[l][r];
    if (l >= r)
    {
        dp[l][r] = 1;
        return dp[l][r];
    }
    dp[l][r] = solve(l + 1, r);
    for (int j = l + 1; j <= r; j++)
        if (a[j] > a[l]) dp[l][r] = (1ll * dp[l][r] + 1ll * solve(l + 1, j - 1) * 1ll * solve(j + 1, r)) % MOD;
    return dp[l][r];
}

int main()
{
#ifdef _DEBUG
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    scanf("%d", &n);
    for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
    memset(dp, -1, sizeof(dp));
    cout << solve(2, n);
    return 0;
}