#pragma GCC optimize ("O3") #pragma GCC target ("avx") #include "bits/stdc++.h" // define macro "/D__MAI" using namespace std; typedef long long int ll; #define debugv(v) printf("L%d %s => ",__LINE__,#v);for(auto e:v){cout< ",__LINE__,#m);for(int x=0;x<(w);x++){cout<<(m)[x]<<" ";}cout< ostream& operator <<(ostream &o, const pair p) { o << "(" << p.first << ":" << p.second << ")"; return o; } #define TIME chrono::system_clock::now() #define MILLISEC(t) (chrono::duration_cast(t).count()) namespace { std::chrono::system_clock::time_point ttt; void tic() { ttt = TIME; } void toc() { fprintf(stderr, "TIME : %lldms\n", MILLISEC(TIME - ttt)); } std::chrono::system_clock::time_point tle = TIME; #ifdef __MAI void safe_tle(int msec) { assert(MILLISEC(TIME - tle) < msec); } #else #define safe_tle(k) ; #endif } template //typedef double T; class matrix { public: size_t height, width; valarray data; matrix(size_t height, size_t width) :height(height), width(width), data(height*width) {} matrix(size_t height, size_t width, const valarray& data) :height(height), width(width), data(data) {} inline T& operator()(size_t y, size_t x) { return data[y*width + x]; } inline T operator() (size_t y, size_t x) const { return data[y*width + x]; } inline T& at(size_t y, size_t x) { return data[y*width + x]; } inline T at(size_t y, size_t x) const { return data[y*width + x]; } inline void resize(size_t h, size_t w) { height = h; width = w; data.resize(h*w); } inline void fill(T val) { data = val; } matrix& setDiag(T val) { for (size_t i = 0, en = min(width, height); i < en; ++i)at(i, i) = val; return *this; } inline bool issquare() { return height == width; } void print(ostream& os) { os << "- - -" << endl; // << setprecision(3) for (size_t y = 0; y < height; ++y) { for (size_t x = 0; x < width; ++x) { os << setw(7) << at(y, x) << ' '; }os << endl; } } template void copyto2d(MT& d2) { for (size_t i = 0; i < width*height; ++i) { d2[i / width][i%width] = data[i]; } } // mathematics void pow(long long) const; double det() const; T tr(); matrix& transpose_self(); matrix transpose() const; }; // IO template inline ostream& operator << (ostream& os, matrix mat) { mat.print(os); return os; } // スカラー template inline matrix& operator+=(matrix& mat, T val) { mat.data += val; return mat; } template inline matrix& operator*=(matrix& mat, T val) { mat.data *= val; return mat; } template inline matrix& operator/=(matrix& mat, T val) { mat.data /= val; return mat; } template inline matrix& operator^=(matrix& mat, T val) { mat.data ^= val; return mat; } // 行列 template inline matrix& operator+=(matrix& mat1, matrix& mat2) { mat1.data += mat2.data; return mat1; } template inline matrix operator+(matrix& mat1, matrix& mat2) { return matrix(mat1.height, mat1.width, mat1.data + mat2.data); } // 掛け算 template matrix multiply(const matrix& mat1, const matrix& mat2) { assert(mat1.width == mat2.height); matrix result(mat1.height, mat2.width); for (size_t i = 0, j, k; i < mat1.height; i++) { for (j = 0; j < mat2.width; j++) { for (k = 0; k < mat1.width; k++) { result(i, j) += mat1(i, k) * mat2(k, j); } } } return result; } template valarray multiply(const matrix& mat1, const valarray& vec2) { assert(mat1.width == vec2.size()); valarray result(mat1.height); for (size_t i = 0, j; i < mat1.height; i++) { for (j = 0; j < mat1.width; j++) { result[i] += mat1(i, j) * vec2[j]; } } return result; } template inline matrix& operator*=(matrix& mat1, matrix& mat2) { mat1 = multiply(mat1, mat2); return mat1; } template inline matrix operator*(matrix& mat1, matrix& mat2) { return multiply(mat1, mat2); } void mojang(matrix& mat) { for (ll& d : mat.data) { d = d%MD; } } ll solve(ll n) { --n; matrix mat1(6, 6,valarray {0, 1, 1, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0}); matrix matz(6, 6); matz.setDiag(1); while (0 vect(6, 1, valarray{1, 0, 0, 1, 0, 1}); matrix rslt = matz * vect; return (rslt(0, 0) % MD + rslt(1, 0) % MD + rslt(2, 0) % MD) % MD; } int main() { int n; cin >> n; cout << solve(n) << endl; return 0; }