#pragma GCC optimize("Ofast") #include using namespace std; #ifdef __LOCAL #include #else #define debug(...) void(0) #endif #define REP(i,n) for(int i=0;i<(n);i++) #define ALL(v) v.begin(),v.end() template istream& operator>>(istream&is,vector&v){ for(T&p:v)is>>p; return is; } template ostream& operator<<(ostream&os,const vector&v){ if(&os==&cerr)os<<"["; for(int i=0;i struct Mint{ inline static constexpr T mod = MOD; T v; Mint():v(0){} Mint(signed v):v(v){} Mint(long long t){v=t%MOD;if(v<0)v+=MOD;} Mint pow(long long k){ Mint res(1),tmp(v); while(k){ if(k&1)res*=tmp; tmp*=tmp; k>>=1; } return res; } static Mint add_identity(){return Mint(0);} static Mint mul_identity(){return Mint(1);} Mint inv(){return pow(MOD-2);} Mint& operator+=(Mint a){v+=a.v;if(v>=MOD)v-=MOD;return *this;} Mint& operator-=(Mint a){v+=MOD-a.v;if(v>=MOD)v-=MOD;return *this;} Mint& operator*=(Mint a){v=1LL*v*a.v%MOD;return *this;} Mint& operator/=(Mint a){return (*this)*=a.inv();} Mint operator+(Mint a) const{return Mint(v)+=a;} Mint operator-(Mint a) const{return Mint(v)-=a;} Mint operator*(Mint a) const{return Mint(v)*=a;} Mint operator/(Mint a) const{return Mint(v)/=a;} Mint operator+() const{return *this;} Mint operator-() const{return v?Mint(MOD-v):Mint(v);} bool operator==(const Mint a)const{return v==a.v;} bool operator!=(const Mint a)const{return v!=a.v;} static Mint comb(long long n,int k){ Mint num(1),dom(1); for(int i=0;i>(istream&is,Mint &m){is>>m.v;m.v%=MOD;if(m.v<0)m.v+=MOD;return is;} }; using ll=long long; using mint=Mint; #define REP_(i,n) for(int i=0;i<(n);i++) #define REP2_(i,s,n) for(int i=(s);i<(n);i++) template struct Matrix{ typedef vector vec; typedef vector mat; size_t r,c; mat M; Matrix(size_t r,size_t c):r(r),c(c),M(r,vec(c,K())){} Matrix(mat A):M(A),r(A.size()),c(A[0].size()){} vec& operator[](size_t k){return M[k];} const vec& operator[](size_t k)const{return M[k];} friend Matrix operator+(const Matrix &A,const Matrix &B){ assert(A.r==B.r&&A.c==B.c); Matrix res(A); REP_(i,A.r)REP_(j,A.c)res[i][j]+=B[i][j]; return res; } Matrix& operator+=(const Matrix &B){ assert(r==B.r&&c==B.c); REP_(i,r)REP_(j,c)M[i][j]+=B[i][j]; return *this; } friend Matrix operator*(const Matrix &A,const Matrix &B){ assert(A.c==B.r); Matrix res(A.r,B.c); REP_(i,A.r)REP_(k,A.c)REP_(j,B.c)res[i][j]+=A[i][k]*B[k][j]; return res; } Matrix& operator*=(const Matrix &B){ M=((*this)*B).M; return *this; } static Matrix I(size_t n){ Matrix res(n,n); REP_(i,n)res[i][i]=K(1); return res; } Matrix pow(long long n)const{ assert(n>=0&&r==c); Matrix A(M),res=I(r); while(n){ if(n&1)res*=A; A*=A; n>>=1; } return res; } int rank() const{ Matrix A(M); int res=0; REP_(k,c){ for(int i=res+1;i>n; if(n&1){ Matrix A(8,8); A[4][6]=A[6][7]=A[4][5]=A[7][5]=A[5][4]=A[1][0]=A[3][1]=A[0][1]=A[5][2]=A[0][2]=A[2][3]=A[4][3]=A[7][3]=1; A=A.pow(n); cout< A(4,4); A[0][2]=A[2][3]=A[0][1]=A[3][1]=A[1][0]=1; A=A.pow(n); cout<