#include "bits/stdc++.h" using namespace std; #define DEBUG(x) cout<<#x<<": "< #define vl vector #define vii vector< vector > #define vll vector< vector > #define vs vector #define pii pair #define pis pair #define psi pair #define pll pair const int inf = 1000000001; const ll INF = 2e18 * 2; #define MOD 1000000007 #define mod 1000000009 #define pi 3.14159265358979323846 #define Sp(p) cout<= mod ? a.n - a.Mod : a.n); } Modint operator-(Modint a, Modint b) { return Modint((a.n -= b.n) < 0 ? a.n + a.Mod : a.n); } Modint operator*(Modint a, Modint b) { return Modint(1LL * a.n * b.n % a.Mod); } Modint &operator+=(Modint &a, Modint b) { return a = a + b; } Modint &operator-=(Modint &a, Modint b) { return a = a - b; } Modint &operator*=(Modint &a, Modint b) { return a = a * b; } typedef vector vec; typedef vector mat; mat mul(mat &A, mat &B) { mat C(A.size(), vec(B[0].size())); for (int i = 0; i < A.size(); i++) { for (int k = 0; k < B.size(); k++) { for (int j = 0; j < B[0].size(); j++) { C[i][j] = C[i][j] + A[i][k] * B[k][j]; } } } return C; } mat pow(mat A, ll n) { mat B(A.size(), vec(A.size())); for (int i = 0; i < A.size(); i++) { B[i][i] = 1; } while (n > 0) { if (n & 1)B = mul(B, A); A = mul(A, A); n >>= 1; } return B; } int main() { ll n, i, j; cin >> n; mat A = { {0,1,1,2,0,1,1,1,2}, {1,0,1,0,1,0,0,0,0}, {1,1,0,0,1,0,0,0,0}, {0,0,0,0,1,0,0,0,0}, {0,0,0,1,0,0,0,0,0}, {1,1,1,1,1,0,0,0,0}, {0,1,0,0,0,0,0,0,0}, {0,0,1,0,0,0,0,0,0}, {0,0,0,1,0,0,0,0,0}, }; mat b = { {0}, {1}, {1}, {0}, {0}, {1}, {0}, {0}, {0} }; mat A2 = pow(A, n); mat ans = mul(A2, b); cout << ans[5][0].n << endl; }