Find an n × n matrix with different numbers from 1 to n^2, so the sum in each row, column and both main diagonals are odd.


-----Input-----

The only line contains odd integer n (1 ≤ n ≤ 49).


-----Output-----

Print n lines with n integers. All the integers should be different and from 1 to n^2. The sum in each row, column and both main diagonals should be odd.


-----Examples-----
Input
1

Output
1

Input
3

Output
2 1 4
3 5 7
6 9 8

Difficulty: MEDIUM
Tags: Mathematics

Constructive algorithms

Starter code:

Solutions:
n = int(input())
o = [i for i in range(1, n ** 2 + 1, 2)]
e = [i for i in range(2, n ** 2, 2)]
x = [[0 for i in range(n)] for j in range(n)]
for i in range(n):
	y = n // 2
	if y - i >= 0:
		for j in range(y - i, y + i + 1):
			x[i][j] = o.pop()
	else:
		for j in range(y + i - n + 1, y - i + n):
			x[i][j] = o.pop()
	for j in range(n):
		if x[i][j] == 0:
			x[i][j] = e.pop()
for i in range(n):
	print(*x[i])


import sys
from bisect import bisect_right as rb
from collections import deque
from queue import PriorityQueue
input_ = lambda : sys.stdin.readline().strip('\r\n')
ii = lambda : int(input_())
il = lambda : list(map(int, input_().split()))
ilf = lambda : list(map(float, input_().split()))
ip = lambda : input_()
fi = lambda : float(input_())
ap = lambda ab, bc, cd: ab[bc].append(cd)
li = lambda : list(input_())
pr = lambda x: print(x)
prinT = lambda x: print(x)
f = lambda : sys.stdout.flush()
inv = lambda x: pow(x, mod - 2, mod)
mod = 10 ** 9 + 7
n = ii()
b = [[0 for i in range(n)] for j in range(n)]
x = n // 2
y = n - 1
for i in range(n * n):
	b[x][y] = i + 1
	x1 = (x + 1) % n
	y1 = (y + 1) % n
	if b[x1][y1] != 0:
		x1 = x
		if y == 0:
			y1 = n - 1
		else:
			y1 = y - 1
	x = x1
	y = y1
for i in b:
	print(*i)


n = int(input())
r = [[0] * n for i in range(n)]
c = n // 2
cur = 1
for i in range(n):
	r[c][i] = cur
	cur += 2
for i in range(n):
	if i != c:
		r[i][c] = cur
		cur += 2
if cur < n * n:
	for i in range(1, c + 1):
		for j in range(1, c + 1):
			r[c - i][c + j] = cur
			cur += 2
			r[c - i][c - j] = cur
			cur += 2
			r[c + i][c + j] = cur
			cur += 2
			r[c + i][c - j] = cur
			cur += 2
			if cur >= n * n:
				break
		if cur >= n * n:
			break
cur = 2
for i in range(n):
	for j in range(n):
		if r[i][j] == 0:
			r[i][j] = cur
			cur += 2
for i in range(n):
	print(str.join(' ', map(str, r[i])))


n = int(input())
i = j = n >> 1
a = 1
b = 2
for _ in range(n):
	for y in range(n):
		if min(i, j) <= y <= max(i, j):
			c = a
			a += 2
		else:
			c = b
			b += 2
		print(c, end=' ' if n - 1 > y else '\n')
	i -= 1
	j += 1
	if 0 > i:
		(i, j) = (n - 2, 1)


n = int(input())
i = n >> 1
a = 1
b = 2
for x in range(n):
	l = abs(x - i)
	r = n - l
	for y in range(n):
		if l <= y < r:
			c = a
			a += 2
		else:
			c = b
			b += 2
		print(c, end=' ' if n - 1 > y else '\n')


n = int(input())
lst = [[0 for _ in range(n)] for _ in range(n)]
x = n // 2
y = 0
for i in range(1, n * n + 1):
	lst[y % n][x % n] = i
	x += 1
	y -= 1
	if lst[y % n][x % n] != 0:
		x -= 1
		y += 2
for i in lst:
	for j in i:
		print(j, end=' ')
	print()


n = int(input())
a = 2
b = 1
for i in range(n):
	for j in range(n):
		if j >= i and j != n // 2 and (j <= n - 1 - i):
			print(a, end=' ')
			a = a + 2
		elif j >= n - 1 - i and j != n // 2 and (j <= i):
			print(a, end=' ')
			a = a + 2
		else:
			print(b, end=' ')
			b = b + 2
	print()


