#include using namespace std; typedef long long LL; #define CIN_ONLY if(1) struct cww{cww(){ CIN_ONLY{ ios::sync_with_stdio(false);cin.tie(0); } }}star; #ifdef BTK #define DEBUG if(1) #else #define DEBUG if(0) #endif #define fin "\n" #define FOR(i,bg,ed) for(int i=(bg);i<(ed);i++) #define REP(i,n) FOR(i,0,n) #define ALL(v) (v).begin(),(v).end() #define fi first #define se second #define pb push_back #define REC(ret, ...) std::function template inline bool chmin(T &l,T r) {bool a=l>r;if(a)l=r;return a;} template inline bool chmax(T &l,T r) {bool a=l istream& operator>>(istream &is,vector &v){ for(auto &it:v)is>>it; return is; } #define FOR(i,bg,ed) for(int i=(bg);i<(ed);i++) #define REP(i,n) FOR(i,0,n) typedef LL D; #define REP4(i,n) for(int i=0;i z; map> g; map> rg; inline string rev(string s){ reverse(ALL(s)); return s; } int M=0; void init(){ g["0123"]={"0123","1023","0001"}; g["1023"]={"1023","0001","0123","1203"}; g["1203"]={"1203","1023","1230","0001","0010"}; g["1230"]={"1230","1203","0010","0001"}; g["1000"]={"1000","0100","0010","0001","1230","1203","1023","0123"}; g["0100"]={"1000","0100","0010","0001","0123","1023"}; for(auto &it:g){ vector x; for(auto s:it.se)x.pb(rev(s)); rg[rev(it.fi)]=x; } for(auto &it:g)z[it.fi]=M++; for(auto &it:rg)z[it.fi]=M++; for(auto &it:g){ int v=z[it.fi]; for(auto &jt:it.se){ int u=z[jt]; mat[0](v,u)=1; } } for(auto &it:rg){ int v=z[it.fi]; for(auto &jt:it.se){ int u=z[jt]; mat[0](v,u)=1; } } REP(i,61)mat_mul(mat[i],mat[i],mat[i+1]); } LL calc_ret(vector v){ LL ret=0; ret+=v[z["0001"]]; return ret%mod; } int main(){ init(); LL N; cin>>N;N++; LL ret=0; vector v(M,0); v[z["1000"]]=1; int id=0; while(N){ vector nxt(M,0); if(N&1){ REP(i,M)REP(j,M) nxt[j]+=v[i]*mat[id](i,j); REP(i,M)nxt[i]%=mod; swap(v,nxt); } id++; N>>=1; } cout<