#include #define all(vec) vec.begin(), vec.end() #define eb emplace_back using namespace std; using ll = long long; using P = pair; constexpr ll INF = (1LL << 30) - 1LL; constexpr ll MOD = 1e9 + 7; template void chmin(T &a, T b) { a = min(a, b); } template void chmax(T &a, T b) { a = max(a, b); } void ok() { cerr << "ok" << endl; } //from http://noshi91.hatenablog.com/entry/2019/03/31/174006 template class modint { using u64 = std::uint_fast64_t; public: u64 a; constexpr modint(const u64 x = 0) noexcept : a(x % Modulus) {} constexpr u64 &value() noexcept { return a; } constexpr const u64 &value() const noexcept { return a; } constexpr modint operator+(const modint rhs) const noexcept { return modint(*this) += rhs; } constexpr modint operator-(const modint rhs) const noexcept { return modint(*this) -= rhs; } constexpr modint operator*(const modint rhs) const noexcept { return modint(*this) *= rhs; } constexpr modint operator/(const modint rhs) const noexcept { return modint(*this) /= rhs; } constexpr modint operator^(const u64 rhs) const noexcept { return modint(*this) ^= rhs; } constexpr modint &operator+=(const modint rhs) noexcept { a += rhs.a; if (a >= Modulus) { a -= Modulus; } return *this; } constexpr modint &operator-=(const modint rhs) noexcept { if (a < rhs.a) { a += Modulus; } a -= rhs.a; return *this; } constexpr modint &operator*=(const modint rhs) noexcept { a = a * rhs.a % Modulus; return *this; } constexpr modint &operator/=(modint rhs) noexcept { u64 exp = Modulus - 2; while (exp) { if (exp % 2) { *this *= rhs; } rhs *= rhs; exp /= 2; } return *this; } constexpr modint &operator^=(u64 exp) { modint rhs = modint(*this); a = 1; while (exp) { if (exp % 2) { *this *= rhs; } rhs *= rhs; exp /= 2; } return *this; } }; using mint = modint; template struct Matrix { vector> a; Matrix() {} Matrix(int n, int m) : a(n, vector(m)) {} inline const vector &operator[](int k) const { return a.at(k); } inline vector &operator[](int k) { return a.at(k); } Matrix I(int n) { Matrix mat(n, n); for (int i = 0; i < n; i++) { mat[i][i] = 1; } return mat; } Matrix &operator+=(const Matrix &rhs) { for (int i = 0; i < a.size(); i++) { for (int j = 0; j < a[i].size(); j++) { (*this)[i][j] += rhs[i][j]; } } return (*this); } Matrix &operator-=(const Matrix &rhs) { for (int i = 0; i < a.size(); i++) { for (int j = 0; j < a[i].size(); j++) { (*this)[i][j] -= rhs[i][j]; } } return (*this); } Matrix &operator*=(const Matrix &rhs) { int n = a.size(), m = a[0].size(), p = rhs[0].size(); assert(m == rhs.a.size()); vector> b(n, vector(p)); for (int i = 0; i < n; i++) { for (int j = 0; j < p; j++) { for (int k = 0; k < m; k++) { b[i][j] += (*this)[i][k] * rhs[k][j]; } } } swap(a, b); return (*this); } Matrix &operator^=(const long long &rhs) { long long n = rhs; Matrix res = Matrix::I(a.size()); while (n > 0) { if (n & 1) { res *= (*this); } (*this) *= (*this); n >>= 1; } swap(a, res.a); return (*this); } Matrix operator+(const Matrix &rhs) const { return Matrix(*this) += rhs; } Matrix operator-(const Matrix &rhs) const { return Matrix(*this) -= rhs; } Matrix operator*(const Matrix &rhs) const { return Matrix(*this) *= rhs; } Matrix operator^(const long long &rhs) const { return Matrix(*this) ^= rhs; } }; int main() { cin.tie(0); ios::sync_with_stdio(0); ll n; cin >> n; Matrix a(6, 6), b(6, 1), res(6, 1); b[1][0] = 1, b[3][0] = 1, b[5][0] = 1; a[0][1] = 1, a[1][0] = 1, a[1][1] = 1, a[2][3] = 1, a[3][2] = 1; a[3][3] = 1, a[3][4] = 2, a[4][3] = 1, a[4][4] = 1, a[5][2] = 1, a[5][3] = 1, a[5][4] = 2, a[5][5] = 1; res = (a ^ (n - 1LL)) * b; cout << res[5][0].a << endl; }