#!/usr/bin/env python3 # %% import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines # %% import numpy as np N = int(read()) # %% def f(N): if N % 4 == 0: return f0(N) elif N % 4 == 2: return f2(N) else: return f13(N) def f13(N): A = np.zeros((N, N), np.int32) x = 0 y = N // 2 for i in range(1, N * N + 1): if A[x][y]: x += 2 y -= 1 x %= N y %= N A[x, y] = i x -= 1 y += 1 x %= N y %= N return A def f0(N): A = np.arange(N * N).reshape(N, N) A[1::4, 0::4] *= -1 A[1::4, 3::4] *= -1 A[2::4, 0::4] *= -1 A[2::4, 3::4] *= -1 A[0::4, 1::4] *= -1 A[0::4, 2::4] *= -1 A[3::4, 1::4] *= -1 A[3::4, 2::4] *= - 1 A[A < 0] += N * N - 1 A += 1 return A def f2(N): A = f(N // 2) A = np.repeat(A, 2, axis=0).repeat(2, axis=1) A = (A - 1) * 4 n = N // 4 # L-type A[:2 * n + 2:2, ::2] += 4 A[:2 * n + 2:2, 1::2] += 1 A[1:2 * n + 2:2, ::2] += 2 A[1: 2 * n + 2:2, 1::2] += 3 # U-type A[2 * n + 2, ::2] += 1 A[2 * n + 2, 1::2] += 4 A[2 * n + 3, ::2] += 2 A[2 * n + 3, 1::2] += 3 # X-type A[2 * n + 4::2, ::2] += 1 A[2 * n + 4::2, 1::2] += 4 A[2 * n + 5::2, ::2] += 3 A[2 * n + 5::2, 1::2] += 2 # modify center A[2 * n, 2 * n] -= 3 A[2 * n, 2 * n + 1] += 3 A[2 * n + 2, 2 * n] += 3 A[2 * n + 2, 2 * n + 1] -= 3 return A # %% A = f(N) print('\n'.join(' '.join(row) for row in A.astype(str)))