#include using namespace std; #define int long long #define ii pair #define app push_back #define all(a) a.begin(), a.end() #define bp __builtin_popcountll #define ll long long #define mp make_pair #define f first #define s second #define Time (double)clock()/CLOCKS_PER_SEC #define debug(x) std::cout << #x << ": " << x << '\n'; const int N = 4, MOD = 1000 * 1000 * 1000 + 7; int mod(int n) { n %= MOD; if (n < 0) return n + MOD; else return n; } void add(int &a, int b) { a = mod(a + b); } void clear(int a[N][N], bool t) { for (int i = 0; i < N; ++i) for (int j = 0; j < N; ++j) a[i][j] = t * (i == j); } void cop(int a[N][N], int b[N][N]) { for (int i = 0; i < N; ++i) for (int j = 0; j < N; ++j) a[i][j] = b[i][j]; } int t[N][N]; void add(int a[N][N], int b[N][N]) { clear(t, 0); for (int i = 0; i < N; ++i) for (int j = 0; j < N; ++j) for (int k = 0; k < N; ++k) add(t[i][j], a[i][k] * b[k][j]); cop(a, t); } void print(int a[N][N]) { for (int i = 0; i < N; ++i) { for (int j = 0; j < N; ++j) cout << a[i][j] << ' '; cout << '\n'; } cout << '\n'; } int ans[N][N], cur[N][N]; void fp(int a[N][N], int p) { cop(cur, a); clear(ans, 1); for (int i = 0; (1ll << i) <= p; ++i) { if ((p >> i) & 1) add(ans, cur); add(cur, cur); } cop(a, ans); } int a[N][N]; signed main() { #ifdef HOME freopen("input.txt", "r", stdin); #else #define endl '\n' ios_base::sync_with_stdio(0); cin.tie(0); #endif int n; cin >> n; for (int i = 0; i < 4; ++i) for (int j = 0; j < 4; ++j) if (i != j) a[i][j] = 1; fp(a, n); cout << a[0][0] << endl; }