#include #include using namespace std; int n,k; int lc0[26],lc[26],li[26][500]; char a0[64][64],aa[64][64]; int ra[500],rb[500],rc[500],rd[500]; int ra1[500],rb1[500],rc1[500],rd1[500]; int score0,score,score1; void reg(int l,int a,int c,int b, int d){ int i=li[l][--lc[l]]; ra[i]=a; rb[i]=b; rc[i]=c; rd[i]=d; for(int y=a;y<=c;++y){ for(int x=b;x<=d;++x){ aa[y][x]^=1; } } } void solve(int ux,int uy,int vx,int vy){ { int ov=vx+vy<0?n+1:0; int ou=ux+uy<0?n+1:0; for(int y=1;y<=n;++y){ for(int x=1;x<=n;++x){ aa[y][x]=a0[ov+vx*x+vy*y][ou+ux*x+uy*y]; } } } for(int i=1;i<=25;++i){ lc[i]=lc0[i]; } score=score0; { bool m; do{ m=false; for(int y=2;y<=n-1;++y){ int bl=0,bx=0; int bv=450; for(int x=1;x<=n;++x){ int v=0; for(int l=0;l<25&&x+l<=n;++l){ v+= aa[y][x+l]!=aa[y-1][x+l] ? 100 : -101; v+= aa[y][x+l]!=aa[y+1][x+l] ? 100 : -99; if(bv<=v&&lc[l+1]){ bv=v; bx=x; bl=l+1; } } } if(bx){ reg(bl,y,y,bx,bx+bl-1); m=true; } } }while(m); } for(int z=1;z<=n;++z){ for(int x=1;x<=n;++x) { if(aa[z][x]&&(z==n||aa[z+1][x])){ int bl=0,bv=0,v=0; for(int l=0;l<25&&z+l<=n;++l){ v+=aa[z+l][x]*6-1; int v1=v; if(aa[z+l][x]&&!aa[z+l+1][x]) v1+=200; if(!aa[z+l][x]&&aa[z+l+1][x]) v1+=181; if(bv<=v1&&lc[l+1]){ bv=v1; bl=l+1; } } if(bl){ reg(bl,z,z+bl-1,x,x); } } } } for(int bl=1;bl<=25;++bl){ while(lc[bl]){ int by=1,bx=1,bv=0; for(int y=1;y<=n;++y){ int v=0; for(int x=1;x<=bl;++x){ v+=aa[y][x]; } for(int x=1;x+bl-1<=n;++x){ if(bv0?ra[i]:vy<0?n+1-rc[i]:vx>0?rb[i]:vx<0?n+1-rd[i]:0; rb1[i]=uy>0?ra[i]:uy<0?n+1-rc[i]:ux>0?rb[i]:ux<0?n+1-rd[i]:0; rc1[i]=vy>0?rc[i]:vy<0?n+1-ra[i]:vx>0?rd[i]:vx<0?n+1-rb[i]:0; rd1[i]=uy>0?rc[i]:uy<0?n+1-ra[i]:ux>0?rd[i]:ux<0?n+1-rb[i]:0; } } } main(){ scanf("%d%d",&n,&k); for(int i=0;i