#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #define popcount __builtin_popcount using namespace std; typedef long long int ll; typedef pair P; const ll MOD=1e9+7; vector> matrixmul(int l, int m, int n, vector> a, vector> b){ vector> c(l, vector(n)); for(int i=0; i> matrixpow(int n, vector> a, ll k){ vector> ap=a, ans(n, vector(n)); for(int i=0; i>=1; } return ans; } struct unionfind{ vector par, sz; unionfind() {} unionfind(int n):par(n), sz(n, 1){ for(int i=0; isz[y]) swap(x, y); par[x]=y; sz[y]+=sz[x]; } bool same(int x, int y){ return find(x)==find(y); } int size(int x){ return sz[find(x)]; } }; int dx[4]={1, 0, -1, 0}, dy[4]={0, 1, 0, -1}; const int n1=6; bool used[4][n1]; vector> w; void dfs(vector

v){ int x=v.back().first, y=v.back().second; for(int k=0; k<4; k++){ int x1=x+dx[k], y1=y+dy[k]; if(x1<0 || x1>=4 || y1<0 || y1>=n1) continue; if(used[x1][y1]) continue; v.push_back({x1, y1}); used[x1][y1]=1; if(x1==3 && y1==n1-1){ w.push_back(v); }else{ dfs(v); } used[x1][y1]=0; v.pop_back(); } } vector state; vector> mat; vector v0, v1; void calc(){ used[0][0]=1; vector

vs(1, P(0, 0)); dfs(vs); int c[6000][n1]; for(int l=0; l=4 || y<0 || y>=n1) continue; if(a[j][i] && a[x][y] && (abs(a[x][y]-a[j][i])==1 || abs(a[x][y]-a[j][i])==v.size()-1)){ b[j][i]^=(1< mp; int k=0; for(int j=0; j<4; j++){ if(!a[j][i]) continue; int r=uf.find(i*4+j); if(mp.find(r)==mp.end()){ s[j][i]=k; mp[r]=k; k++; }else{ s[j][i]=mp[r]; } } c[l][i]=0; for(int j=0; j<4; j++){ s[j][i]=s[j][i]*16+b[j][i]; c[l][i]^=(s[j][i]<<(6*j)); } state.push_back(c[l][i]); } } sort(state.begin(), state.end()); state.erase(unique(state.begin(), state.end()), state.end()); int m=state.size(); mat.resize(m); for(int i=0; i>n; if(n==1){ cout<<8<