#include using namespace std; typedef long long ll; typedef long double ld; ll big = 1000000007ll; int n,q,m,k,x,y; ll T; ll FAC[2000] = {0}; ll INV[2000] = {0}; vector M; ll DP[1400][1400] = {0}; ll upp(ll i, ll j){ if(j == 0)return 1; if(j%2 == 0){ ll h = upp(i,j/2); return (h*h)%big; } return (upp(i,j-1)*i)%big; } ll bin(ll i, ll j){ if(j > i)return 0; return (FAC[i]*INV[i-j])%big; } void setup(){ ll t = 1; for(ll c1 = 0; c1 < 1201; c1++){ FAC[c1] = t; INV[c1] = upp(t, big-2); t *=c1+1; if(t >= big)t %= big; } } ll dp(ll i, ll k2){ if(i == n)return 1; if(DP[i][k2] != -1)return DP[i][k2]; ll mi = M[i]; ll ans = 0; for(ll c1 = 1; c1 <= min(n-i , k2); c1++){ if(M[i+c1-1] < mi)break; mi = M[i+c1-1]; ll co = 1; if(k2 != n)co = bin(k2,c1); ans += (co*dp(i+c1 , c1)); ans %= big; } DP[i][k2] = ans; return ans; } int main() { //freopen("input.txt","r",stdin); //freopen("output.txt","w",stdout); ll c1,c2,c3,c4,c5; int a,b,c; setup(); //cin >> n; scanf("%d" , &n); for(c1 = 0; c1 < n; c1++){ scanf("%d" , &a); M.push_back(a); for(c2 = 0; c2 < n+1; c2++){ DP[c1][c2] = -1; } } cout << dp(0,n) << "\n"; return 0; }