#include using namespace std; #define N 1205 #define ll long long #define pii pair #define mp make_pair int num[N],n; ll permu[N][N],ans = 0; const ll pri = pow(10,9)+7; bool pr[N][N]; ll perm(ll n,ll k) { if(permu[n][k] != 0) return permu[n][k]; ll an = 1; ll temp = n-k+1; while(temp <= n) { an *= temp; an %= pri; temp++; } permu[n][k] = an; return an; } ll dp[N][N]; ll myFn(int i,int j,int s,int t) { if(!pr[i][i+j-1]) return 0; else { ll temp = 0; if(s != 0 and dp[i+j][j] != 0) temp = dp[i+j][j]; else { for(int k=1;k <= j;k++) { if(i+j+k-1 <= n) { temp += myFn(i+j,k,1,j); temp %= pri; } else break; } if(temp == 0) temp = 1; if(s != 0) dp[i+j][j] = temp; } if(s != 0) temp *= perm((ll)t,(ll)j); temp %= pri; return temp; } } int main() { cin >> n; for(int i=1;i<=n;i++) cin >> num[i]; for(int i=1;i<=n;i++) { pr[i][i] = 1; int j=i+1,r=i; if(j <= n) { while(num[j] >= num[r]) { pr[i][j] = 1; j++; r++; if(j == n+1) break; } } } for(int i=1;i <= n;i++) { ans += myFn(1,i,0,0); ans %= pri; } cout << ans << endl; }