#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i)) #define rer(i,l,u) for(int (i)=(int)(l);(i)<=(int)(u);++(i)) #define reu(i,l,u) for(int (i)=(int)(l);(i)<(int)(u);++(i)) #if defined(_MSC_VER) || __cplusplus > 199711L #define aut(r,v) auto r = (v) #else #define aut(r,v) __typeof(v) r = (v) #endif #define each(it,o) for(aut(it, (o).begin()); it != (o).end(); ++ it) #define all(o) (o).begin(), (o).end() #define pb(x) push_back(x) #define mp(x,y) make_pair((x),(y)) #define mset(m,v) memset(m,v,sizeof(m)) #define INF 0x3f3f3f3f #define INFL 0x3f3f3f3f3f3f3f3fLL using namespace std; typedef vector vi; typedef pair pii; typedef vector > vpii; typedef long long ll; template inline void amin(T &x, U y) { if(y < x) x = y; } template inline void amax(T &x, U y) { if(x < y) x = y; } template struct ModInt { static const int Mod = MOD; unsigned x; ModInt() : x(0) {} ModInt(signed sig) { int sigt = sig % MOD; if(sigt < 0) sigt += MOD; x = sigt; } ModInt(signed long long sig) { int sigt = sig % MOD; if(sigt < 0) sigt += MOD; x = sigt; } int get() const { return (int)x; } ModInt &operator+=(ModInt that) { if((x += that.x) >= MOD) x -= MOD; return *this; } ModInt &operator-=(ModInt that) { if((x += MOD - that.x) >= MOD) x -= MOD; return *this; } ModInt &operator*=(ModInt that) { x = (unsigned long long)x * that.x % MOD; return *this; } ModInt operator+(ModInt that) const { return ModInt(*this) += that; } ModInt operator-(ModInt that) const { return ModInt(*this) -= that; } ModInt operator*(ModInt that) const { return ModInt(*this) *= that; } }; typedef ModInt<1000000007> mint; struct DP { int N; vector dp; DP(int N_) : N(N_) { init(); } void init() { dp.assign(N * 8, mint()); } void swap(DP &that) { dp.swap(that.dp); } //lasta: 1つ前のがattackされてるか //snda: 2つ前のがattackされてるか //twoc: 1つ前のと2つ前のが隣り合ってるか //num: 3つより前のattackされてる個数 mint &operator()(int lasta, int snda, int twoc, int num) { return dp[(lasta * 4 + snda * 2 + twoc) * N + num]; } }; int main() { /* rer(N, 1, 10) { vi perm(N); iota(perm.begin(), perm.end(), 0); int cnt[2][2][2][11] = {}; do { int lasta = N >= 3 && abs(perm[0] - perm[2]) == 1; int snda = N >= 4 && abs(perm[1] - perm[3]) == 1; int twoc = N >= 2 && abs(perm[0] - perm[1]) == 1; int num = 0; reu(i, 2, N - 2) num += abs(perm[i] - perm[i + 2]) == 1; ++ cnt[lasta][snda][twoc][num]; } while(next_permutation(perm.begin(), perm.end())); rep(lasta, 2) rep(snda, 2) rep(twoc, 2) rer(num, 0, N) { mint x = cnt[lasta][snda][twoc][num]; if(x.x == 0) continue; cerr << N << ", " << lasta << ", " << snda << ", " << twoc << ", " << num << ": " << x.get() << endl; } int naiveans = cnt[0][0][0][0] + cnt[0][0][1][0]; cerr << N << ": " << naiveans << endl; }*/ int N; while(~scanf("%d", &N)) { DP dp(N), ndp(N); ndp(0, 0, 0, 0) = 1; rep(i, N) { dp.swap(ndp); ndp.init(); rep(lasta, 2) rep(snda, 2) rep(twoc, 2) rer(num, 0, i) { mint x = dp(lasta, snda, twoc, num); if(x.x == 0) continue; // cerr << i << ", " << lasta << ", " << snda << ", " << twoc << ", " << num << ": " << x.get() << endl; if(twoc == 0) { if(i >= 1) { //1つ前のやつの左右 ndp(0, lasta, 1, num + snda) += x; ndp(0, 0, 1, num + snda) += x; } if(i >= 2) { //2つ前のやつの左右 ndp(1, lasta, 0, num) += x; ndp(1, lasta, 0, num + snda) += x; } } else { assert(i >= 2); //1つ前のやつの隣で、2つ前のじゃないほう ndp(0, 0, 1, num + snda) += x; //1つ前のと2つ前のとの間 ndp(1, lasta, 1, num + snda) += x; //2つ前のやつの隣で、1つ前のじゃないほう ndp(1, lasta, 0, num) += x; } //1つ前の隣でも2つ前の隣でもない場所 int spaces = (i + 1) - (i >= 1 ? 2 : 0) - (i >= 2 ? 2 : 0) + twoc; //そのうちattackされてるやつらの間 if(num > 0) ndp(0, lasta, 0, num - 1 + snda) += x * num; //それ以外 ndp(0, lasta, 0, num + snda) += x * (spaces - num); } } mint ans; rep(twoc, 2) ans += ndp(0, 0, twoc, 0); printf("%d\n", ans.get()); } return 0; }