/* -*- coding: utf-8 -*- * * 1136.cc: No.1136 Four Points Tour - yukicoder */ #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; /* constant */ const int N = 4; const int MOD = 1000000007; /* typedef */ typedef long long ll; typedef int mat[N][N]; /* global variables */ mat ma, mb; /* subroutines */ inline void initmat(mat a) { memset(a, 0, sizeof(mat)); } inline void unitmat(mat a) { initmat(a); for (int i = 0; i < N; i++) a[i][i] = 1; } inline void copymat(const mat a, mat b) { memcpy(b, a, sizeof(mat)); } inline void mulmat(const mat a, const mat b, mat 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] = (c[i][j] + (ll)a[i][k] * b[k][j] % MOD) % MOD; } } inline void powmat(const mat a, ll b, mat c) { mat s, t; copymat(a, s); unitmat(c); while (b > 0) { if (b & 1) { mulmat(c, s, t); copymat(t, c); } mulmat(s, s, t); copymat(t, s); b >>= 1; } } /* main */ int main() { ll n; scanf("%lld", &n); for (int i = 0; i < N; i++) for (int j = 0; j < N; j++) ma[i][j] = (i == j) ? 0 : 1; powmat(ma, n, mb); printf("%d\n", mb[0][0]); return 0; }