#include #define F(i,n)for(int i=n;i--;) int n,m,d[200][202][100],a,e,z; int main(){ std::cin>>n>>m;a=z=2*n; F(k,m)F(i,n)F(j,n)(std::cin>>e),d[k][i][j]=d[k][n+j][i]=d[k][i-j?0:z][j]=d[k][n-i-j-1?0:z+1][j]=e; F(k,m)F(i,z+2)std::sort(d[k][i],d[k][i]+n); F(k,m)F(l,k)F(i,z+2)F(j,z+2)F(x,(e=z,n))F(y,n)a=(e-=d[k][i][x]==d[l][j][y])