#include using namespace std; #define p 1000000007 typedef long long ll; ll fac[1207],fac_inv[1207]; int n; int *sor; ll **dp; ll mod_pow(ll a,ll b){ ll res=1; while(b>0){ if(b%2==1)res=(res*a)%p; a=(a*a)%p; b/=2; } return res; } ll mod_inv(ll a){ return mod_pow(a,p-2); } void init(){ fac[0]=1; for(int i=1;i<1207;i++){ fac[i]=(fac[i-1]*i)%p; } fac_inv[0]=fac_inv[1]=1; for(int i=2;i<1207;i++){ fac_inv[i]=mod_inv(fac[i]); } return; } void cal(int a,int b){ if(dp[a][b]!=-1){ return; } if(a>sor[b]){ dp[a][b]=0; return; } ll res=0; for(int i=1;i<=a;i++){ cal(i,b+a); ll temp=(dp[i][b+a]*fac[a])%p; temp=(temp*fac_inv[a-i])%p; if(i==1&&b+a==n)temp=1; res=(res+temp)%p; } dp[a][b]=res; return; } int main(){ cin >> n; vector m(n); for(int m_i = 0; m_i < n; m_i++){ cin >> m[m_i]; } sor=new int[n]; for(int i=0;im[i+1]) sor[i]=1; } sor[n-1]=1; for(int i=n-2;i>=0;i--){ if(sor[i]==-1){ sor[i]=sor[i+1]+1; } } for(int i=0;i