ll@N;Mint A[N+1][3]{},t=2;rep[A,i](a,N){char@s;rep(c,3)c[a+3]=s%3==c?a[c]:a[3-c-s%3]+t**i;}wt(A[N][2]);