import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); int[][] ret = new int[n][n]; if (n % 2 == 1) { msOdd(ret); } else if (n % 4 == 0) { ms4n(ret); } else if (n % 4 == 2) { ms4np2(ret); } for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { System.out.printf("%d ", ret[j][i]); } } sc.close(); } private static void ms4np2(int[][] ret) { int n = ret[0].length; int nn = (n - 2) / 4; int[][] ret2 = new int[2 * nn + 1][2 * nn + 1]; msOdd(ret2); for (int i = 0; i < ret2[0].length; i++) { for (int j = 0; j < ret2[0].length; j++) { ret2[i][j] = (ret2[i][j] - 1) * 4; } } int[] L = {4, 1, 2, 3}; int[] U = {1, 4, 2, 3}; int[] X = {1, 4, 3, 2}; for (int i = 0; i < 2 * nn + 1; i++) { for (int j = 0; j < 2 * nn + 1; j++) { if (j < nn || (j == nn + 1 && i == nn) || (j == nn && i != nn)) { ret[i * 2][j * 2] = ret2[i][j] + L[0]; ret[i * 2 + 1][j * 2] = ret2[i][j] + L[1]; ret[i * 2][j * 2 + 1] = ret2[i][j] + L[2]; ret[i * 2 + 1][j * 2 + 1] = ret2[i][j] + L[3]; } else if ((j == nn && i == nn) || (j == nn + 1 && i != nn)) { ret[i * 2][j * 2] = ret2[i][j] + U[0]; ret[i * 2 + 1][j * 2] = ret2[i][j] + U[1]; ret[i * 2][j * 2 + 1] = ret2[i][j] + U[2]; ret[i * 2 + 1][j * 2 + 1] = ret2[i][j] + U[3]; } else if (j > nn) { ret[i * 2][j * 2] = ret2[i][j] + X[0]; ret[i * 2 + 1][j * 2] = ret2[i][j] + X[1]; ret[i * 2][j * 2 + 1] = ret2[i][j] + X[2]; ret[i * 2 + 1][j * 2 + 1] = ret2[i][j] + X[3]; } } } } private static void ms4n(int[][] ret) { int n = ret[0].length; for (int i = 1; i <= n * n; i++) { int x = (i - 1) % n; int y = (i - 1) / n; if ((x % 4 == 0 || x % 4 == 3) && (y % 4 == 0 || y % 4 == 3)) { ret[x][y] = i; } else if ((x % 4 == 1 || x % 4 == 2) && (y % 4 == 1 || y % 4 == 2)) { ret[x][y] = i; } } for (int i = 1; i <= n * n; i++) { int x = n - 1 - (i - 1) % n; int y = n - 1 - (i - 1) / n; if (ret[x][y] == 0) { ret[x][y] = i; } } } private static void msOdd(int[][] ret) { int n = ret[0].length; int x = n / 2; int y = 0; for (int i = 1; i <= n * n; i++) { ret[x][y] = i; int tmpx = x + 1; int tmpy = y - 1; if (tmpx >= n) { tmpx = 0; } if (tmpy < 0) { tmpy = n - 1; } if (ret[tmpx][tmpy] == 0) { x = tmpx; y = tmpy; ret[x][y] = i; } else { y++; if (y >= n) { y = 0; } } } } }