#include #define gc getchar #define ii(x) scanf(" %d", &x) #define ill(x) scanf(" %lld", &x) #define ll long long #define pb push_back #define mp make_pair #define F first #define S second #define all(x) x.begin(),x.end() #define fill(a,b) memset(a, b, sizeof(a)) #define rep(i,a,b) for(i=a;i=b;i--) #define pii pair using namespace std; void in(int &x){ register int c=gc(); x=0; for(;(c<48||c>57);c=gc()); for(;c>47&&c<58;c=gc()){x=(x<<1)+(x<<3)+c-48;} } const int N = 1203; const ll mod = 1e9 + 7; ll a[N], dp[N][N], fact[N], ifact[N]; ll powmod(ll base, ll exp){ ll res = 1; while(exp){ if(exp & 1) res = (res * base) % mod; base = (base * base) % mod; exp >>= 1; } return res; } int main() { ll n, i, j; fact[0] = ifact[0] = 1; rep(i, 1, N) fact[i] = (fact[i - 1] * i) % mod; rep(i, 1, N) ifact[i] = powmod(fact[i], mod - 2); cin >> n; rep(i, 1, n + 1) cin >> a[i]; dp[n][1] = 1; per(i, n - 1, 1){ ll diff = n - i + 1, pre = -1; rep(j, 1, diff + 1){ //cout << i << " " << j << " " << diff << " "; if(a[i + j - 1] > pre){ //cout << "yes"; pre = a[i + j - 1]; if(j == 1 || j == diff) dp[i][j] = 1; else for(ll k = 1; k <= j; k++){ ll comb = (fact[j] * ifact[j - k]) % mod; dp[i][j] = (dp[i][j] + ((dp[i + j][k] * comb) % mod)) % mod; } }else break; //cout << endl; } } ll ret = 0; rep(i, 1, n + 1) ret = (ret + dp[1][i]) % mod; cout << ret << endl; return 0; }