#include using namespace std; #define mod 1000000007 #define ll long long ll permu[1300][1300]={{0}}; ll dp[1300][1300]; ll cum_sum[1300][1300]; void precompute() { ll i,j; for(i=1;i<=1205;i++) permu[i][0] = 1; for(i=1;i<=1205;i++) { for(j=1;j<=i;j++) { permu[i][j] = (permu[i][j-1]*(i-j+1))%mod; } } } ll _sorted(ll arr[],ll st,ll end,ll n) { ll val = arr[st]; ll i = st+1; ll max_len = 1; while(i<=end&&i<=n) { if(arr[i]>val) { val = arr[i]; i++; max_len++; } else break; } return max_len; } int main() { ll n,i,ans,v,curr_v,len,val,j,k,arr[1300]; precompute(); cin >> n; for(i=1;i<=n;i++) cin >> arr[i]; // for sizeof(V) = 1; /*for(v=2;v<=n;v++) { curr_v = v; i = 1; //index in array if(_sorted(arr,i,i+v-1)==v) //from (1,v) { i = i+curr_v; while(curr_v>1&&i<=n) { val = 1; //sizeof(V) = v; len = _sorted(arr,i,i+curr_v-1); //curr_v = len , will be updated later val = (val*permu[curr_v][len]); curr_v = len; i = i+curr_v; } ans = (ans+val)%mod; } else //if no sorted length of size v, no length of size > v break; }*/ for(j=0;j<=n;j++) dp[n+1][j] = 1; for(i=1;i<=n;i++) dp[i][1] = 1; //cout << n << endl; for(i=n-1;i>0;i--) { //cout << i << "- " <n) dp[i][j] = (dp[i][j]+1)%mod; else { for(k=1;k<=j;k++) { dp[i][j] = (dp[i][j]+permu[j][k]*dp[i+j][k])%mod; //cout << i <<" " << j << " " << k << endl; } } //cout << dp[i][j] << ";"; } else break; } //cout << endl; } ans = 0; for(i=1;i<=n;i++) ans = (ans+dp[1][i])%mod; cout << ans << endl; }