n = int(input())
a = [[0] * n for _ in range(n)]
odds = iter(range(1, n ** 2 + 1, 2))
evens = iter(range(2, n ** 2 + 1, 2))
for i in range((n + 1) // 2):
	for j in range(n):
		a[i][j] = next(odds) if i + j >= n // 2 >= j - i else next(evens)
for i in range((n + 1) // 2, n):
	for j in range(n):
		a[i][j] = next(odds) if i - j <= n // 2 and i + j <= n - 1 + n // 2 else next(evens)
for i in range(n):
	print(*a[i])


n = int(input())
mx = [[0 for x in range(n)] for y in range(n)]
xx = 0
yy = (n - 1) // 2
for i in range(1, n * n + 1):
	if mx[xx][yy] == 0:
		mx[xx][yy] = i
	else:
		yy = (yy - 1) % n
		xx = (xx + 2) % n
		mx[xx][yy] = i
	yy = (yy + 1) % n
	xx = (xx - 1) % n
for i in range(n):
	for j in range(n - 1):
		print(mx[i][j], end=' ')
	print(mx[i][n - 1])


from collections import defaultdict
import sys
n = int(input())
table = [[0] * 100 for _ in range(100)]
(i, j) = (0, n // 2)
for num in range(1, n * n + 1):
	table[i][j] = num
	if table[(i - 1 + n) % n][(j + 1 + n) % n] == 0:
		i = (i - 1 + n) % n
		j = (j + 1 + n) % n
	else:
		i = (i + 1 + n) % n
for i in range(n):
	print(' '.join([str(j) for j in table[i][:n]]))


n = int(input())
A = [[0 for i in range(n)] for i in range(n)]
c = n // 2
odds = (n * n + 1) // 2
for i in range(n):
	for j in range(n):
		if abs(i - c) + abs(j - c) <= c:
			A[i][j] = 1
(o, e) = (1, 2)
for i in range(n):
	for j in range(n):
		if A[i][j] == 0:
			A[i][j] = e
			e += 2
		else:
			A[i][j] = o
			o += 2
for row in A:
	print(*row)


import math
import re
n = int(input())
arr = [[0] * n for i in range(n)]
a = [1] + [1 + 2 * i for i in range(1, n * n // 2 + 1)]
b = [2 * i for i in range(1, n * n // 2 + 1)]
k = 0
for i in range(n // 2 + 1):
	for j in range(n // 2 - i, n // 2 + i + 1):
		arr[i][j] = a[k]
		k += 1
for i in range(n // 2):
	for j in range(i + 1, n - i - 1):
		arr[n // 2 + 1 + i][j] = a[k]
		k += 1
k = 0
for i in range(n):
	for j in range(n):
		if arr[i][j] == 0:
			arr[i][j] = b[k]
			k += 1
for i in range(n):
	print(' '.join(list(map(str, arr[i]))))


n = int(input())
(c, o, e) = (n // 2, 1, 2)
for i in range(n):
	for j in range(n):
		if abs(i - c) + abs(j - c) <= c:
			print(o, end=' ')
			o += 2
		else:
			print(e, end=' ')
			e += 2
	print('')


n = int(input())
it = n // 2
(n1, n2) = (1, 2)
A = []
for i in range(n):
	A.append([])
	for j in range(n):
		if j >= it and j <= n - it - 1:
			A[i].append(n1)
			n1 += 2
		else:
			A[i].append(n2)
			n2 += 2
	if i < n / 2 - 1:
		it -= 1
	else:
		it += 1
for i in A:
	for j in i:
		print(j, end=' ')
	print()


size = int(input())
square = [[0 for j in range(2 * size - 1)] for i in range(2 * size - 1)]
counter = 1
dj = 0
for i in range(size):
	di = size - 1
	for j in range(size):
		square[i + di][j + dj] = counter
		counter += 1
		di -= 1
	dj += 1
for j in range(size // 2):
	for i in range(2 * size - 1):
		square[i][j - size // 2 * 2] = square[i][j] or square[i][j - size // 2 * 2]
		square[i][j] = 0
		square[i][j + size // 2] = square[i][j - size // 2] or square[i][j + size // 2]
		square[i][j - size // 2] = 0
		square[j - size // 2 * 2][i] = square[j][i] or square[j - size // 2 * 2][i]
		square[j][i] = 0
		square[j + size // 2][i] = square[j - size // 2][i] or square[j + size // 2][i]
		square[j - size // 2][i] = 0
square = [square[i][size // 2:2 * size - 1 - size // 2] for i in range(size // 2, 2 * size - 1 - size // 2)]
for i in range(len(square)):
	for j in range(len(square[i])):
		print(square[i][j], end=' ')
	print()


n = int(input())
if n == 1:
	print(1)
	exit()
odd = 1
evn = 2
for x in range(n):
	for y in range(n):
		x1 = min(x, n - 1 - x)
		if y < (n - 1) / 2 - x1 or y > (n - 1) / 2 + x1:
			print(evn, end=' ')
			evn += 2
		else:
			print(odd, end=' ')
			odd += 2
	print()


UNFILLED_CELL = 0

def get_blank_matrix(n):
	matrix = []
	for i in range(n):
		row = []
		for j in range(n):
			row.append(UNFILLED_CELL)
		matrix.append(row)
	return matrix

def generate_matrix(n):
	matrix = get_blank_matrix(n)
	x = n // 2
	y = 0
	max_number = n ** 2
	current_number = 1
	while current_number != max_number + 1:
		matrix[y][x] = current_number
		next_x = x + 1
		next_y = y - 1
		if next_y == -1:
			next_y = n - 1
		if next_x == n:
			next_x = 0
		if matrix[next_y][next_x] != UNFILLED_CELL:
			next_y = y + 1
			next_x = x
		x = next_x
		y = next_y
		current_number += 1
	return matrix

def print_matrix(matrix):
	delimeter = ' '
	for row in matrix:
		print(delimeter.join(map(str, row)))

def main():
	n = int(input())
	matrix = generate_matrix(n)
	print_matrix(matrix)
main()


def m(n):
	for r in range(1, n + 1):
		print(' '.join(('%*i' % (len(str(n ** 2)), cell) for cell in (n * ((r + col - 1 + n // 2) % n) + (r + 2 * col - 2) % n + 1 for col in range(1, n + 1)))))
n = int(input())
m(n)


import sys
n = int(input())
matrix = [[0] * n for _ in range(n)]
num = 1
for (i, s, t) in zip(range(n), range(n // 2, -1, -1), range(n // 2 + 1, n + 1)):
	for j in range(s, t):
		matrix[i][j] = num
		num += 2
for (i, s, t) in zip(range(n // 2 + 1, n), range(1, n), range(n - 1, -1, -1)):
	for j in range(s, t):
		matrix[i][j] = num
		num += 2
num = 2
for i in range(n):
	for j in range(n):
		if matrix[i][j] == 0:
			matrix[i][j] = num
			num += 2
for row in matrix:
	print(*row)


n = int(input())
matrix = [[0 for i in range(n)] for j in range(n)]
i = n // 2
j = n - 1
o = 1
while o <= n * n:
	if i == -1 and j == n:
		j = n - 2
		i = 0
	else:
		if j == n:
			j = 0
		if i < 0:
			i = n - 1
	if matrix[i][j]:
		j -= 2
		i += 1
		continue
	else:
		matrix[i][j] = str(o)
		o += 1
	j += 1
	i -= 1
for i in range(n):
	print(' '.join(matrix[i]))


n = int(input())
l = [[0 for i in range(n)] for j in range(n)]
r = 1
for i in range(n):
	if i <= int(n / 2):
		for j in range(int(n / 2) - i, int(n / 2) + i + 1):
			l[i][j] = r
			r = r + 2
	else:
		for j in range(i - int(n / 2), n - (i - int(n / 2))):
			l[i][j] = r
			r = r + 2
r = 2
for i in range(n):
	for j in range(n):
		if l[i][j] == 0:
			l[i][j] = r
			r = r + 2
for i in range(n):
	print(*l[i])


n = int(input())
s = [i for i in range(1, n ** 2 + 1)]
Ans = [[0] * n for i in range(n)]
if n == 1:
	print(1)
else:
	Centre = n // 2
	Ans[Centre][Centre] = 1
	line = 1
	while line < n:
		s = [i for i in range(line ** 2 + 1, (line + 2) ** 2 + 1)]
		line += 2
		if Ans[Centre - line // 2 + 1][Centre - line // 2 + 1] % 2 == 0:
			s = s[1:] + s[:1]
		ind = 0
		for j in range(Centre - line // 2, Centre + 1 + line // 2):
			Ans[Centre - line // 2][j] = s[ind]
			ind += 1
		for i in range(Centre - line // 2 + 1, Centre + 1 + line // 2):
			Ans[i][Centre + line // 2] = s[ind]
			ind += 1
		for j in range(Centre + line // 2 - 1, Centre - 1 - line // 2, -1):
			Ans[Centre + line // 2][j] = s[ind]
			ind += 1
		for i in range(Centre + line // 2 - 1, Centre - line // 2, -1):
			Ans[i][Centre - line // 2] = s[ind]
			ind += 1
	for i in range(n):
		print(' '.join(map(str, Ans[i])))


__author__ = 'Think'
n = int(input())
parity = (n - 1) // 2 % 2

def cell(r, c):
	r = min(r, n + 1 - r)
	c = min(c, n + 1 - c)
	id = max(r, c)
	return (id - parity) % 2
odd = -1
even = 0

def get(par, odd, even):
	if par == 0:
		even += 2
		return (even, odd, even)
	if par == 1:
		odd += 2
		return (odd, odd, even)
for r in range(1, n + 1):
	for c in range(1, n + 1):
		(val, odd, even) = get(cell(r, c), odd, even)
		print(val, end='')
		if c != n:
			print(' ', end='')
	print()


from math import *
n = int(input())
nn = 1
nc = 2
a = []
for i in range(n):
	a.append([0] * n)
	for q in range(n):
		if abs((n - 1) // 2 - i) + abs((n - 1) // 2 - q) <= (n - 1) // 2:
			a[i][q] = nn
			nn += 2
		else:
			a[i][q] = nc
			nc += 2
for i in range(n):
	print(*a[i])


n = int(input())
ans = [[0 for i in range(n)] for j in range(n)]
start = 0
od = 1
do = n
for i in range(n // 2, n):
	for j in range(start, start + do):
		ans[i][j] = od
		od += 2
	start += 1
	do -= 2
start = n // 2
do = 1
for i in range(0, n // 2):
	for j in range(start, start + do):
		ans[i][j] = od
		od += 2
	start -= 1
	do += 2
ev = 2
for i in ans:
	for j in i:
		if j:
			print(j, end=' ')
		else:
			print(ev, end=' ')
			ev += 2
	print('')


n = int(input())
a = [[0] * n for i in range(n)]
cur = 1
sum = 0
x = n // 2
for i in range(n):
	a[x][i] = cur
	cur += 2
while x != 0:
	x -= 1
	sum += 1
	for i in range(sum, n - sum):
		a[x][i] = cur
		cur += 2
x = n // 2
sum = 0
while x != n - 1:
	x += 1
	sum += 1
	for i in range(sum, n - sum):
		a[x][i] = cur
		cur += 2
cur = 2
for i in range(n):
	for j in range(n):
		if a[i][j] == 0:
			a[i][j] = cur
			cur += 2
	print(' '.join(map(str, a[i])))


n = int(input())
used = set()
odd = 1
even = 2
data = [[0] * n for i in range(n)]
rombs = n // 2
rombe = n // 2
for x in range(n):
	for y in range(n):
		if rombs <= y <= rombe:
			data[y][x] = str(odd)
			odd += 2
		else:
			data[y][x] = str(even)
			even += 2
	if x < n // 2:
		rombs -= 1
		rombe += 1
	else:
		rombs += 1
		rombe -= 1
for i in data:
	print(' '.join(i))


n = int(input())
mat = [['-1'] * n for a in range(n)]
mat[0][n // 2] = '1'
pos = [0, n // 2]
for num in range(2, n ** 2 + 1):
	if pos[0] - 1 < 0 and pos[1] + 1 >= n:
		pos[0] += 1
	elif pos[0] - 1 < 0:
		pos[0] = n - 1
		pos[1] += 1
	elif pos[1] + 1 >= n:
		pos[0] -= 1
		pos[1] = 0
	else:
		pos[0] -= 1
		pos[1] += 1
		if mat[pos[0]][pos[1]] != '-1':
			pos[0] += 2
			pos[1] -= 1
	if mat[pos[0]][pos[1]] == '-1':
		mat[pos[0]][pos[1]] = str(num)
for a in range(n):
	print(' '.join(mat[a]))


n = int(input())
from collections import deque
odd = deque([i for i in range(1, n * n + 1) if i % 2 == 1])
even = deque([i for i in range(1, n * n + 1) if i % 2 == 0])
ans = [[] for _ in range(n)]

def populate(r, o):
	k = (n - o) // 2
	for _ in range(k):
		ans[r].append(even.popleft())
	for _ in range(o):
		ans[r].append(odd.popleft())
	for _ in range(k):
		ans[r].append(even.popleft())
for i in range(n // 2):
	o = 2 * i + 1
	populate(i, o)
	populate(n - 1 - i, o)
populate(n // 2, n)
for row in ans:
	print(*row)


n = int(input())
g = [[0 for _ in range(n // 2 + 1)] for _ in range(n // 2 + 1)]
(e, o) = (list(filter(lambda x: x % 2 == 0, range(1, n * n + 1))), list(filter(lambda x: x % 2 == 1, range(1, n * n + 1))))
for k in range(n, 0, -4):
	(x, y) = (k // 2, 0)
	for _ in range(k // 2):
		g[x][y] = 1
		y += 1
	for _ in range(k - k // 2):
		g[x][y] = 1
		x -= 1
for i in range(n // 2 + 1):
	g[i] = g[i] + g[i][:-1][::-1]
for i in range(n // 2 - 1, -1, -1):
	g.append(list(g[i]))
(ie, io) = (0, 0)
for i in range(n):
	for j in range(n):
		if g[i][j] == 1:
			g[i][j] = o[io]
			io += 1
		else:
			g[i][j] = e[ie]
			ie += 1
for r in range(n):
	print(' '.join(map(str, g[r])))


def ind(i, j, len):
	mid = int(len / 2)
	if mid == i or mid == j:
		return 1
	if i < mid:
		if j < mid:
			if j >= i:
				return 0
			else:
				return 1
		elif i + j >= len:
			return 1
		else:
			return 0
	elif j < mid:
		if i + j + 1 >= len:
			return 0
		else:
			return 1
	elif j > i:
		return 1
	else:
		return 0
len = int(input())
evn = 1
odd = 2
for i in range(len):
	str1 = ''
	for j in range(len):
		if ind(i, j, len) == 1:
			str1 += str(evn) + ' '
			evn += 2
		else:
			str1 += str(odd) + ' '
			odd += 2
	print(str1)


n = int(input())
odd = []
even = []
for i in range(1, n ** 2 + 1):
	if i % 2:
		odd.append(i)
	else:
		even.append(i)
a = [[0] * n for i in range(n)]
L = R = n // 2
flag = False
for i in range(n):
	for j in range(L, R + 1):
		a[i][j] = odd.pop()
	if flag or L == 0:
		flag = True
		L += 1
		R -= 1
	else:
		L -= 1
		R += 1
for i in range(n):
	for j in range(n):
		if not a[i][j]:
			a[i][j] = even.pop()
[print(*i) for i in a]


n = int(input())
magic_constant = n * (n ** 2 + 1) / 2
(x, y) = (n // 2, 0)
cur_number = 1
field = [[-1 for i in range(n)] for j in range(n)]
for i in range(n ** 2):
	field[y][x] = cur_number
	cur_number += 1
	if field[(y - 1) % n][(x + 1) % n] != -1:
		y = (y + 1) % n
	else:
		x = (x + 1) % n
		y = (y - 1) % n
for i in field:
	print(*i)


n = int(input())

def rec(x):
	if x == 1:
		return [[1]]
	else:
		tmp = [[0] * x for i in range(x)]
		ins = rec(x - 2)
		for i in range(0, x):
			tmp[0][i] = i % 2
			tmp[x - 1][i] = i % 2
			tmp[i][0] = i % 2
			tmp[i][x - 1] = i % 2
		sum = 0
		for i in tmp[0]:
			sum += i
		if sum % 2 == 0:
			for i in range(0, x):
				tmp[0][i] = 1 - i % 2
				tmp[x - 1][i] = 1 - i % 2
				tmp[i][0] = 1 - i % 2
				tmp[i][x - 1] = 1 - i % 2
		for i in range(1, x - 1):
			for j in range(1, x - 1):
				tmp[i][j] = ins[i - 1][j - 1]
		return tmp

def extract_same(ch):
	global num
	for i in num:
		if i % 2 == ch:
			result = i
			num.remove(i)
			return result
num = {i for i in range(1, n ** 2 + 1)}
mask = rec(n)
for i in range(0, n):
	for j in range(0, n):
		print(extract_same(mask[i][j]), end=' ')
	print(end='\n')


sz = int(input())
odd_no = 1
even_no = 2
for z in range(sz):
	for q in range(sz):
		if z + q >= sz // 2 and z + q <= sz // 2 + sz - 1 and (q - z <= sz // 2) and (z - q <= sz // 2):
			print(odd_no, end=' ')
			odd_no += 2
		else:
			print(even_no, end=' ')
			even_no += 2
	print('')


n = int(input())
mt = [[0 for col in range(n)] for row in range(n)]
r = 0
c = (n - 1) // 2
x = 1
while x < n * n + 1:
	mt[r][c] = x
	if not x % n:
		r = (r + 1) % n
	else:
		r = (r - 1 + n) % n
		c = (c + 1) % n
	x += 1
for i in range(n):
	for j in range(n):
		print('%s%d' % (' ' if j else '', mt[i][j]), end='')
	print()


n = int(input())
matrice = [[0] * n for i in range(n)]
milieu = n // 2
modulo = milieu % 2
matrice[milieu][milieu] = 1
chiffreImpair = 1
chiffrePair = 2
for lig in range(n):
	for col in range(n):
		retourCol = n - col - 1
		retourLig = n - lig - 1
		supGauche = max(lig, col)
		supDroite = max(lig, retourCol)
		infGauche = max(retourLig, col)
		infDroite = max(retourLig, retourCol)
		minimum = min(supGauche, supDroite, infGauche, infDroite)
		if minimum % 2 == modulo:
			matrice[lig][col] = chiffreImpair
			chiffreImpair += 2
		else:
			matrice[lig][col] = chiffrePair
			chiffrePair += 2
for ligne in matrice:
	print(*ligne)


n = int(input())
ll = []
for i in range(n):
	ll.append([0] * n)
ll[n // 2][n // 2] = 1
if n > 1:
	ll[n // 2 - 1][n // 2 - 1] = 2
	ll[n // 2 - 1][n // 2] = 3
	ll[n // 2 - 1][n // 2 + 1] = 6
	ll[n // 2][n // 2 - 1] = 7
	ll[n // 2][n // 2 + 1] = 9
	ll[n // 2 + 1][n // 2 - 1] = 8
	ll[n // 2 + 1][n // 2] = 5
	ll[n // 2 + 1][n // 2 + 1] = 4
q = 9
nq = 25
nqq = 5
for i in range(n // 2 - 2, -1, -1):
	ll[i][i] = q + 1
	ll[n - 1 - i][n - 1 - i] = q + 3
	ll[i][n - 1 - i] = q + 5
	ll[n - 1 - i][i] = q + 7
	q += 7
	j = i + 1
	while q < nq:
		ll[i][j] = q + 2
		ll[n - 1 - i][j] = q + 4
		q += 4
		j += 1
	q = (nqq - 2) ** 2
	ll[i][n - 2 - i] = q + 2
	ll[n - 1 - i][n - 2 - i] = q + 4
	q += 4
	j = i + 1
	while q < nq:
		ll[j][i] = q + 2
		ll[j][n - 1 - i] = q + 4
		q += 4
		j += 1
	nqq += 2
	nq = nqq ** 2
for i in range(n):
	print(' '.join(map(str, ll[i])))


from sys import exit
n = int(input())
if n == 1:
	print(1)
	exit(0)
odd = iter(range(1, n * n + 1, 2))
even = iter(range(2, n * n + 1, 2))
result = []
for _ in range(n):
	result.append([None] * n)
for i in range(n):
	result[n // 2][i] = next(odd)
offset = 1
length = n - 2
for i in range(n // 2):
	for j in range(offset, offset + length):
		result[i][j] = next(odd)
		result[-1 - i][j] = next(odd)
	offset += 1
	length -= 2
for i in range(n):
	for j in range(n):
		if result[i][j] is None:
			result[i][j] = next(even)
for i in range(n):
	print(' '.join(map(str, result[i])))


n = int(input())
evenNums = list(range(2, n ** 2 + 1, 2))
oddNums = list(range(1, n ** 2 + 1, 2))
for i in range(n):
	outList = []
	if i > n // 2:
		oddNumIndeces = list(range(n // 2 + i - n + 1, n // 2 - (i - n)))
	else:
		oddNumIndeces = list(range(n // 2 - i, n // 2 + i + 1))
	for j in range(n):
		if j not in oddNumIndeces:
			outList.append(str(evenNums[0]))
			evenNums.pop(0)
		else:
			outList.append(str(oddNums[0]))
			oddNums.pop(0)
	print(' '.join(outList))


n = int(input())
a = [i for i in range(1, n * n + 1)]
even = []
odd = []
for x in a:
	if x % 2 == 0:
		even.append(x)
	else:
		odd.append(x)
c = 1
for i in range(n):
	si = (n - c) // 2
	ei = si + c - 1
	for j in range(n):
		if j >= si and j <= ei:
			print(odd[0], end=' ')
			odd.pop(0)
		else:
			print(even[0], end=' ')
			even.pop(0)
	print()
	if i >= n // 2:
		c -= 2
	else:
		c += 2


n = int(input())
matrix = [[0] * n for i in range(n)]
for i in range(n):
	matrix[i][n - 1 - i] = int((n * n - n + 2) / 2) + i
p = 1
sx = 0
sy = n - 2
x = 0
y = n - 2
j = 0
while p != int((n * n - n + 2) / 2):
	if y != j:
		matrix[x][y] = p
		matrix[n - 1 - x][n - 1 - y] = n * n + 1 - p
		p += 1
		y -= 1
	elif x + y != n - 1:
		matrix[x][y] = p
		matrix[n - 1 - x][n - 1 - y] = n * n + 1 - p
		p += 1
		x += 1
	elif x + y == n - 1:
		x = sx + 1
		y = sy - 1
		sx += 1
		sy -= 1
		j += 1
for i in range(n):
	for j in range(n):
		print(matrix[i][j], end='')
		if j != n - 1:
			print(' ', end='')
	print('\n', end='')


import sys
n = int(input())
odd = list(range(1, n * n + 1, 2))
even = list(range(2, n * n + 1, 2))
A = [[0] * n for _ in range(n)]
for i in range(n):
	A[i][n // 2] = odd.pop()
for i in range(n):
	if i != n // 2:
		A[n // 2][i] = odd.pop()
n_off = (n + 1) // 2
for p in range(2):
	for q in range(2):
		even_to_spend = n // 2 * (n + 1) // 2 // 2
		for i in range(n // 2):
			for j in range(n // 2):
				if even_to_spend > 0:
					even_to_spend -= 1
					A[i + p * n_off][j + q * n_off] = even.pop()
				else:
					A[i + p * n_off][j + q * n_off] = odd.pop()
for i in range(n):
	for j in range(n):
		print(A[i][j], end=' ')
	print()


n = int(input())
matrix = [[0] * n for i in range(n)]
ans = [[0] * n for i in range(n)]
a = n * n // 2
lis = []
for i in range(a + 1):
	lis.append(2 * i + 1)
for i in range(a):
	lis.append(2 * (i + 1))
j = 0
x = n // 2
y = x + 1
for i in range(n):
	if i <= n // 2:
		for k in range(x, y):
			ans[i][k] = lis[j]
			matrix[i][k] = 1
			j += 1
		if i != n // 2:
			x -= 1
			y += 1
	else:
		x += 1
		y -= 1
		for k in range(x, y):
			ans[i][k] = lis[j]
			matrix[i][k] = 1
			j += 1
for i in range(n):
	for k in range(n):
		if matrix[i][k] == 0:
			ans[i][k] = lis[j]
			j += 1
for i in range(n):
	print(' '.join((str(x) for x in ans[i])))


import sys
sys.setrecursionlimit(30000)
from collections import Counter, defaultdict, deque
from math import ceil, floor, factorial, fsum, isinf, exp, log, log10, log2, isfinite, sqrt
from math import pi as PI, e as E
from fractions import Fraction
from itertools import starmap, tee, chain, filterfalse, combinations as combos
from itertools import permutations as perms, product as prod, combinations_with_replacement as rcombos
from functools import reduce, partial
import operator as ops
from operator import __not__ as notit
from operator import __abs__ as absit
from operator import __or__ as orit
(PHI, PHI2) = ((1 + 5 ** 0.5) / 2, (5 ** 0.5 - 1) / 2)
INF = float('inf')

class TreeNode:

	def __init__(self, v):
		self.val = v
		self.left = None
		self.right = None

def setBit(x, offset):
	return x | 1 << offset

def clearBit(x, offset):
	return x & ~(1 << offset)

def getBit(x, offset):
	return 1 if testBit(x, offset) > 0 else 0

def testBit(x, offset):
	return x & 1 << offset

def flipBitAt(x, offset):
	return x ^ 1 << offset

def flipBits(x, length=-1):
	length = x.bit_length() - 1 if length == -1 else length
	return x ^ (1 << length) - 1

def numBits(x):
	return x.bit_length()

def countOnes(x):
	return bin(x).count('1')

def countZeros(x, length=-1):
	length = x.bit_length() if length == -1 else length
	return length - countOnes(x)

def getList(tcast=str):
	return [tcast(x) for x in input().strip().split(' ')]

def getItems(*tcast):
	return map(lambda f, x: f(x), tcast, getList())

def getVal(tcast=str):
	return tcast(input().strip())

def getMatrix(r, tcast=str):
	return [getList(tcast) for row in range(r)]

def isOdd(n):
	return n & 1 > 0

def isEven(n):
	return not n & 1

def numDigits(n):
	return len(str(n)) - (1 if n < 0 else 0)

def getRecip(f):
	return Fraction(f.denominator, f.numerator)

def _gcd(a, b):
	while b:
		(a, b) = (b, a % b)
	return a

def gcd(*xs):
	nums = xs[0] if type(xs[0]) == list else list(xs)
	cur = nums[0]
	for n in nums[1:]:
		if cur == 1:
			return cur
		cur = _gcd(cur, n)
	return cur

def _lcm(a, b):
	return a // gcd(a, b) * b

def lcm(*xs):
	nums = xs[0] if type(xs[0]) == list else list(xs)
	cur = nums[0]
	for n in nums[1:]:
		cur = _lcm(cur, n)
	return cur

def primesUpto(n):
	isp = [True] * (n + 1)
	(isp[0], isp[1]) = (False, False)
	primes = []
	for (i, x) in enumerate(isp):
		if x:
			primes.append(i)
			mults = i * i
			while mults <= n:
				isp[mults] = False
				mults += i
	return primes

def primeFactor(n):
	factors = Counter()
	while not n & 1:
		factors[2] += 1
		n >>= 1
	trynum = 3
	while trynum <= ceil(sqrt(n)):
		while n % trynum == 0:
			factors[trynum] += 1
			n //= trynum
		trynum += 2
	if n != 1:
		factors[n] += 1
	return factors

def isPrime(n):
	if n & 1 and n >= 2:
		trynum = 3
		limit = ceil(sqrt(n))
		while trynum < limit:
			if n % trynum == 0:
				return False
			trynum += 2
		else:
			return True
	else:
		return False

def nthFib(n):
	if n <= 2:
		return 1
	else:
		(a, b) = (1, 1)
		while n > 2:
			(a, b) = (b, a + b)
			n -= 1
		return b

def zipNWith(f, *x):
	return (f(y) for y in zip(*x))

def zipWith(f, xs, ys):
	return (f(x, y) for (x, y) in zip(xs, ys))

def flatten(xs):
	return reduce(ops.concat, xs)

def quantify(pred, it):
	return sum(map(pred, it))

def dotproduct(xs, ys):
	return sum(map(ops.mul, xs, ys))

def pairwise(it):
	(a, b) = tee(it)
	next(b, None)
	return zip(a, b)

def bipartition(pred, it):
	(t, f) = tee(it)
	return (filter(pred, t), filterfalse(pred, f))

def powerset(it):
	s = list(it)
	return chain.from_iterable((combos(s, r) for r in range(len(s) + 1)))

def printmat(mat):
	for row in mat:
		print(*row)

def nextwrap(coords):
	global n
	(r, c) = coords
	(r, c) = ((r - 1) % n, (c + 1) % n)
	return (r, c)

def nextdown(coords):
	global n
	(r, c) = coords
	(r, c) = ((r + 1) % n, c % n)
	return (r, c)
n = getVal(int)
if n == 1:
	print(1)
else:
	mat = []
	for i in range(n):
		mat.append([0] * n)
	start = [0, n // 2]
	mat[start[0]][start[1]] = 1
	for i in range(n ** 2 - 1):
		(r, c) = nextwrap(start)
		if mat[r][c] != 0:
			(r, c) = nextdown(start)
		mat[r][c] = i + 2
		start = [r, c]
	printmat(mat)


n = int(input())
a = [[0] * n for _ in range(n)]

def od(i, j):
	k = min(i + 1, n - i)
	return abs(j - n // 2) < k
(u, v) = (0, 0)
for i in range(n):
	for j in range(n):
		if od(i, j):
			u += 1
			a[i][j] = u * 2 - 1
		else:
			v += 1
			a[i][j] = v * 2
print('\n'.join([' '.join(map(str, x)) for x in a]))


n = int(input())

def fun(n, s, nn):
	mas = [[0] * n for i in range(n)]
	start = n // 2
	i = 0
	j = start
	for value in range(s, nn):
		if i < 0 and j > n - 1:
			i = n - 1
			j = n - 1
			if mas[i][j] != 0:
				i = 1
				j = n - 1
		if i < 0:
			i = n - 1
		if j > n - 1:
			j = 0
		if mas[i][j] != 0:
			i = i + 2
			j = j - 1
		mas[i][j] = value
		i = i - 1
		j = j + 1
	return mas
if n % 2 != 0:
	mas = fun(n, 1, n ** 2 + 1)
	for i in range(n):
		t = []
		for y in range(n):
			t.append(str(mas[i][y]))
		print(' '.join(t))


def table(n, i):
	if n == 1:
		print(1, end=' ')
		return
	k = (n + 1) // 2
	p = (n - 2) ** 2
	if k % 2 == 0:
		if i == 0:
			for m in range(p + 1, p + 1 + n):
				print(m, end=' ')
		elif i == n - 1:
			for m in range(n * n - n, n * n):
				print(m, end=' ')
		else:
			print(p + n + i, end=' ')
			table(n - 2, i - 1)
			if i == 1:
				print(n ** 2, end=' ')
			else:
				print(p + n + i + n - 3, end=' ')
	elif i == 0:
		for m in range(p + 2, p + 2 + n):
			print(m, end=' ')
	elif i == n - 1:
		for m in range(n * n - n + 1, n * n + 1):
			print(m, end=' ')
	else:
		print(p + n + i + 1, end=' ')
		table(n - 2, i - 1)
		if i == 1:
			print(p + 1, end=' ')
		else:
			print(p + n + i + n - 2, end=' ')
n = int(input())
for i in range(0, n):
	table(n, i)
	print()


def main():

	def f(n):
		if n == 1:
			return [[1]]
		it = iter(range((n - 4) * n + 5, n * n + 1) if n & 2 else range(n * n, 0, -1))
		res = [[next(it) for _ in range(n)]]
		for row in f(n - 2):
			res.append([next(it)] + row)
		res.append([next(it) for _ in range(n)])
		for row in res[1:-1]:
			row.append(next(it))
		return res
	for l in f(int(input())):
		print(*l)
main()


n = int(input())
square = [[0 for x in range(n)] for y in range(n)]
toInsert = n * n // 2 + 1
np = 1
for i in range(n):
	if square[i][n // 2] == 0:
		toInsert -= 1
		square[i][n // 2] = np
		np = np + 2
	if square[n // 2][i] == 0:
		toInsert -= 1
		square[n // 2][i] = np
		np = np + 2

def exiting():
	p = 2
	for i in range(n):
		for j in range(n):
			if square[i][j] == 0:
				square[i][j] = p
				p += 2
			print(square[i][j], end=' ')
		print()
	exit()
if toInsert <= 0:
	exiting()
for i in range(n // 2):
	for j in range(n // 2):
		if toInsert <= 0:
			exiting()
		toInsert -= 4
		square[i][j] = np
		np = np + 2
		square[n - 1 - i][j] = np
		np = np + 2
		square[i][n - 1 - j] = np
		np = np + 2
		square[n - 1 - i][n - 1 - j] = np
		np = np + 2


n = int(input())
c = n // 2 + 1
odd = 1
even = 2
for i in range(1, n + 1):
	s = ''
	for j in range(1, n + 1):
		if abs(c - i) + abs(c - j) <= n // 2:
			s = s + str(odd) + ' '
			odd += 2
		else:
			s = s + str(even) + ' '
			even += 2
	print(s)


a = int(input())
list = []
for i in range(a):
	list.append([0] * a)
it = [int(a / 2), 0]
list[it[0]][it[1]] = 1
for i in range(2, a ** 2 + 1):
	if list[(it[0] + 1) % a][(it[1] - 1) % a] == 0:
		list[(it[0] + 1) % a][(it[1] - 1) % a] = i
		it[0] = (it[0] + 1) % a
		it[1] = (it[1] - 1) % a
	else:
		list[it[0]][(it[1] + 1) % a] = i
		it[1] = (it[1] + 1) % a
for i in range(a):
	for j in range(a):
		print(list[i][j], end=' ')
	print('')


n = int(input())
odds = [[False] * n for _ in range(n)]
numbers = [[None] * n for _ in range(n)]
for i in range(n // 2):
	for j in range(n):
		mid = n // 2
		if mid - i <= j <= mid + i:
			odds[i][j] = True
odds[n // 2] = [True] * n
for i in range(n // 2 + 1, n):
	for j in range(n):
		mid = n // 2
		dist = n - i - 1
		if mid - dist <= j <= mid + dist:
			odds[i][j] = True
(odd, even) = (1, 2)
for i in range(n):
	for j in range(n):
		if odds[i][j]:
			numbers[i][j] = odd
			odd += 2
		else:
			numbers[i][j] = even
			even += 2
print('\n'.join((' '.join(map(str, row)) for row in numbers)))


n = int(input())
magic = int((n - 1) / 2)
x = []
for t in range(magic, -1, -1):
	x.append(t * '*' + 'D' * (n - 2 * t) + t * '*')
for u in range(1, magic + 1):
	x.append(u * '*' + 'D' * (n - 2 * u) + u * '*')
no = 1
ne = 2
for i in range(n):
	for j in range(n):
		if x[i][j] == 'D':
			print(no, end=' ')
			no += 2
		else:
			print(ne, end=' ')
			ne += 2
	print()


n = int(input())
h = (n - 1) // 2
A = [[0 for c in range(n)] for r in range(n)]
for r in range(n):
	for c in range(n):
		A[(r + c - h) % n][(r - c + h) % n] = r * n + c + 1
for r in range(n):
	print(' '.join(('{:d}'.format(x) for x in A[r])))


a = int(input())
odd = 1
even = 2
c = a // 2
l = [[] for x in range(a)]
for row in range(0, a):
	for col in range(0, a):
		if c <= col <= a - 1 - c:
			l[row].append(odd)
			odd += 2
		else:
			l[row].append(even)
			even += 2
	if row < a // 2:
		c -= 1
	else:
		c += 1
for row in l:
	print(' '.join(list(map(str, row))))


import sys
input = sys.stdin.readline

def ceil(x, y):
	return (x + y - 1) // y

def swaparr(arr, a, b):
	temp = arr[a]
	arr[a] = arr[b]
	arr[b] = temp

def gcd(a, b):
	if b == 0:
		return a
	return gcd(b, a % b)

def nCr(n, k):
	if k > n - k:
		k = n - k
	res = 1
	for i in range(k):
		res = res * (n - i)
		res = res / (i + 1)
	return int(res)

def upper_bound(a, x, lo=0):
	hi = len(a)
	while lo < hi:
		mid = (lo + hi) // 2
		if a[mid] < x:
			lo = mid + 1
		else:
			hi = mid
	return lo

def primefs(n):
	primes = {}
	while n % 2 == 0 and n > 0:
		primes[2] = primes.get(2, 0) + 1
		n = n // 2
	for i in range(3, int(n ** 0.5) + 2, 2):
		while n % i == 0 and n > 0:
			primes[i] = primes.get(i, 0) + 1
			n = n // i
	if n > 2:
		primes[n] = primes.get(n, 0) + 1
	return primes

def power(x, y, p):
	res = 1
	x = x % p
	if x == 0:
		return 0
	while y > 0:
		if y & 1 == 1:
			res = res * x % p
		y = y >> 1
		x = x * x % p
	return res

def swap(a, b):
	temp = a
	a = b
	b = temp
	return (a, b)

def find(x, link):
	p = x
	while p != link[p]:
		p = link[p]
	while x != p:
		nex = link[x]
		link[x] = p
		x = nex
	return p

def union(x, y, link, size):
	x = find(x, link)
	y = find(y, link)
	if size[x] < size[y]:
		(x, y) = swap(x, y)
	if x != y:
		size[x] += size[y]
		link[y] = x

def sieve(n):
	prime = [True for i in range(n + 1)]
	p = 2
	while p * p <= n:
		if prime[p] == True:
			for i in range(p * p, n + 1, p):
				prime[i] = False
		p += 1
	return prime
MAXN = int(10000000.0 + 5)

def spf_sieve():
	spf[1] = 1
	for i in range(2, MAXN):
		spf[i] = i
	for i in range(4, MAXN, 2):
		spf[i] = 2
	for i in range(3, ceil(MAXN ** 0.5), 2):
		if spf[i] == i:
			for j in range(i * i, MAXN, i):
				if spf[j] == j:
					spf[j] = i

def factoriazation(x):
	ret = {}
	while x != 1:
		ret[spf[x]] = ret.get(spf[x], 0) + 1
		x = x // spf[x]
	return ret

def int_array():
	return list(map(int, input().strip().split()))

def str_array():
	return input().strip().split()
MOD = int(1000000000.0) + 7
CMOD = 998244353
INF = float('inf')
NINF = -float('inf')
n = int(input())
a = [[0 for _ in range(n)] for __ in range(n)]
odd = 1
even = 2
for i in range(n):
	if i < n // 2:
		for j in range(n // 2 - i, n // 2 + i + 1):
			a[i][j] = odd
			odd += 2
	elif i == n // 2:
		for j in range(n):
			a[i][j] = odd
			odd += 2
	else:
		x = n - 1 - i
		for j in range(n // 2 - x, n // 2 + x + 1):
			a[i][j] = odd
			odd += 2
for i in range(n):
	for j in range(n):
		if a[i][j] == 0:
			a[i][j] = even
			even += 2
for i in a:
	print(*i)


N = int(input())
evens = [n for n in range(1, N * N + 1) if n % 2 == 0]
odds = [n for n in range(1, N * N + 1) if n % 2 != 0]
s = 0
t = 0
for i in range(N):
	n_even = max(N // 2 - i, i - N // 2)
	n_odd = N - n_even * 2
	res = []
	for ne in range(n_even):
		res.append(evens[s])
		s += 1
	for no in range(n_odd):
		res.append(odds[t])
		t += 1
	for ne in range(n_even):
		res.append(evens[s])
		s += 1
	print(' '.join(map(str, res)))


from math import ceil
n = int(input())
evens = [i for i in range(1, n ** 2 + 1) if i % 2 == 0]
odds = [i for i in range(1, n ** 2 + 1) if i % 2 == 1]
x = ceil(n / 2)
e = 0
o = 0
for i in range(1, n + 1):
	for j in range(abs(x - i)):
		print(evens[e], end=' ')
		e += 1
	for j in range(abs(n - abs(x - i) * 2)):
		print(odds[o], end=' ')
		o += 1
	for j in range(abs(x - i)):
		print(evens[e], end=' ')
		e += 1
	print('\t')


n = int(input())
answer = [[0] * n] * n
even = []
not_even = []
for i in range(1, n ** 2 + 1):
	if i % 2 == 0:
		even.append(i)
	else:
		not_even.append(i)
levels = [(0, 0)] * n
if n == 1:
	print(1)
else:
	for i in range(n):
		if i > n // 2:
			middle_r = levels[n - i - 1][1]
			middle_l = levels[n - i - 1][0]
		else:
			middle_r = max(n // 2 + i, n // 2 - i)
			middle_l = min(n // 2 - i, n // 2 + i)
			levels[i] = (middle_l, middle_r)
		for j in range(n):
			if middle_r >= j >= middle_l:
				print(not_even.pop(len(not_even) - 1), end=' ')
			else:
				print(even.pop(len(even) - 1), end=' ')
		print('\n')


def solve():
	n = int(input())
	if n == 1:
		print(1)
		return
	b = [[False for i in range(n)] for j in range(n)]
	m = n // 2
	en = n ** 2 // 2
	for i in range(m):
		for j in range(m):
			b[i][j] = True
			b[i][2 * m - j] = True
			b[2 * m - i][j] = True
			b[2 * m - i][2 * m - j] = True
			en -= 4
			if en == 0:
				break
		if en == 0:
			break
	o = 1
	e = 2
	a = [['0' for i in range(n)] for j in range(n)]
	for i in range(n):
		for j in range(n):
			if b[i][j]:
				a[i][j] = str(e)
				e += 2
			else:
				a[i][j] = str(o)
				o += 2
	for i in range(n):
		print(' '.join(a[i]))

def main():
	solve()
main()


from collections import namedtuple
Dir = namedtuple('Dir', ['x', 'y'])
dirs4 = [Dir(-1, -1), Dir(-1, 1), Dir(1, -1), Dir(1, 1)]
dirs = [(dirs4[0], Dir(1, 0)), (dirs4[0], Dir(0, 1)), (dirs4[1], Dir(1, 0)), (dirs4[1], Dir(0, -1)), (dirs4[2], Dir(-1, 0)), (dirs4[2], Dir(0, 1)), (dirs4[3], Dir(-1, 0)), (dirs4[3], Dir(0, -1))]

def build_pattern(n):
	odd_n = n * n // 2 + 1
	m = [[0] * n for _ in range(n)]
	mid = n // 2
	for i in range(n):
		m[i][mid] = 1
	odd_n -= n
	for i in range(n):
		m[mid][i] = 1
	odd_n -= n - 1
	step = 2
	while odd_n > 0:
		for dir in dirs4:
			m[mid + step * dir.x][mid + step * dir.y] = 1
		odd_n -= 4
		o_odd_n = odd_n // 8
		for (start, dir) in dirs:
			for i in range(1, o_odd_n + 1):
				x = mid + step * start.x + i * dir.x
				y = mid + step * start.y + i * dir.y
				if x == mid or y == mid:
					break
				m[x][y] = 1
				odd_n -= 1
		step += 2
	return m

def solve(n):
	odds = [x for x in range(1, n * n + 1) if x % 2 != 0]
	evens = [x for x in range(1, n * n) if x % 2 == 0]
	(odds_i, evens_i) = (0, 0)
	mp = build_pattern(n)
	m = [[0] * n for _ in range(n)]
	for i in range(n):
		for j in range(n):
			if mp[i][j] > 0:
				m[i][j] = odds[odds_i]
				odds_i += 1
			else:
				m[i][j] = evens[evens_i]
				evens_i += 1
	return m

def main():
	n = int(input())
	m = solve(n)
	for row in m:
		print(' '.join(map(str, row)))
main()


def matrix(k):
	for i in range(len(k)):
		for j in range(len(k[i])):
			print(k[i][j], end=' ')
		print('\n', end='')
n = int(input())
l = [[0] * n for _ in range(n)]
s = 1
x = int((n + 1) / 2)
y = int((n - 1) / 2)
for j in range(x):
	for i in range(y - j, y + j + 1, 1):
		l[i][j] = s
		s += 2
for j in range(x, n, 1):
	for i in range(j - x + 1, x - j + n - 2 + 1, 1):
		l[i][j] = s
		s += 2
s = 2
for i in range(n):
	for j in range(n):
		if l[i][j] == 0:
			l[i][j] = s
			s += 2
matrix(l)


n = eval(input())
lst = [[None] * n for i in range(n)]
row = 0
col = int((n - 1) / 2)
for i in range(1, n ** 2 + 1):
	if lst[row][col] == None:
		lst[row][col] = i
	else:
		row += 2
		col -= 1
		if row > n - 1:
			row -= n
		if col == -1:
			col += n
		lst[row][col] = i
	row -= 1
	col += 1
	if row == -1:
		row += n
	if col == n:
		col -= n
for i in lst:
	for j in i:
		print(j, end='\t')
	print()


read = input().split(' ')
n = int(read[0])
tab = [[0 for x in range(n)] for y in range(n)]
p = int((n - 1) / 2)
k = p + 1
for i in range(n):
	for j in range(p, k):
		tab[i][j] = 1
	if i < (n - 1) / 2:
		p -= 1
		k += 1
	else:
		p += 1
		k -= 1
odd = 1
even = 2
for i in range(n):
	output = ''
	for j in range(n):
		if tab[i][j] == 1:
			result = odd
			odd += 2
		else:
			result = even
			even += 2
		output += str(result)
		output += ' '
	print(output)


from collections import *
import os, sys
from io import BytesIO, IOBase

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
BUFSIZE = 8192
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
rstr = lambda : input().strip()
rstrs = lambda : [str(x) for x in input().split()]
rstr_2d = lambda n: [rstr() for _ in range(n)]
rint = lambda : int(input())
rints = lambda : [int(x) for x in input().split()]
rint_2d = lambda n: [rint() for _ in range(n)]
rints_2d = lambda n: [rints() for _ in range(n)]
ceil1 = lambda a, b: (a + b - 1) // b
(n, o, e) = (rint(), 1, 2)
(ans, l, r) = ([[0] * n for i in range(n)], n >> 1, n >> 1)
for i in range(n):
	for j in range(n):
		if l <= j <= r:
			ans[i][j] = o
			o += 2
		else:
			ans[i][j] = e
			e += 2
	if i < n >> 1:
		l -= 1
		r += 1
	else:
		r -= 1
		l += 1
print(*[' '.join(map(str, x)) for x in ans], sep='\n')


n = int(input())
odd = list(filter(lambda m: m % 2 == 1, range(1, n ** 2 + 1)))
even = list(filter(lambda m: m % 2 == 0, range(1, n ** 2 + 1)))
magic_square = []
for i in range(n):
	if i == 0:
		s = '01' * (n // 2)
		if n % 4 == 1:
			s = '1' + s
		else:
			s = s + '0'
		magic_square.append(s)
	else:
		last = int(magic_square[i - 1], 2)
		fil_a = '1' * i + '0' * (n - i)
		fil_b = '0' * (n - i) + '1' * i
		s = format(last ^ int(fil_a, 2) ^ int(fil_b, 2), 'b').zfill(n)
		magic_square.append(s)
ans = []
for row in magic_square:
	l = []
	for col in row:
		if col == '1':
			l.append(odd.pop())
		else:
			l.append(even.pop())
	ans.append(l)
for i in ans:
	print(' '.join(map(str, i)))


import math
n = int(input())
m = n // 2
mx = m
my = m
a = [[0 for x in range(n)] for y in range(n)]
a[mx][my] = 1
for dm in range(1, m + 1):
	base = int(math.pow(2 * (dm - 1) + 1, 2)) + 1
	for x in range(0, 2 * dm):
		a[my - dm][mx - dm + x + (dm + 1) % 2] = base + x
		a[my - dm + x + (dm + 1) % 2][mx + dm] = base + 2 * dm + x
		a[my + dm][mx + dm - x - (dm + 1) % 2] = base + 4 * dm + x
		a[my + dm - x - (dm + 1) % 2][mx - dm] = base + 6 * dm + x
for y in range(0, n):
	print(' '.join(map(str, a[y])))


n = int(input())
o = 1
e = 2
import sys
for i in range(n):
	for j in range(n):
		if abs(i - n // 2) + abs(j - n // 2) <= n // 2:
			sys.stdout.write(str(o))
			o += 2
		else:
			sys.stdout.write(str(e))
			e += 2
		sys.stdout.write(' ')
	sys.stdout.write('\n')


n = int(input())
mxc = ((n * n + 1) // 2 - (2 * n - 1)) // 4
m = []
for i in range(n):
	l = [0] * n
	m.append(l)
odd = 1
i = n // 2
j = 0
while j < n:
	m[i][j] = odd
	j += 1
	odd += 2
j = 0
while j < n:
	if i == j:
		j += 1
		continue
	m[j][i] = odd
	j += 1
	odd += 2
i = 0
j = 0
c = 0
while c < mxc:
	c += 1
	m[i][j] = odd
	odd += 2
	m[i][n - 1 - j] = odd
	odd += 2
	m[n - 1 - i][j] = odd
	odd += 2
	m[n - i - 1][n - 1 - j] = odd
	odd += 2
	j += 1
	if j == n // 2:
		j = 0
		i += 1
even = 2
for i in range(n):
	for j in range(n):
		if m[i][j] == 0:
			m[i][j] = even
			even += 2
for i in range(n):
	for j in range(n):
		print(m[i][j], end=' ')
	print()


n = int(input())
pp = 2
pn = 1
if n == 1:
	print(1)
else:
	k = n // 2
	for i in range(k + 1):
		for j in range(k - i):
			print(pp, end=' ')
			pp += 2
		for j in range(k - i, n - k + i):
			print(pn, end=' ')
			pn += 2
		for j in range(n - k + i, n):
			print(pp, end=' ')
			pp += 2
		print()
	for i in range(k - 1, -1, -1):
		for j in range(k - i):
			print(pp, end=' ')
			pp += 2
		for j in range(k - i, n - k + i):
			print(pn, end=' ')
			pn += 2
		for j in range(n - k + i, n):
			print(pp, end=' ')
			pp += 2
		print()


import io
import sys
import time
import random
n = int(input())
k = n // 2
m = [[1 for j in range(n)] for i in range(n)]
for i in range(1, k + 1):
	for j in range(1, k + 2 - i):
		m[i - 1][j - 1] = 0
		m[n - i][j - 1] = 0
		m[i - 1][n - j] = 0
		m[n - i][n - j] = 0
even_index = 1
odd_index = 1
for i in range(n):
	for j in range(n):
		if m[i][j] == 0:
			m[i][j] = even_index * 2
			even_index += 1
		else:
			m[i][j] = odd_index * 2 - 1
			odd_index += 1
for i in range(n):
	for j in range(n):
		print(m[i][j], end=' ')
	print()


sz = int(input())
odd_no = 1
even_no = 2
for z in range(sz):
	odds_to_print = sz - 2 * int(abs(sz // 2 - z))
	evens_to_print = (sz - odds_to_print) // 2
	while evens_to_print > 0:
		print(even_no, end=' ')
		even_no += 2
		evens_to_print -= 1
	while odds_to_print > 0:
		print(odd_no, end=' ')
		odd_no += 2
		odds_to_print -= 1
	odds_to_print = sz - 2 * abs(sz // 2 - z)
	evens_to_print = (sz - odds_to_print) // 2
	while evens_to_print > 0:
		print(even_no, end=' ')
		even_no += 2
		evens_to_print -= 1
	print('')


import sys, os
from io import BytesIO, IOBase
import collections, itertools, bisect, heapq, math, string
from decimal import *
BUFSIZE = 8192
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

def main():
	n = int(input())
	if n == 1:
		print(1)
		return
	ans = [[0] * n for i in range(n)]
	k = 0
	for i in range(n):
		if i < n // 2:
			for j in range(n // 2 - i, n // 2 - i + 2 * i + 1):
				ans[i][j] = 2 * k + 1
				k += 1
		if i > n // 2:
			for j in range(i - n // 2, i - n // 2 + 2 * (n - i - 1) + 1):
				ans[i][j] = 2 * k + 1
				k += 1
		if i == n // 2:
			for j in range(n):
				ans[i][j] = 2 * k + 1
				k += 1
	k = 1
	for i in range(n):
		for j in range(n):
			if ans[i][j] == 0:
				ans[i][j] = 2 * k
				k += 1
	for a in ans:
		print(' '.join([str(x) for x in a]))
main()


import sys
import bisect
from bisect import bisect_left as lb
input_ = lambda : sys.stdin.readline().strip('\r\n')
from math import log
from math import gcd
from math import atan2, acos
from random import randint
sa = lambda : input_()
sb = lambda : int(input_())
sc = lambda : input_().split()
sd = lambda : list(map(int, input_().split()))
sflo = lambda : list(map(float, input_().split()))
se = lambda : float(input_())
sf = lambda : list(input_())
flsh = lambda : sys.stdout.flush()
mod = 10 ** 9 + 7
mod1 = 998244353
gp = []
cost = []
dp = []
mx = []
ans1 = []
ans2 = []
special = []
specnode = []
a = 0
kthpar = []

def dfs(root, par):
	if par != -1:
		dp[root] = dp[par] + 1
	for i in range(1, 20):
		if kthpar[root][i - 1] != -1:
			kthpar[root][i] = kthpar[kthpar[root][i - 1]][i - 1]
	for child in gp[root]:
		if child == par:
			continue
		kthpar[child][0] = root
		dfs(child, root)
ans = 0

def hnbhai(tc):
	n = sb()
	mat = [[0 for i in range(n)] for j in range(n)]
	x = n // 2
	y = n - 1
	for i in range(n * n):
		mat[x][y] = i + 1
		x1 = (x + 1) % n
		y1 = (y + 1) % n
		if mat[x1][y1] != 0:
			x1 = x
			y1 = (y - 1) % n
		x = x1
		y = y1
	for i in mat:
		print(*i)
for _ in range(1):
	hnbhai(_ + 1)


n = int(input())
nn = n ** 2
Es = [2 * i for i in range(1, nn // 2 + 1)]
Os = [2 * i + 1 for i in range(nn // 2 + 1)]
k = n // 2
for i in range(n // 2):
	o = [str(Es.pop()) for i in range(k)] + [str(Os.pop()) for q in range(n - 2 * k)] + [str(Es.pop()) for i in range(k)]
	print(' '.join(o))
	k -= 1
print(' '.join([str(Os.pop()) for i in range(n)]))
for i in range(n // 2):
	k += 1
	o = [str(Es.pop()) for i in range(k)] + [str(Os.pop()) for q in range(n - 2 * k)] + [str(Es.pop()) for i in range(k)]
	print(' '.join(o))


n = int(input())
c = n // 2
m = []
o = 1
e = 2
for i in range(n):
	row = []
	for j in range(n):
		if abs(i - c) + abs(j - c) <= c:
			row.append(str(o))
			o += 2
		else:
			row.append(str(e))
			e += 2
	m.append(row)
for row in m:
	print(' '.join(row))


(d, n) = ([-1, 0], int(input()))
for x in range(n):
	t = []
	for y in range(n):
		s = min(abs(x - n // 2), abs(y - n // 2)) & 1
		d[s] += 2
		t += [d[s]]
	print(*t)


import sys
n = int(input())
odd = [i for i in range(1, n ** 2 + 1, 2)]
even = [i for i in range(2, n ** 2, 2)]
for i in range(1, n + 1, 2):
	for j in range((n - i) // 2):
		sys.stdout.write('%-2d ' % even.pop())
	for j in range(i):
		sys.stdout.write('%-2d ' % odd.pop())
	for j in range((n - i) // 2):
		sys.stdout.write('%-2d ' % even.pop())
	sys.stdout.write('\n')
for i in reversed(range(1, n, 2)):
	for j in range((n - i) // 2):
		sys.stdout.write('%-2d ' % even.pop())
	for j in range(i):
		sys.stdout.write('%-2d ' % odd.pop())
	for j in range((n - i) // 2):
		sys.stdout.write('%-2d ' % even.pop())
	sys.stdout.write('\n')


from bisect import insort, bisect_right, bisect_left
from sys import stdout, stdin, setrecursionlimit
from heapq import heappush, heappop, heapify
from io import BytesIO, IOBase
from collections import *
from itertools import *
from random import *
from string import *
from queue import *
from math import *
from re import *
from os import *

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = read(self._fd, max(fstat(self._fd).st_size, 8192))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = read(self._fd, max(fstat(self._fd).st_size, 8192))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(stdin, stdout) = (IOWrapper(stdin), IOWrapper(stdout))
(graph, mod, szzz) = ({}, 10 ** 9 + 7, lambda : sorted(zzz()))

def getStr():
	return input()

def getInt():
	return int(input())

def listStr():
	return list(input())

def getStrs():
	return input().split()

def isInt(s):
	return '0' <= s[0] <= '9'

def input():
	return stdin.readline().strip()

def zzz():
	return [int(i) for i in input().split()]

def output(answer, end='\n'):
	stdout.write(str(answer) + end)

def lcd(xnum1, xnum2):
	return xnum1 * xnum2 // gcd(xnum1, xnum2)

def getPrimes(N=10 ** 5):
	SN = int(sqrt(N))
	sieve = [i for i in range(N + 1)]
	sieve[1] = 0
	for i in sieve:
		if i > SN:
			break
		if i == 0:
			continue
		for j in range(2 * i, N + 1, i):
			sieve[j] = 0
	prime = [i for i in range(N + 1) if sieve[i] != 0]
	return prime

def primeFactor(n, prime=getPrimes()):
	lst = []
	mx = int(sqrt(n)) + 1
	for i in prime:
		if i > mx:
			break
		while n % i == 0:
			lst.append(i)
			n //= i
	if n > 1:
		lst.append(n)
	return lst
dx = [-1, 1, 0, 0, 1, -1, 1, -1]
dy = [0, 0, 1, -1, 1, -1, -1, 1]
daysInMounth = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
n = getInt()
lst = [[0 for i in range(n)] for j in range(n)]
x = n // 2
y = 0
for i in range(1, n * n + 1):
	lst[y % n][x % n] = i
	x += 1
	y -= 1
	if lst[y % n][x % n]:
		x -= 1
		y += 2
for i in lst:
	for j in i:
		print(j, end=' ')
	print()


n = int(input())
arr = []
kC = 2
for i in range(n):
	arr.append([])
	for j in range(n):
		arr[i].append(0)
kN = 1
kS = 1
for i in range(n // 2 + 1):
	k = 0
	for j in range(n // 2, n):
		if k == 0:
			arr[i][j] = kN
			kN += 2
			k += 1
		elif k + 2 <= kS:
			arr[i][j] = kN
			kN += 2
			arr[i][n // 2 - (k - 1) // 2 - 1] = kN
			kN += 2
			k += 2
		else:
			break
	kS += 2
kS = n - 2
for i in range(n // 2 + 1, n):
	k = 0
	for j in range(n // 2, n):
		if k == 0:
			arr[i][j] = kN
			kN += 2
			k += 1
		elif k + 2 <= kS:
			arr[i][j] = kN
			kN += 2
			arr[i][n // 2 - (k - 1) // 2 - 1] = kN
			kN += 2
			k += 2
		else:
			break
	kS -= 2
kC = 2
for i in range(n):
	for j in range(n):
		if arr[i][j] == 0:
			arr[i][j] = kC
			kC += 2
	print(*arr[i])


N = int(input())
cnt = 0
the_odd = -1
the_eve = 0

def get_with_eve_N(x, y):
	return -1

def get_with_odd_N(x, y):
	global the_odd
	global the_eve
	if x + y <= N + 1 >> 1 or x + y >= N + (N + 1 >> 1) + 1 or y - x >= N + 1 >> 1 or (x - y >= N + 1 >> 1):
		the_eve += 2
		return the_eve
	else:
		the_odd += 2
		return the_odd
if N % 2 == 0:
	for i in range(1, N + 1):
		for j in range(1, N + 1):
			if j == N:
				print(get_with_eve_N(i, j))
			else:
				print(get_with_eve_N(i, j), end=' ')
else:
	for i in range(1, N + 1):
		for j in range(1, N + 1):
			if j == N:
				print(get_with_odd_N(i, j))
			else:
				print(get_with_odd_N(i, j), end=' ')


n = int(input())
m = n ** 2
ch = []
nech = []
for i in range(1, m + 1):
	if i % 2 == 0:
		ch += [i]
	else:
		nech += [i]
line = []
for i in range(n):
	line += [[]]
for i in range(n):
	for j in range(n):
		if i < n // 2:
			if j < n // 2 - i or j > n // 2 + i:
				line[i] += [ch[-1]]
				ch.pop()
			else:
				line[i] += [nech[-1]]
				nech.pop()
		elif i == n // 2:
			line[i] += [nech[-1]]
			nech.pop()
		else:
			i1 = n - i - 1
			if j < n // 2 - i1 or j > n // 2 + i1:
				line[i] += [ch[-1]]
				ch.pop()
			else:
				line[i] += [nech[-1]]
				nech.pop()
for i in range(n):
	print(' '.join(map(str, line[i])))


n = int(input())
t = n // 2
r = ['0' * (i + 1) + '1' * (t - i - 1) for i in range(t)]
r = [x + '1' + x[::-1] for x in r]
r += ['1' * n] + r[::-1]
a = 1
b = 2
for i in r:
	q = ''
	for j in i:
		if j == '0':
			t = b
			b += 2
		else:
			t = a
			a += 2
		q += str(t) + ' '
	print(q)