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: interview

Starter code:

Solutions:
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())
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())
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())
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)))


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))


'''
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 n2. The sum in each row, 
column and both main diagonals should be odd.
'''

import io
import sys
import time
import random
#~ start = time.clock()
#~ test ='''5
#~ '''

#~ sys.stdin = io.StringIO(test)

n = int(input())
k = n//2
# input is 2k+1

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: # get next even number
         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()
         
#~ dur = time.clock()-start
#~ print("Time:",dur)


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())

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



# Fill the table
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()) #always odd
#takes the shape of an expanding cross
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=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()


#!/usr/bin/env	python
#-*-coding:utf-8 -*-
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