#include #define rep(i,n) for(int i=0;i<(int)(n);i++) #define chmin(x,y) x = min((x),(y)); #define chmax(x,y) x = max((x),(y)); using namespace std; using ll = long long ; using P = pair ; using pll = pair; const int INF = 1e9; const long long LINF = 1e17; const int MOD = 1000000007; //const int MOD = 998244353; const double PI = 3.14159265358979323846; template struct ModInt{ long long x=0; constexpr ModInt(long long x=0):x((x%mod+mod)%mod){} constexpr ModInt operator+(const ModInt& r)const{return ModInt(*this)+=r;} constexpr ModInt operator-(const ModInt& r)const{return ModInt(*this)-=r;} constexpr ModInt operator*(const ModInt& r)const{return ModInt(*this)*=r;} constexpr ModInt operator/(const ModInt& r)const{return ModInt(*this)/=r;} constexpr ModInt& operator+=(const ModInt& r){ if((x+=r.x)>=mod) x-=mod; return *this;} constexpr ModInt& operator-=(const ModInt& r){ if((x-=r.x)<0) x+=mod; return *this;} constexpr ModInt& operator*=(const ModInt& r){ if((x*=r.x)>=mod) x%=mod; return *this;} constexpr ModInt& operator/=(const ModInt& r){ return *this*=r.inv();} ModInt inv() const { long long s=x,sx=1,sy=0,t=mod,tx=0,ty=1; while(s%t!=0){ long long temp=s/t,u=s-t*temp,ux=sx-temp*tx,uy=sy-temp*ty; s=t;sx=tx;sy=ty; t=u;tx=ux;ty=uy; } return ModInt(tx); } ModInt pow(long long n) const { ModInt a=1; ModInt b=*this; while(n>0){ if(n&1) a*=b; b*=b; n>>=1; } return a; } friend constexpr ostream& operator<<(ostream& os,const ModInt& a) {return os << a.x;} friend constexpr istream& operator>>(istream& is,ModInt& a) {return is >> a.x;} }; using mint = ModInt; template struct Matrix{ int n,m; vector> Mat; Matrix(int n,int m,T val = 0):n(n),m(m){ Mat.assign(n,vector(m,val)); } Matrix(vector> Mat):Mat(Mat){ n = (int)Mat.size(); m = (int)(Mat[0].size()); } inline const vector &operator[](int i)const{ return Mat[i];} inline vector &operator[](int i){ return Mat[i];} }; template Matrix mul(Matrix &A, Matrix &B) { assert(A.m == B.n); Matrix C(A.n,B.m); for(int i=0;i Matrix matpow(Matrix &A,long long n){ assert(A.n == A.m); Matrix B(A.n,A.n); for(int i=0;i 0){ if(n & 1) B = mul(B,A); A = mul(A,A); n >>= 1; } return B; } template struct Vector{ int n; vector Vec; Vector(int n,T val = 0):n(n){ Vec.assign(n,val); } Vector(vector Vec):Vec(Vec){ int n = (int)Vec.size(); } inline const T &operator[](int i)const{ return Vec[i];} inline T &operator[](int i){ return Vec[i];} }; template Vector mul(Matrix &A,Vector &x){ assert(A.m == x.n); Vector Ax(A.n); for(int i=0;i> n; mint six_inv = mint(1)/mint(6); Matrix mat(6,6); rep(i,5) mat[i][i+1] = 1; rep(i,6) mat[5][i] = six_inv; Vector vec(6); vec[0] = 1; for(int i=1;i<6;i++){ for(int j=1;j<=6;j++){ if(i-j<0) break; vec[i] += vec[i-j]; } vec[i] *= six_inv; } mat = matpow(mat,n); vec = mul(mat,vec); cout << vec[0] << endl; return 0; }