#include using namespace std; typedef long long ll; typedef pair ii; #define X first #define Y second const int N=1210; const int MOD=1e9+7; const ll linf=1e10; const int inf=2e9+10; const int maxv=40; const double eps=1e-12; int n,a[N]; int oseg[N],f[N][N]; int fac[N],rev[N],revfac[N]; int C(int x,int y){ return 1LL*fac[x]*revfac[y]%MOD*revfac[x-y]%MOD; } int solve(){ fac[0]=1; for(int i=1;i<=n;i++) fac[i]=1LL*fac[i-1]*i%MOD; rev[1]=1; for(int i=2;i<=n;i++) rev[i]=MOD-1LL*(MOD/i)*rev[MOD%i]%MOD; revfac[0]=1; for(int i=1;i<=n;i++) revfac[i]=1LL*revfac[i-1]*rev[i]%MOD; /// oseg[1]=1; for(int i=2;i<=n;i++) if (a[i]>a[i-1]) oseg[i]=oseg[i-1]; else oseg[i]=i; f[n+1][0]=1; for(int tot=n+1;tot>=2;tot--) for(int len=0;len<=n-tot+1;len++) for(int len2=max(len,1);tot-len2>=oseg[tot-1];len2++) { f[tot-len2][len2]=(f[tot-len2][len2]+1LL*f[tot][len]*fac[len2]%MOD*revfac[len2-len])%MOD; } // for(int i=1;i<=n;i++) // for(int j=1;j<=n;j++) cout<