ll@n,@m,z=n*m,i,d,a[m][n],b[5]; rep(j,z){ ll@x,@y; a[y-1][x-1]=j; } rep(y,m){ rep(x,n-3){ b[0..4]=a[y][(x..)%n]; sortA(5,b); i=4; z