#include #define rep(i,n) for(int i=(0);i<(n);i++) using namespace std; typedef long long ll; 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 MOD = 1e9 + 7; typedef vector> mat; void print(mat A){ rep(i, A.size()){ rep(j, A[i].size()){ cout << A[i][j] << (j == A[i].size()-1 ? "\n" : " "); } } } mat mmul(mat A, mat B){ int n = A.size(); int l = A[0].size(); int m = B[0].size(); mat C(n, vector(m, 0)); for(int i = 0; i < n; i++){ for(int j = 0; j < m; j++){ for(int k = 0; k < l; k++){ C[i][j] += A[i][k] * B[k][j]; C[i][j] %= MOD; } } } return C; } mat mE(int n){ mat A(n, vector(n, 0)); for(int i = 0; i < n; i++){ A[i][i] = 1LL; } return A; } mat mpow(mat A, ll x){ int n = A.size(); if(x == 0) return mE(n); if(x % 2 == 1) return mmul(A, mpow(A, x - 1)); mat B = mpow(A, x / 2); return mmul(B, B); } int main(){ cin.tie(0); ios::sync_with_stdio(false); ll n; cin >> n; mat x = mat(4, vector(1, 0)); x[0][0] = 1; x[1][0] = 0; x[2][0] = 0; x[3][0] = 0; mat A = mat(4, vector(4, 0)); rep(i, 4) rep(j, 4) A[i][j] = (i == j ? 0 : 1); A = mpow(A, n); x = mmul(A, x); cout << x[0][0] << endl; }