#include #include #define rep(i,j,n) for(ll i=j;i<(ll)(n);i++) #define rrep(i,j,n) for(ll i=j;i>=n;i--) #define all(x) (x).begin(),(x).end() #define m0(x) memset(x,0,sizeof(x)) #define pb push_back #define mp make_pair #define perm(c) sort(all(c)); for(bool c##p=1;c##p;c##p=next_permutation(all(c))) #define UNIQUE(v) sort(v.begin(),v.end()); v.erase(unique(v.begin(),v.end()),v.end()) using namespace std; using namespace atcoder; typedef long long ll; typedef unsigned long long ull; typedef long double ld; template bool chmax(T &a, const T &b){if(a bool chmin(T &a, const T &b){if(a>b) {a=b;return 1;}return 0;} const ll LINF = 1LL << 60LL; const int IINF = (1 << 30) - 1; ll gcd(ll a,ll b){return b?gcd(b,a%b):a;} using mint = modint1000000007; mint dp[1100][1100][2][2] = {0}; void solve(){ ll n; cin >> n; dp[1][0][0][0] = 1; dp[2][0][0][0] = 2; rep(i,2,n){ rep(j,0,i){ if(j == 0){ // i+1 i-1 or i-1 i+1 dp[i+1][j+1][0][1] += 2*dp[i][j][0][0]; // others dp[i+1][j][0][0] += (i-1)*dp[i][j][0][0]; } else{ // i+1 i-1 or i-1 i+1 dp[i+1][j+1][0][1] += 2*dp[i][j][0][0]; // x i+1 x+2 dp[i+1][j-1][0][0] += j*dp[i][j][0][0]; // others dp[i+1][j][0][0] += (i-j-1)*dp[i][j][0][0]; // i-2 i+1 i dp[i+1][j-1][0][0] += dp[i][j][0][1]; // i+1 i-1 or i-1 i+1 dp[i+1][j+1][1][1] += 2*dp[i][j][0][1]; // x i+1 x+2 dp[i+1][j-1][1][0] += (j-1)*dp[i][j][0][1]; //others dp[i+1][j][1][0] += (i-j-1)*dp[i][j][0][1]; // i+1 i-1 or i-1 i+1 dp[i+1][j+1][1][1] += dp[i][j][1][1]; // i-2 i+1 i dp[i+1][j-1][0][0] += dp[i][j][1][1]; // x i+1 x+2 dp[i+1][j-1][1][0] += (j-2)*dp[i][j][1][1]; // x-3 i+1 x-1 dp[i+1][j][1][1] += dp[i][j][1][1]; // others dp[i+1][j][1][0] += (i-j)*dp[i][j][1][1]; dp[i+1][j+1][0][1] += dp[i][j][1][0]; dp[i+1][j-1][0][0] += (j-1)*dp[i][j][1][0]; // others dp[i+1][j][0][1] += dp[i][j][1][0]; dp[i+1][j][0][0] += (i-j)*dp[i][j][1][0]; } } } cout << dp[n][0][0][0].val() << endl; } int main(){ cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(20); ll T; T = 1; /* cin >> T; */ while(T--) solve(); }