#include using namespace std; #define x first #define y second #define low(x) (x&-x) typedef long long int LL; int dp[1205][1205]; int mul[1205][1205]; int fac[1205],rev[1205],mod=1000000007; LL poww(LL a,LL b){ LL tmp = 1; while(b){ if(b&1) tmp=tmp*a%mod; a=a*a%mod; b>>=1; } return tmp; } int s[1205]; int main(){ rev[0]=fac[0]=1; for(int i=1;i<=1200;i++) fac[i]=1LL*fac[i-1]*i%mod; for(int i=1;i<=1200;i++) rev[i]=1LL*rev[i-1]*poww(i,mod-2)%mod; int n; scanf("%d",&n); for(int i=1;i<=n;i++){ scanf("%d",&s[i]); } //memset(dp,-1,sizeof(dp)); for(int i=1;i<=n;i++){ for(int j=i;j>=1;j--){ if(js[j+1]) break; int len=i-j+1; if(j==1){ dp[i][len]=1; continue; } int tmp=0; for(int k=len;k<=j-1;k++){ //if(!dp[j-1][k]) break; tmp+=1LL*mul[j-1][k]*rev[k-len]%mod; tmp%=mod; } dp[i][len]=tmp; } for(int j=1;j<=i;j++){ mul[i][j]=1LL*dp[i][j]*fac[j]%mod; } } LL ans=0; for(int i=1;i<=n;i++){ ans=(ans+dp[n][i])%mod; } printf("%lld\n",ans); }