ll n,h[4][3]; char a[5][10][10],b[10][10]; bool f(ll z){ if(z==0){ return memcmp(a,b,100)==0; } --z; rep(p,n){ rep(y,n){ memcpy(a[z][a[z+1][p][y]],a[z+1][y],10); } if(f(z)){ h[z][0]=1; h[z][1]=p; return true; } } rep(p,n){ rep(y,n){ rep(x,n){ a[z][y][a[z+1][x][p]]=a[z+1][y][x]; } } if(f(z)){ h[z][0]=0; h[z][1]=p; return true; } } return false; } { ll k; rd(n,k); rep(y,n){ rep(x,n){ int@v; a[k][y][x]=v-1; } } rep(y,n){ rep(x,n){ int@v; b[y][x]=v-1; } } f(k); ll m=0; IntMap c(n); rep(z,k){ if(h[z][0]){ rep(x,n){ c[x]=a[z+1][h[z][1]][x]; } }else{ rep(y,n){ c[y]=a[z+1][y][h[z][1]]; } } ll n=c.calcCycle(); m+=h[z][2]=lcm[i,0,n](c.cycleLen[i])-1; } wt(m); rep(z,k){ ll p=h[z][1]; rep(i,h[z][2]){ if(h[z][0]){ p=a[z+1][h[z][1]][p]; }else{ p=a[z+1][p][h[z][1]]; } wt(h[z][0]?'R':'C',p+1); } } }