import java.io.*; import java.util.*; class Main { static final long MOD=1000000007; static long[][]matMul(long[][]a,long[][]b){ int n=a.length; int m=b.length; int l=b[0].length; long[][]ret=new long[n][l]; for(int i=0;i= 0; --i) { prod = matMul(prod,prod); if ((exponent & 1L << i) != 0) { prod =matMul(prod,x); } } return prod; } public static void main(String[] args) { MyScanner sc = new MyScanner(); out = new PrintWriter(new BufferedOutputStream(System.out)); long n=sc.nextLong(); long[][]trans=new long[27][27]; int valid=0x60b; for(int i=0;i<27;++i){ int[]a=new int[3]; a[0]=i%3; a[1]=i/3%3; a[2]=i/9; for(int j=0;j<8;++j){ boolean ok=true; for(int k=0;k<3;++k){ if((j&1<=1; else ok&=a[k]<=1; } if(!ok)continue; int pb=j; for(int k=0;k<3;++k) if(a[k]==0){ if((pb&(1<=2)throw new Error(); nxt+=(a[k]+1)*pw[k]; } trans[i][nxt]+=1; if((j&3)==0){ int pn=(j&1<<2)==0?(a[2]+1)*9:0; trans[i][pn]+=1; } if((j&6)==0){ int pn=(j&1<<0)==0?(a[0]+1)*1:0; trans[i][pn]+=1; } } } long[][]pw=powerMat(trans,n); long ans=0; for(int i=0;i<27;++i) if((valid&1<