N=int(input()) ANS=[[0]*N for i in range(N)] if N%2==1: i=N//2 j=0 now=1 for t in range(N): for u in range(N): ANS[j][i]=now now+=1 j-=1 i+=1 j%=N i%=N j+=2 i-=1 j%=N i%=N elif N%4==0: for i in range(N): for j in range(N): if i%4==0 or i%4==3: if j%4==0 or j%4==3: ANS[i][j]=i*N+j+1 else: ANS[i][j]=N*N-(i*N+j) else: if j%4==0 or j%4==3: ANS[i][j]=N*N-(i*N+j) else: ANS[i][j]=i*N+j+1 else: K=N//2 ANS2=[[0]*K for i in range(K)] i=K//2 j=0 now=1 for t in range(K): for u in range(K): ANS2[j][i]=now now+=1 j-=1 i+=1 j%=K i%=K j+=2 i-=1 j%=K i%=K for i in range(K): for j in range(K): ANS2[i][j]=(ANS2[i][j]-1)*4 for i in range(K): for j in range(K): if i==K//2 and j==K//2: ANS[i*2][j*2]=ANS2[i][j]+1 ANS[i*2+1][j*2]=ANS2[i][j]+2 ANS[i*2][j*2+1]=ANS2[i][j]+3 ANS[i*2+1][j*2+1]=ANS2[i][j]+4 elif i<=K//2 or (i==K//2+1 and j==K//2): ANS[i*2][j*2]=ANS2[i][j]+4 ANS[i*2+1][j*2]=ANS2[i][j]+2 ANS[i*2][j*2+1]=ANS2[i][j]+1 ANS[i*2+1][j*2+1]=ANS2[i][j]+3 elif i==K//2+1: ANS[i*2][j*2]=ANS2[i][j]+1 ANS[i*2+1][j*2]=ANS2[i][j]+2 ANS[i*2][j*2+1]=ANS2[i][j]+3 ANS[i*2+1][j*2+1]=ANS2[i][j]+4 else: ANS[i*2][j*2]=ANS2[i][j]+1 ANS[i*2+1][j*2]=ANS2[i][j]+3 ANS[i*2][j*2+1]=ANS2[i][j]+4 ANS[i*2+1][j*2+1]=ANS2[i][j]+2 for i in range(N): print(*ANS[i])