// This C++ code is transpiled using Jikka transpiler v5.2.0.0 https://github.com/kmyk/Jikka // The original Python code: // from typing import * // // // def solve(n: int) -> int: // a = 1 // bcd = 0 // for _ in range(n): // tmp = bcd // bcd = a * 3 + bcd * 2 // a = tmp // return a % 1000000007 #include #include #include #include #include #include #include #include #include #include #line 3 "jikka/modulo_matrix.hpp" /** * @file jikka/modulo_matrix.hpp * @author Kimiyuki Onaka * @copyright Apache License 2.0 */ #line 3 "jikka/divmod.hpp" /** * @file jikka/divmod.hpp * @author Kimiyuki Onaka * @copyright Apache License 2.0 */ #include #include namespace jikka { inline int64_t floordiv(int64_t n, int64_t d) { assert(d != 0); return n / d - ((n ^ d) < 0 && n % d); } inline int64_t floormod(int64_t n, int64_t d) { assert(d != 0); n %= d; return (n < 0 ? n + d : n); } inline int64_t ceildiv(int64_t n, int64_t d) { assert(d != 0); return n / d + ((n ^ d) >= 0 && n % d); } inline int64_t ceilmod(int64_t n, int64_t d) { assert(d != 0); return n - ceildiv(n, d) * d; } } // namespace jikka #line 3 "jikka/matrix.hpp" /** * @file jikka/matrix.hpp * @author Kimiyuki Onaka * @copyright Apache License 2.0 */ #include namespace jikka { template using matrix = std::array, H>; namespace mat { template std::array ap(const matrix &a, const std::array &b) { std::array c = {}; for (size_t y = 0; y < H; ++y) { for (size_t x = 0; x < W; ++x) { c[y] += a[y][x] * b[x]; } } return c; } template matrix zero() { return {}; } template matrix one() { matrix a = {}; for (size_t i = 0; i < N; ++i) { a[i][i] = 1; } return a; } template matrix add(const matrix &a, const matrix &b) { matrix c; for (size_t y = 0; y < H; ++y) { for (size_t x = 0; x < W; ++x) { c[y][x] = a[y][x] + b[y][x]; } } return c; } template matrix mul(const matrix &a, const matrix &b) { matrix c = {}; for (size_t y = 0; y < H; ++y) { for (size_t z = 0; z < N; ++z) { for (size_t x = 0; x < W; ++x) { c[y][x] += a[y][z] * b[z][x]; } } } return c; } template matrix pow(matrix x, int64_t k) { matrix y = one(); for (; k; k >>= 1) { if (k & 1) { y = mul(y, x); } x = mul(x, x); } return y; } } // namespace mat } // namespace jikka #line 10 "jikka/modulo_matrix.hpp" #include namespace jikka { namespace modmat { using jikka::floormod; template std::array floormod(std::array x, int64_t MOD) { for (size_t i = 0; i < N; ++i) { x[i] = floormod(x[i], MOD); } return x; } template matrix floormod(matrix a, int64_t MOD) { for (size_t y = 0; y < H; ++y) { for (size_t x = 0; x < W; ++x) { a[y][x] = floormod(a[y][x], MOD); } } return a; } template std::array ap(const matrix &a, const std::array &b, int64_t MOD) { std::array c = {}; for (size_t y = 0; y < H; ++y) { for (size_t x = 0; x < W; ++x) { c[y] += a[y][x] * b[x] % MOD; } c[y] = floormod(c[y], MOD); } return c; } template matrix add(const matrix &a, const matrix &b, int64_t MOD) { matrix c; for (size_t y = 0; y < H; ++y) { for (size_t x = 0; x < W; ++x) { c[y][x] = floormod(a[y][x] + b[y][x], MOD); } } return c; } template matrix mul(const matrix &a, const matrix &b, int64_t MOD) { matrix c = {}; for (size_t y = 0; y < H; ++y) { for (size_t z = 0; z < N; ++z) { for (size_t x = 0; x < W; ++x) { c[y][x] += a[y][z] * b[z][x] % MOD; } } } for (size_t y = 0; y < H; ++y) { for (size_t x = 0; x < W; ++x) { c[y][x] = floormod(c[y][x], MOD); } } return c; } template matrix pow(matrix x, int64_t k, int64_t MOD) { matrix y = mat::one(); for (; k; k >>= 1) { if (k & 1) { y = mul(y, x, MOD); } x = mul(x, x, MOD); } return y; } } // namespace modmat } // namespace jikka #line 12 "main.cpp" int64_t solve(int64_t n_0) { return jikka::modmat::ap<2, 2>(jikka::modmat::pow<2>(std::array, 2>{std::array{0, 1}, std::array{3, 2}}, n_0, 1000000007), std::array{1, 0}, 1000000007)[0]; } int main() { int64_t x1 = -1; std::cin >> x1; auto x2 = solve(x1); std::cout << x2 << ' '; }