//hi #include using namespace std; #define PB push_back #define MP make_pair #define F first #define S second #define mod 1000000007 typedef long long int LL; LL a[1204]; LL dp[1204][1204]; LL dps[1204][1204]; LL step[1204]; LL istep[1204]; LL mpow(LL a,LL b){ LL ret=1; while(b){ if(b&1) ret=(ret*a)%mod; a=(a*a)%mod; b>>=1; } return ret; } int main(void){ int n; scanf("%d",&n); int i,l,l2; for(i=1;i<=n;i++) scanf("%lld",&a[i]); step[0]=step[1]=1; for(i=2;i<=n;i++) step[i]=(step[i-1]*i)%mod; istep[0]=istep[1]=1; for(i=2;i<=n;i++) istep[i]=mpow(step[i],mod-2); for(i=1;i<=n;i++){ int mn=a[i]; for(l=1;i-l>=0;l++){ int p=i-l; for(l2=l;l2<=p;l2++){ dp[i][l]+=(((dp[p][l2]*step[l2])%mod)*istep[l2-l])%mod; dp[i][l]%=mod; } if(i==l) dp[i][l]=1; //printf("%d %d %lld\n",i,l,dp[i][l]); if(a[p]>mn) break; mn=a[p]; } } LL ans=0; for(l=1;l<=n;l++){ ans+=dp[n][l]; ans%=mod; } printf("%lld\n",ans); return 0; }