#include using namespace std; const int64_t mod=1e9+7; int64_t n,a[1205],fac[1205],C[1205][1205],F[1205][1205]; bool FF[1205][1205],Free[1205][1205]; int64_t f(int64_t i,int64_t j) { if(i>n) return 1; if(Free[i][j]==true) return F[i][j]; Free[i][j]=true; int64_t sum=0; for(int64_t k=i;k<=min(i+j-1,n);k++) if(FF[i][k]==true) sum=(sum+f(k+1,k-i+1)*C[j][k-i+1]%mod*fac[k-i+1]%mod)%mod; else break; return F[i][j]=sum; } int main() { //freopen("A.INP","r",stdin); cin>>n; for(int64_t i=1;i<=n;i++) cin>>a[i]; for(int64_t i=1;i<=n;i++) { FF[i][i]=true; for(int64_t j=i+1;j<=n;j++) if(a[j]>a[j-1]) FF[i][j]=true; else break; } fac[0]=1; for(int64_t i=1;i<=n;i++) fac[i]=fac[i-1]*i%mod; for(int64_t i=0;i<=n;i++) { C[i][0]=1; C[i][i]=1; for(int64_t j=1;j