#include #define all(x) begin(x), end(x) using namespace std; using i32 = int; using i64 = long long; using ld = long double; template inline bool chmax(T1 &a, T2 b) {return a < b and (a = b, true);} template inline bool chmin(T1 &a, T2 b) {return a > b and (a = b, true);} const i64 supl = LONG_LONG_MAX / 2 - 100; const i32 supi = INT_MAX / 2 - 100; const i32 mod = 1000000007; vector> mul(vector>& a, vector>& b) { assert(a[0].size() == b.size()); vector res(a.size(), vector(b[0].size(), 0LL)); for (size_t i = 0 ; i < a.size() ; i++) { for (size_t j = 0 ; j < b[0].size() ; j++) { for (size_t k = 0 ; k < a[0].size() ; k++) { res[i][j] += (a[i][k] * b[k][j]) % mod; res[i][j] %= mod; } } } return res; } void main_() { i64 n; cin >> n; const i32 lg = 64; vector dob(lg, vector(4, vector(4, 0LL))); dob[0] = { { 0, 1, 1, 1 }, { 1, 0, 1, 1 }, { 1, 1, 0, 1 }, { 1, 1, 1, 0 } }; for (i32 i = 0 ; i + 1 < lg ; i++) { dob[i + 1] = mul(dob[i], dob[i]); } vector mat(4, vector(4, 0LL)); for (i32 i = 0 ; i < 4 ; i++) { mat[i][i] = 1; } for (i32 i = 0 ; i < lg ; i++) { if (n & (1LL << i)) { mat = mul(mat, dob[i]); } } cout << mat[0][0] << endl; } int main() { ios::sync_with_stdio(false); std::cin.tie(nullptr); main_(); return 0; }