#include using namespace std; typedef long long ll; ll dp[1205][1205]; ll fact[1205],inv[1205]; ll M=1e9+7; ll modexp(ll a, ll b){ if(b==0) return 1; else{ ll temp=modexp(a,b/2); if(b%2==0) return (temp*temp)%M; else return (((temp*temp)%M)*a)%M; } } int main(){ fact[0]=1; for(int i=1;i<1205;i++) fact[i]=(fact[i-1]*i)%M; inv[0]=1; for(int i=1;i<1205;i++) inv[i]=modexp(fact[i],M-2); int n; scanf("%d",&n); int arr[n+1],limit[n+1]; for(int i=1;i<=n;i++) scanf("%d",arr+i); for(int i=1;i<=n;i++){ int j; for(j=i-1;j>=1;j--){ if(arr[j]<=arr[j+1]){} else break; } limit[i]=j+1; //cout << "limit " << i << " is " << limit[i] << endl; } for(int i=1;i<=n;i++){ for(int j=i;j>=limit[i];j--){ int k=i-j+1; if(j==1){ dp[i][i-j+1]=1; //cout << "dp[" << i << "][" << i-j+1 << "] is " << dp[i][i-j+1] << endl; break; } while(k<=i){ //if(i==4 && k==1)cout << "k is " << k << "dp[" << j-1 << "][" << k << "] is " << dp[j-1][k] << endl; if(dp[j-1][k]>0) dp[i][i-j+1]=(dp[i][i-j+1]+(dp[j-1][k]*((fact[k]*inv[k-i+j-1])%M))%M)%M; k++; } //cout << "dp[" << i << "][" << i-j+1 << "] is " << dp[i][i-j+1] << endl; } } ll ans=0; for(int i=0;i<1205;i++) ans=(ans+dp[n][i])%M; printf("%lld\n",ans); return 0; }