#include #include #include using namespace std; typedef long long int Lint; const int MAXN = 2000; const Lint MOD = 1e9+7; int N; int ar[MAXN]; Lint factorial[MAXN]; Lint dn[MAXN][MAXN]; Lint permutation[MAXN][MAXN]; Lint fast_power( Lint base , int power ){ if( power == 0 ) return 1LL; if( power == 1 ) return base; Lint next = fast_power(base,power>>1); if( power&1 ) return (next*next*base)%MOD; return (next*next)%MOD; } Lint f( int place , int last ){ Lint &rev = dn[place][last]; if( rev != -1 ) return rev; if( place == N+1 ) return rev=1; if( place == 1 ) rev = f(place+1,1); else rev = (f(place+1,1)*last)%MOD; for( int i=1 ; i