#include #include #include #include #include #define FF 1000000007 using namespace std; int main() { long long n; cin>>n; vector vin(n); vector isbreak(n, false); for (long long i=0; i>vin[i]; } for (long long i=1; i > D(n+1, vector (n+1,1)); for (long long row=2; row<=n; row++){ for (long long col=n-1; col>=0; col--){ if (col==0 || col-row>=0){ long long s=0; long long link=1; long long accCol=col+link; long long accRow=1; long long fac=row; long long mult=fac; while (accCol<=n && link<=row){ if (col>0){ s=(s+(mult*D[accRow][accCol])%FF)%FF; } else if (col==0 && accRow==row){ s=D[accRow][accCol]; } if (isbreak[accCol]){ break; } accRow++; accCol++; link++; fac--; mult=(mult*fac)%FF; } D[row][col]=s; } } } long long result=0; for (long long row=1; row<=n; row++){ /*for (long long col=0; col