def solve(): N = int(input()) if N & 1: magic = solve_odd(N) elif N % 4 == 0: magic = solve_4(N) else: magic = solve_LUX(N) print_mat(magic) def print_mat(magic): for row in magic: print(' '.join(map(str,row))) def solve_odd(N): magic = [[0] * N for i in range(N)] mid = N // 2 num = 1 x = 0 y = mid while num <= N * N: while magic[x][y]: x = (x + 2) % N y = (y - 1) % N magic[x][y] = num num += 1 x = (x - 1) % N y = (y + 1) % N return magic def solve_4(N): magic = [[0] * N for i in range(N)] num = 1 for x in range(N): for y in range(N): if is_diagonal(x, y): magic[x][y] = num num += 1 num = 1 for x in range(N-1, -1, -1): for y in range(N-1, -1, -1): if not magic[x][y]: magic[x][y] = num num += 1 return magic def is_diagonal(x, y): x %= 4 y %= 4 return x == y or x + y == 3 def solve_LUX(N): seed = solve_odd(N//2) LUX = [[0] * (N//2) for i in range(1 + N//4)] LUX.extend([[1] * (N//2) for i in range(N//4)]) LUX.append([2] * (N//2)) LUX[N//4][N//4] = 1 LUX[1 + N//4][N//4] = 0 L = [[4, 1], [2, 3]] U = [[1, 4], [2, 3]] X = [[1, 4], [3, 2]] LUXmat = [L, U, X] magic = [[0] * N for i in range(N)] for x in range(N//2): for y in range(N//2): val = (seed[x][y] - 1) * 4 idx = LUX[x][y] for dx, dy in [(0, 0), (0, 1), (1, 0), (1, 1)]: magic[2 * x + dx][2 * y + dy] = LUXmat[idx][dx][dy] + val return magic solve()