#include using namespace std; typedef long long ll; typedef vector vi; typedef vector vl; typedef pair pii; typedef pair pll; typedef int _loop_int; #define REP(i,n) for(_loop_int i=0;i<(_loop_int)(n);++i) #define FOR(i,a,b) for(_loop_int i=(_loop_int)(a);i<(_loop_int)(b);++i) #define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1;i>=(_loop_int)(a);--i) #define DEBUG(x) cout<<#x<<": "< mat; const int sz = 8*3+2; mat matmul(mat A, mat B){ mat R(sz,vl(sz)); REP(i,sz)REP(j,sz)REP(k,sz)(R[i][j]+=A[i][k]*B[k][j]%MOD)%=MOD; return R; } int main(){ ll n; cin>>n; mat A(sz,vl(sz,0)); REP(from,3*8)REP(to,3*8){ int fs = from/3; int fx = from%3; int ts = to/3; int tx = to%3; if(fx!=tx){ if(fx==0 && tx==2){ // must close if(ts!=0b101)continue; if(fs!=0b100 && fs!=0b001)continue; }else if(fx==0 && tx==1){ // mustn't close if(ts!=0b101)continue; if(fs!=0b111)continue; }else if(fx==2 && tx==0){ // close if(ts!=0b111)continue; if(fs!=0b101)continue; }else if(fx==1 && tx==0){ // erase if(ts!=0b100 && ts!=0b001)continue; if(fs!=0b101)continue; }else{ continue; } }else{ if(fx==1){ if(fs!=0b101)continue; if(ts!=0b101)continue; } if(fx==2){ if(fs!=0b101)continue; if(ts!=0b101)continue; } if(fx==0){ if((fs&ts)==0)continue; if(ts==0b101)continue; } } A[to][from] = 1; } int cone = 3*8; int cans = 3*8+1; A[cans][cans] = 1; A[cone][cone] = 1; REP(to,3*8){ int s = to/3; int x = to%3; // one if(s!=0){ if(x==0 && s!=0b101){ A[to][cone] = 1; }else if(x==2 && s==0b101){ A[to][cone] = 1; } } // ans if(s!=0){ if(x!=2){ A[cans][to] = 1; } } } n++; mat I(sz,vl(sz,0)); REP(i,sz)I[i][i] = 1; while(n>0){ if(n&1)I = matmul(A,I); A = matmul(A,A); n >>= 1; } cout << I[cans][cone] << endl; return 0; }