/* -*- coding: utf-8 -*- * * 569.cc: No.569 3 x N グリッドのパスの数 - yukicoder */ #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; /* constant */ typedef long long ll; const ll MOD = 1000000007; // pattern: // 0: 1000, 1: 0100, 2: 0010, 3: 0001, // 4: 1220, 5: 1202, 6: 1022, // 7: 0122, // 8: 2210, // 9: 2201, 10: 2021, 11: 0221 const int N = 12; typedef ll mat[N][N]; const mat IM = { { 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0 }, { 1, 1, 1, 1, 0, 0, 1, 1, 0, 0, 0, 0 }, { 1, 1, 1, 1, 0, 0, 0, 0, 1, 1, 0, 0 }, { 1, 1, 1, 1, 0, 0, 0, 0, 1, 1, 1, 1 }, { 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0 }, { 0, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0 }, { 0, 0, 0, 1, 0, 1, 1, 1, 0, 0, 0, 0 }, { 0, 0, 0, 1, 0, 0, 1, 1, 0, 0, 0, 0 }, { 1, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0 }, { 1, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0 }, { 1, 1, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1 }, { 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1 }, }; /* typedef */ typedef vector vi; typedef queue qi; typedef pair pii; /* global variables */ /* subroutines */ void mulmat(const mat a, const mat b, mat c) { // a * b => c for (int i = 0; i < N; i++) for (int j = 0; j < N; j++) { c[i][j] = 0; for (int k = 0; k < N; k++) { c[i][j] += a[i][k] * b[k][j]; c[i][j] %= MOD; } } } inline void initmat(mat a) { for (int i = 0; i < N; i++) { fill(a[i], a[i] + N, 0); a[i][i] = 1; } } inline void copymat(const mat a, mat b) { // a -> b memcpy(b, a, sizeof(mat)); } void powmat(const mat a, ll b, mat p) { // a^b => c mat aa, c; initmat(p); copymat(a, aa); while (b > 0LL) { if ((b & 1LL) != 0LL) { mulmat(p, aa, c); copymat(c, p); } mulmat(aa, aa, c); copymat(c, aa); b >>= 1; } } /* main */ int main() { ll n; cin >> n; mat p; powmat(IM, n + 1, p); printf("%lld\n", p[3][0]); return 0; }