// May this submission get accepted #include // エイリアス using ll = long signed long; using ull = long unsigned long; using ld = long double; using namespace std; // AtCoder/Codeforces 用 デバッグ検知 #ifdef ONLINE_JUDGE constexpr bool DEBUG_MODE = false; #else constexpr bool DEBUG_MODE = true; #endif // エイリアス (補完・コンパイルが重くなる) // #include // using mll = boost::multiprecision::cpp_int; // 汎用マクロ #define ALL_OF(x) (x).begin(), (x).end() #define REP(i,n) for (long long i=0, i##_len=(n); i=i##_end; i--) #define STEP(i, is, ie, step) for (long long i=(is), i##_end=(ie), i##_step = (step); i<=i##_end; i+=i##_step) #define UNIQUE(v) do { sort((v).begin(), (v).end()); (v).erase(unique((v).begin(), (v).end()), (v).end()); } while (false) #define FOREACH(i,q) for (auto &i : q) template bool chmax(T &a, const T b) { if (a < b) {a = b; return true;} return false; } template bool chmin(T &a, const T b) { if (a > b) {a = b; return true;} return false; } constexpr int INF = numeric_limits::max(); constexpr long long LINF = numeric_limits::max(); constexpr long double EPS = 1e-10L; #define Yes(q) ((q) ? "Yes" : "No") #define YES(q) ((q) ? "YES" : "NO") #define Possible(q) ((q) ? "Possible" : "Impossible") #define POSSIBLE(q) ((q) ? "POSSIBLE" : "IMPOSSIBLE") #define IIF(q,t,f) ((q) ? (t) : (f)) #define DUMP(q) DUMP_FUNC(q, #q, __FILE__, __LINE__) template void DUMP_PROC(T x) { if (is_integral() || is_floating_point()) cerr << "\e[32m" << x << "\e[m"; else cerr << x; } template<> void DUMP_PROC(char x) { cerr << "\e[36m\'" << x << "\'\e[m"; } template<> void DUMP_PROC(string x) { cerr << "\e[33m\"" << x << "\"\e[m"; } template void DUMP_PROC(pair x) { cerr << "{"; DUMP_PROC(x.first); cerr << ", "; DUMP_PROC(x.second); cerr << "}"; } template void DUMP_PROC(tuple &x, integer_sequence) { (void)(int[]){(cerr << ((const char*[]){"", ", "})[!!Seq] << (DUMP_PROC(get(x)), ""), 0)...}; } template void DUMP_PROC(tuple x) {cerr << "{"; DUMP_PROC(x, index_sequence_for()); cerr << "}";} template void DUMP_PROC(vector x) { cerr << "["; for (auto &xi : x) { DUMP_PROC(xi); cerr << (&xi != &*x.rbegin()?", ":""); } cerr << "]"; } template void DUMP_FUNC(T x, const char* name, const char* fn, int ln) { cerr << "\e[32m[DEBUG]\e[m " << name << ": "; DUMP_PROC(x); cerr << " @ " << fn << "(" << ln << ")" << endl; } // gcc拡張マクロ #define popcount __builtin_popcount #define popcountll __builtin_popcountll // 標準入出力 struct qin { // query input size_t sz; qin(size_t _sz = 1) : sz(_sz) {} template operator T () const { T a; cin >> a; return a; } template operator vector () const { vector a(sz); for (size_t i = 0; i < sz; i++) cin >> a[i]; return a; } template operator pair () const { T f; U s; cin >> f >> s; return pair(f, s); } }; qin in1; // input one template void say(const T x, const char* end = "\n") { cout << x << end; } void say(const ld x, const char* end = "\n") { cout << setprecision(30) << x << end; } template void say(const vector x, const char* sep = " ", const char* end = "\n") { REP(i, x.size()) { cout << x[i] << (i+1 == i_len ? end : sep); } } template void say(const vector> x, const char* sep = " ", const char* end = "\n") { REP(i, x.size()) { say(x[i], sep, end); } } // モジュール // [[LIBRARY]] // 行列演算 // pdivの余りを取りたくない場合はoperator+=/-=/*のコメントアウトを適宜 constexpr ll pdiv = 1000000007LL; template class matrix { private: size_t col_size, row_size; vector raw; public: matrix() : col_size(0), row_size(0), raw() {} matrix(size_t n) : col_size(1), row_size(n), raw(n, 0) {} matrix(size_t n, size_t m) : col_size(m), row_size(n), raw(n * m, 0) {} matrix(const vector> &a) : col_size(a.size() ? a[0].size() : 0), row_size(a.size()), raw(col_size * row_size) { for (size_t i = 0; i < row_size; i++) { for (size_t j = 0; j < col_size; j++) { at(i, j) = a[i][j]; } } } matrix(initializer_list init) : col_size(init.size()), row_size(1), raw(init) {} matrix(initializer_list> init) : col_size(0), row_size(0), raw() { const size_t n = init.size(); const size_t m = [&]() { size_t maxm = 0; for (const auto& initi : init) { const size_t mi = initi.size(); if (mi > maxm) maxm = mi; } return maxm; }(); tie(row_size, col_size) = make_pair(n, m); raw.resize(n * m); size_t i = 0, j = 0; for (const auto &initi : init) { for (const auto &v : initi) { at(i, j++) = v; } i++; j = 0; } } size_t rows() const { return row_size; } size_t cols() const { return col_size; } const T& at(const size_t i, const size_t j) const { return raw.at(i * col_size + j); } const T& at(const size_t i) const { return raw.at(i); } T& at(const size_t i, const size_t j) { return raw.at(i * col_size + j); } T& at(const size_t i) { return raw.at(i); } T& operator() (size_t i, size_t j) { return raw[i * col_size + j]; } T& operator() (size_t i) { return raw[i]; } T& operator[] (size_t i) { return raw[i]; } const T& operator() (size_t i, size_t j) const { return raw[i * col_size + j]; } const T& operator() (size_t i) const { return raw[i]; } const T& operator[] (size_t i) const { return raw[i]; } matrix& operator+= (const matrix &a) { for (size_t i = 0; i < row_size; i++) { for (size_t j = 0; j < col_size; j++) { // at(i, j) += a.at(i, j); if ((at(i, j) += a.at(i, j)) >= pdiv) at(i, j) -= pdiv; } } return *this; } matrix& operator-= (const matrix &a) { for (size_t i = 0; i < row_size; i++) { for (size_t j = 0; j < col_size; j++) { // at(i, j) -= a.at(i, j); if ((at(i, j) += pdiv - a.at(i, j)) >= pdiv) at(i, j) -= pdiv; } } return *this; } matrix operator* (const matrix &a) { assert(col_size == a.row_size); const size_t n = row_size, m = col_size, q = a.col_size; matrix r(n, q); for (size_t i = 0; i < n; i++) { for (size_t k = 0; k < m; k++) { for (size_t j = 0; j < q; j++) { // r.at(i, j) += at(i, k) * a.at(k, j); (r.at(i, j) += at(i, k) * a.at(k, j) % pdiv) %= pdiv; } } } return r; } matrix operator+ (const matrix &a) const { matrix r = *this; return r += a; } matrix operator- (const matrix &a) const { matrix r = *this; return r -= a; } matrix& operator*= (const matrix &a) { return *this = move(*this * a); } operator T () const { assert(col_size == 1 && row_size == 1); return raw[0]; } static matrix eye(size_t n) { matrix r(n, n); for (size_t i = 0; i < n; i++) r.at(i, i) = 1; return r; } matrix transpose() const { matrix r(col_size, row_size); for (size_t i = 0; i < col_size; i++) { for (size_t j = 0; j < row_size; j++) { r.at(i, j) = at(j, i); } } return r; } matrix pow(long long int n) const { assert(row_size == col_size); matrix r = eye(row_size); matrix a = *this; while (n) { if (n & 1) r *= a; n /= 2; if (n) a *= a; } return r; } }; template void DUMPMTR(matrix m) { cerr << "[DEBUG] DUMPMTR: " << endl; for (size_t i = 0; i < m.rows(); i++) { cerr << " ["[!i] << "["; for (size_t j = 0; j < m.cols(); j++) { cerr << setw(4) << m(i, j) << " ]"[j+1 == m.cols()]; } if (i+1 == m.rows()) cerr << ']'; cerr << endl; } } // 剰余演算ライブラリ (小): 剰余と逆元だけ欲しいときに使う軽量ライブラリ // mod pdiv 上での a^n ll modpow(const ll a, ll n, const ll pdiv) { if (a == 0) return 0; ll r = 1; ((n %= pdiv-1) += pdiv-1) %= pdiv-1; // a^(p-1) === a^0 mod pdiv for (ll b = (a % pdiv + pdiv) % pdiv; n; n >>= 1, (b *= b) %= pdiv) if (n & 1) (r *= b) %= pdiv; return r; } inline ll modinv(const ll a, const ll pdiv) { return modpow(a, pdiv-2, pdiv); } // 処理内容 int main() { ios::sync_with_stdio(false); // stdioを使うときはコメントアウトすること cin.tie(nullptr); // インタラクティブ問題ではコメントアウトすること ll n = in1; ll sixth = modinv(6, pdiv); matrix m = { {sixth, sixth, sixth, sixth, sixth, sixth}, {1LL, 0LL, 0LL, 0LL, 0LL, 0LL}, {0LL, 1LL, 0LL, 0LL, 0LL, 0LL}, {0LL, 0LL, 1LL, 0LL, 0LL, 0LL}, {0LL, 0LL, 0LL, 1LL, 0LL, 0LL}, {0LL, 0LL, 0LL, 0LL, 1LL, 0LL} }; matrix x0 = matrix{1LL, 0LL, 0LL, 0LL, 0LL, 0LL}.transpose(); say((m.pow(n) * x0).at(0)); }