Gerald has n younger brothers and their number happens to be even. One day he bought n^2 candy bags. One bag has one candy, one bag has two candies, one bag has three candies and so on. In fact, for each integer k from 1 to n^2 he has exactly one bag with k candies. 

Help him give n bags of candies to each brother so that all brothers got the same number of candies.


-----Input-----

The single line contains a single integer n (n is even, 2 ≤ n ≤ 100) — the number of Gerald's brothers.


-----Output-----

Let's assume that Gerald indexes his brothers with numbers from 1 to n. You need to print n lines, on the i-th line print n integers — the numbers of candies in the bags for the i-th brother. Naturally, all these numbers should be distinct and be within limits from 1 to n^2. You can print the numbers in the lines in any order. 

It is guaranteed that the solution exists at the given limits.


-----Examples-----
Input
2

Output
1 4
2 3



-----Note-----

The sample shows Gerald's actions if he has two brothers. In this case, his bags contain 1, 2, 3 and 4 candies. He can give the bags with 1 and 4 candies to one brother and the bags with 2 and 3 to the other brother.

Difficulty: EASY
Tags: Implementation

Starter code:

Solutions:
def solve():
	n = int(input())
	mx = [[0] * n for _ in range(n)]
	for i in range(n):
		for j in range(n):
			mx[i][j] = i * n + j + 1
	for i in range(n):
		ans = []
		for j in range(n):
			ans.append(mx[j][(i + j) % n])
		print(*ans)
solve()


n = int(input())
a = [[i, n ** 2 - i + 1] for i in range(1, n ** 2)]
for j in range(0, n ** 2 // 2, n // 2):
	x = a[j:j + n // 2]
	s = []
	for i in range(len(x)):
		s.append(x[i][0])
		s.append(x[i][1])
	print(' '.join(map(str, s)))


user_input = int(input())
candies = user_input ** 2
candy_pairs = []
for i in range(1, candies // 2 + 1):
	candy_pairs.append([i, candies - i + 1])
per_person = len(candy_pairs) // user_input
number = 0
for i in range(user_input):
	for j in range(per_person):
		print(candy_pairs[number][0], candy_pairs[number][1], '', end='')
		number += 1
	print('')


N = int(input())
candies = [x + 1 for x in range(N ** 2)]
sumof_candies_per_person = sum(candies) / N
candies = list(reversed(sorted(candies)))
bags_per_person = []
for i in range(N):
	bags_per_person.append(candies[0:N // 2] + candies[-N // 2:])
	del candies[0:N // 2]
	del candies[-N // 2:]
for bags in bags_per_person:
	for bag in bags:
		print(bag, end=' ')
	print('')


n = int(input())
(m, strt) = (n * n, 1)
for i in range(n):
	for j in range(n // 2):
		print(m, end=' ')
		m -= 1
		print(strt, end=' ')
		strt += 1
	print()


n = int(input())
for i in range(1, n ** 2 // 2 + 1):
	print(i, n ** 2 - (i - 1))


n = int(input())
for i in range(n):
	for j in range(n):
		if j == 0:
			a = i + 1
			print(a, end=' ')
		elif i == j - 1:
			a = a + 2 * n - 1
			print(a, end=' ')
		else:
			a = a + n - 1
			print(a, end=' ')
	print('\n')


brothers = int(input())
vals = []
for i in range(0, brothers):
	vals.append('')
setLength = brothers * 2
setCount = int(brothers / 2)
for i in range(0, brothers):
	for j in range(0, setCount):
		print(i + setLength * j + 1, (j + 1) * setLength - i, '', end='')
	print()


n = int(input())
k = 1
for i in range(0, n):
	for j in range(0, n // 2):
		print(k, end=' ')
		print(n * n + 1 - k, end=' ')
		k += 1
	print(' ')


_ = int(input())
b = _ ** 2
le = list(range(1, b + 1))
r = 0
l = _ ** 2 - 1
f = []
for i in range(1, _ ** 2 + 1):
	if i & 1:
		print(le[r], end=' ')
		r += 1
	else:
		print(le[l], end=' ')
		l -= 1
	if i % _ == 0:
		print()


def read():
	inputs = input().strip()
	return list(map(int, inputs.split()))

def read_pair():
	return map(int, input().split(' '))
n = int(input())
z = 1
mid = n * n
for i in range(n):
	for j in range(n // 2):
		print(z, mid, end=' ')
		z += 1
		mid -= 1
	print()


n = int(input())
end = n * n
total = end * (end + 1) / 2
div = total / n
l1 = []
for i in range(1, end + 1):
	l1.append(i)
n = len(l1)
for i in range(int(n / 2)):
	print(l1[i], l1[n - 1 - i])


def main():
	n = int(input())
	n_2 = n * n
	output = ''
	for x in range(n):
		k_list = []
		for j in range(int(n / 2)):
			number = int(x * (n / 2) + 1 + j)
			k_list.append(number)
			k_list.append(n_2 - number + 1)
		k_list.sort()
		k_list = [str(number) for number in k_list]
		print(' '.join(k_list))
main()


from sys import stdin, stdout
input = stdin.readline
n = int(input())
res = [[0] * n for _ in range(n)]
for i in range(n * n):
	if i // n % 2 == 0:
		res[i % n][i // n] = str(i + 1)
	else:
		res[n - i % n - 1][i // n] = str(i + 1)
for i in res:
	stdout.write(' '.join(i) + '\n')


n = int(input())
for (i, j) in zip(range(1, n * n // 2 + 1), range(n * n, n * n // 2, -1)):
	print(i, ' ', j)


n = int(input())
l = 1
r = n ** 2
k = 0
while k < n:
	for i in range(n // 2):
		print(l, r, end=' ')
		l += 1
		r -= 1
	print()
	k += 1


x = int(input())
y = x ** 2
i = 0
j = 0
a = 1
number = []
while i < x:
	while j < x / 2:
		number.append(a)
		number.append(y)
		a += 1
		y -= 1
		j += 1
		if j >= x / 2:
			j = 0
			print(' '.join(map(str, number)))
			number = []
			break
	i += 1


n = int(input())
x = n * n
a = [i for i in range(1, x + 1)]
for i in range(n):
	j = 1
	while j <= n // 2:
		print(a[0], a[-1], end=' ')
		a.pop(0)
		a.pop(-1)
		j += 1
	print()


n = int(input())
a = 1
b = n * n
for i in range(n):
	for j in range(n // 2):
		print(a, end=' ')
		a += 1
	for j in range(n // 2):
		print(b, end=' ')
		b -= 1
	print()


n = int(input())
m = n * n
d = m // n
a = 1
b = m
l = []
while a < b:
	l.append(a)
	l.append(b)
	a = a + 1
	b = b - 1
	if len(l) == d:
		print(*l)
		l.clear()


n = int(input())
m = n // 2
for i in range(n):
	for x in range(1 + m * i, 1 + m * (i + 1)):
		print(x, end=' ')
	for x in range(1 + n * n - m * (i + 1), 1 + n * n - m * i):
		print(x, end=' ')
	print()


n = int(input())
print('\n'.join([' '.join(map(str, [n // 2 * i + j + 1 for j in range(n // 2)] + [n ** 2 - n // 2 * i - j for j in range(n // 2)])) for i in range(n)]))


def main():
	n = int(input())
	for i in range(1, n + 1):
		ans = [n * x + i if x % 2 == 0 else n * (x + 1) - i + 1 for x in range(n)]
		print(' '.join(map(str, ans)))
main()


x = int(input())
l = 1
s = [[0 for n in range(x)] for n in range(x)]
for n in range(x):
	if n % 2 != 1:
		for k in range(x):
			s[k][n] = l
			l += 1
	else:
		for k in range(x - 1, -1, -1):
			s[k][n] = l
			l += 1
for n in s:
	print(*n)


n = int(input())
candies = list(range(1, n ** 2 + 1))
j = len(candies) - 1
k = 0
for i in range(0, n):
	out = [0] * n
	for x in range(n // 2):
		out[x] = candies[k]
		k += 1
	for x in range(n - 1, n // 2 - 1, -1):
		out[x] = candies[j]
		j -= 1
	print(*out)


N = int(input())
L = 1
M = N ** 2
for i in range(N):
	for j in range(N // 2):
		print(L, end=' ')
		L += 1
	for k in range(N // 2):
		print(M, end=' ')
		M -= 1
	print('')


def main():
	n = int(input())
	results = [[0 for _ in range(n)] for __ in range(n)]
	number = 1
	for col in range(n):
		starting_row = number // n
		for row in range(starting_row, n):
			results[row][col] = number
			number += 1
		for row in range(starting_row):
			results[row][col] = number
			number += 1
	for row in results:
		print(' '.join([str(value) for value in row]))
main()


import math
n = int(input())
count1 = [0 for i in range(n ** 2 // 2)]
count2 = [0 for i in range(n ** 2 // 2)]
count1[0] = 1
count1[1] = n ** 2
for i in range(n ** 2 // 2):
	if i > 1:
		if i % 2 == 0:
			count1[i] = count1[i - 2] + 2
		else:
			count1[i] = count1[i - 2] - 2
	if i % 2 == 0:
		count2[i] = 1 + count1[i]
	else:
		count2[i] = count1[i] - 1
print(' '.join(map(str, count1)))
print(' '.join(map(str, count2)))


x = int(input())
buffer = 2
for i in range(1, int(x ** 2 / 2) + 1):
	print('{:d} {:d} '.format(i, x ** 2 + 1 - i), end='')
	if buffer % x == 0:
		print()
	buffer += 2


n = int(input())
n = n ** 2
m = 1
while m < n:
	print('{0} {1}'.format(m, n))
	m += 1
	n -= 1


def candy_bags():
	brothers = int(input())
	bags = [i for i in range(1, brothers ** 2 + 1)]
	all_brothers = [[] for i in range(brothers)]
	for i in range(len(all_brothers)):
		for j in range(int(brothers / 2)):
			all_brothers[i].append(bags[0])
			all_brothers[i].append(bags[-1])
			bags.pop()
			bags.pop(0)
		output = str(all_brothers[i][0])
		for x in range(1, len(all_brothers[i])):
			output += ' ' + str(all_brothers[i][x])
		print(output)
candy_bags()


n = int(input())
l = []
for i in range(1, n * n // 2 + 1):
	l.append(i)
	l.append(n * n - i + 1)
for i in range(n):
	print(*l[i * n:(i + 1) * n])


loop = int(input())
usage = []
for i in range(1, loop ** 2 + 1):
	usage.append(str(i))
k = 0
d = len(usage) - 1
for i in range(loop):
	finals = ''
	for j in range(int(loop / 2)):
		finals += usage[k]
		finals += ' '
		k += 1
	for j in range(int(loop / 2)):
		finals += usage[d]
		finals += ' '
		d -= 1
	print(finals)


n = int(input())
k = n ** 2 + 1
for i in range(n * n // 2):
	if i != k - i:
		print(i + 1, k - (i + 1))


n = int(input())
bags = n ** 2
i = 1
result = str()
for k in range(n):
	for l in range(n):
		if l < n // 2:
			result += str(i) + ' '
			i += 1
		else:
			result += str(bags) + ' '
			bags -= 1
	result = result.rstrip() + '\n'
print(result)


from math import ceil

def main():
	n = int(input())
	z = [i for i in range(1, n ** 2 + 1)]
	for i in range(ceil(n ** 2 / 2)):
		print(z[i], z[n ** 2 - i - 1])
main()


n = int(input())
res1 = []
res2 = []
c = 0
for i in range(1, n * n + 1, 2):
	if c & 1:
		res2.append(i)
		res2.append(n * n + 1 - i)
	else:
		res1.append(i)
		res1.append(n * n + 1 - i)
	c += 1
print(*res1)
print(*res2)


class CodeforcesTask334ASolution:

	def __init__(self):
		self.result = ''
		self.n = 0

	def read_input(self):
		self.n = int(input())

	def process_task(self):
		rr = 1 + self.n ** 2
		for x in range(self.n):
			candies = []
			for y in range(self.n // 2):
				candies.append(self.n // 2 * x + y + 1)
				candies.append(rr - self.n // 2 * x - 1 - y)
			print(' '.join([str(z) for z in candies]))

	def get_result(self):
		return self.result
Solution = CodeforcesTask334ASolution()
Solution.read_input()
Solution.process_task()
print(Solution.get_result())


n = int(input())
B = []
a = 1
for i in range(0, n):
	A = []
	for j in range(0, n):
		A.append(a)
		a = a + 1
	B.append(A)
C = []
for k in range(0, n):
	D = []
	b = 0
	c = k
	for l in range(0, n):
		D.append(B[b][c])
		b = b + 1
		c = c + 1
		if c >= n:
			c = 0
	C.append(D)
for x in range(0, n):
	s = ''
	for y in range(0, n):
		s = s + str(C[x][y]) + ' '
	print(s)


n = int(input())
p1 = 1
p2 = n * n
for i in range(n):
	for j in range(int(n // 2)):
		print(p1, end=' ')
		print(p2, end=' ')
		p1 += 1
		p2 -= 1
	print()


import itertools as ittls
from collections import Counter
import string

def sqr(x):
	return x * x

def inputarray(func=int):
	return map(func, input().split())
N = int(input())
s = [None] * N
for i in range(N):
	for j in range(N):
		(_, x) = divmod(i - j + N, N)
		s[j] = j * N + x + 1
	print(' '.join(map(str, s)))


n = int(input())
m = n ** 2
out = ['{} {}'.format(i, m - i + 1) for i in range(1, m // 2 + 1)]
print('\n'.join(out))


n = int(input())
sqN = n ** 2
for i in range(n):
	for j in range(i * int(n / 2) + 1, (i + 1) * int(n / 2) + 1):
		print(j, sqN - j + 1, end=' ')
	print()


n = int(input())
n = n * n
a = [str(x) + ' ' + str(n + 1 - x) for x in range(1, n // 2 + 1)]
for i in a:
	print(i)


n = int(input())
total = n ** 2 * (n ** 2 + 1) // 2
target = total // n
arr = [i for i in range(1, n ** 2 + 1)]
k = 0
l = n ** 2 - 1
for i in range(n):
	for j in range(k, k + n // 2):
		print(arr[j], end=' ')
	k = k + n // 2
	for j in range(l, l - n // 2, -1):
		print(arr[j], end=' ')
	l = l - n // 2
	print()


import math
n = int(input())
bags = int(math.pow(n, 2))
n_bags = []
for j in range(n):
	n_bags.append('')
	for i in range(int(n / 2)):
		n_bags[j] += str(i * n + j + 1)
		n_bags[j] += ' '
		n_bags[j] += str(bags - (j + i * n))
		n_bags[j] += ' '
	print(n_bags[j])


n = int(input())
l = []
r = 1
for i in range(n):
	j = 0
	l1 = []
	while j < n:
		l1.append(r)
		r += 1
		j += 1
	l.append(l1)
for i in range(n):
	if i % 2 == 1:
		l[i].reverse()
for i in range(n):
	for j in range(n):
		print(l[j][i], '', end='')
	print()


n = int(input())
b = [*range(1, n ** 2 + 1)]
l = len(b)
for i in range(n):
	print(*b[i:l // 2:n], end=' ')
	print(*b[-1 - i:-1 - l // 2:-n])


n = int(input())
for i in range(n):
	a = []
	for j in range(n):
		if j < n / 2:
			a.append(n * j + i + 1)
		else:
			a.append(n * (j + 1) - i)
	print(' '.join([str(x) for x in a]))


n = int(input())
for x in range(1, n + 1):
	candies = []
	for y in range(n // 2):
		a = n * y + x
		candies.append(str(a))
		candies.append(str(n ** 2 + 1 - a))
	print(' '.join(candies))


import math, fractions, collections
n = int(input())
each = pow(n, 2) + 1
for i in range(1, n + 1):
	print(i, each - i, end=' ')
	for j in range(i + n, each // 2 + 1, n):
		print(j, each - j, end=' ')
	print()


import os
import sys
from io import BytesIO, IOBase
from collections import Counter
from collections import deque
import heapq
import math

def sin():
	return input()

def ain():
	return list(map(int, sin().split()))

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

def iin():
	return int(sin())
MAX = float('inf')
MIN = float('-inf')

def main():
	n = iin()
	l = []
	x = 1
	y = n ** 2
	for i in range(n):
		p = []
		for _ in range(n // 2):
			p.append(x)
			x += 1
		for _ in range(n // 2):
			p.append(y)
			y -= 1
		l.append(p)
	for p in l:
		print(*p)
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')
main()


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


n = int(input())
sq = n * n
for i in range(0, sq // 2):
	print(i + 1, sq - i, sep=' ')


n = int(input())
a = int(n ** 2 + 1)
t = 1
for i in range(1, n + 1):
	for j in range(int(n / 2) - 1):
		print('%d %d' % (t, a - t), end=' ')
		t += 1
	print('%d %d' % (t, a - t))
	t += 1


n = int(input().strip())
candyBags = list(range(1, n ** 2 + 1))
while len(candyBags) > 1:
	partial = []
	while len(partial) < n:
		partial.append(candyBags.pop(0))
		partial.append(candyBags.pop())
	print(*partial)


n = int(input())
for i in range(n * n // 2):
	if (i + 1) * 2 % n != 0:
		print(i + 1, n * n - i, end=' ')
	else:
		print(i + 1, n * n - i)


brothers = int(input())
candy_bags = brothers ** 2
candies = list(range(1, candy_bags + 1))
c = brothers // 2
for _ in range(brothers):
	print(*candies[:c] + candies[-c:])
	candies = candies[c:-c]


n = int(input())
maxBorder = n * n
for i in range(1, n + 1):
	border = n
	j = i
	while border <= maxBorder:
		border += n
		print(j, end=' ')
		j += n + 1
		if j > border:
			j -= n
	print()


t = int(input())
for i in range(1, t + 1):
	n = t ** 2 - i + 1
	l = []
	x = i
	for j in range(t // 2):
		l.append(n)
		l.append(x)
		n = n - t
		x = x + t
	print(*l)


n = int(input())
total = n ** 2
no = 1
for i in range(1, n + 1):
	for j in range(n // 2):
		print(no, total - no + 1, end=' ')
		no += 1
	print()


n = int(input())
(t1, t2) = (1, n ** 2)
for i in range(0, n):
	for j in range(0, n, 2):
		print(t1, t2, sep=' ', end=' ')
		t1 += 1
		t2 -= 1
	print('')


N = int(input())
left = 1
right = N * N
ans = []
for i in range(N):
	temp = []
	for j in range(N // 2):
		temp.append(left)
		left += 1
		temp.append(right)
		right -= 1
	ans.append(temp)
for line in ans:
	print(' '.join(map(str, line)))


n = int(input())
a = n // 2
cnt = 1
for i in range(n):
	c = list(range(cnt, cnt + a)) + list(range(n * n - cnt - a + 2, n * n - cnt + 1 + 1))
	print(*c)
	cnt += a


n = int(input())
l = 1
r = n * n
ans = [[] for i in range(n)]
j = 0
while l < r:
	ans[j % n].append(l)
	ans[j % n].append(r)
	l += 1
	r -= 1
	j += 1
for i in range(n):
	print(*ans[i])


n = int(input())
(l, r) = (1, n * n)
while l < r:
	c = 0
	while c < n // 2:
		print(l, r, end=' ')
		l += 1
		r -= 1
		c += 1
	print()


n = int(input())
a = [int(i) for i in range(1, n * n + 1)]
b = a[:round(n * n / 2)]
c = a[round(n * n / 2):]
c = c[::-1]
for i in range(n):
	for i in range(round(n / 2)):
		print(b.pop(0), c.pop(0), end=' ')
	print()


n = int(input())
miss = 0
for i in range(n):
	line = list()
	for j in range(n):
		line.append(str(j * n + (j + miss) % n + 1))
	miss += 1
	print(' '.join(line))


n = int(input())
for g in range(pow(n, 2) // 2):
	print(g + 1, pow(n, 2) - g)


n = int(input())
s = 0
(a, b) = ([], [])
for i in range(1, n ** 2 // 2 + 1):
	b.append(i)
for j in range(n ** 2, n ** 2 // 2, -1):
	a.append(j)
for i in range(len(a)):
	print(a[i], b[i])


n = int(input())
n2 = n * n + 1
ndiv2 = n // 2
for i in range(1, n + 1):
	first = list(range(ndiv2 * (i - 1) + 1, ndiv2 * i + 1))
	last = [n2 - k for k in first]
	candies = first + last
	print(' '.join(map(str, candies)))


n = int(input())
m = n * n
a = 1
while m > a:
	print(a, m)
	a += 1
	m -= 1


n = int(input())
candies = []
for pair in zip(range(1, n * n // 2 + 1), range(n * n, 0, -1)):
	candies.extend(pair)
	if len(candies) == n:
		print(*candies)
		candies.clear()


n = int(input())
ans = [[0] * n for i in range(n)]
cnt = 1
for j in range(n):
	if j % 2 == 0:
		for i in range(n):
			ans[i][j] = cnt
			cnt += 1
	else:
		for i in range(n - 1, -1, -1):
			ans[i][j] = cnt
			cnt += 1
for i in ans:
	print(*i)


import sys

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

def iinput():
	return int(input())

def rinput():
	return map(int, sys.stdin.readline().strip().split())

def get_list():
	return list(map(int, sys.stdin.readline().strip().split()))
n = iinput()
a = [i for i in range(1, n ** 2 + 1)]
b = list(reversed(a))
i = 1
while i <= n ** 2 // 2:
	ans = []
	for j in range(i, i + n // 2):
		ans.append(a[j - 1])
	for j in range(i, i + n // 2):
		ans.append(b[j - 1])
	ans.sort()
	print(*ans)
	i += n // 2


n = int(input())
l = 0
h = n * n + 1
for i in range(n):
	for j in range(n // 2):
		l = l + 1
		h = h - 1
		print(l, h, end=' ')
	print('\n')


n = int(input())
d = n ** 2
for i in range(1, d):
	print(i, d)
	d = d - 1
	if i == d:
		break


n = int(input())
x = 1
y = n * n
s = ''
for i in range(n):
	for j in range(n // 2):
		s += str(x) + ' ' + str(y) + ' '
		x += 1
		y -= 1
	print(s)
	s = ''


n = int(input())
t = n ** 2
step = n // 2
for x in range(n):
	l = [str(_ + 1) for _ in range(step * x, step * (x + 1))] + [str(_) for _ in range(t - step * x, t - step * (x + 1), -1)]
	print(' '.join(l))


import sys
import math
import bisect

def transpose(A):
	n = len(A)
	B = []
	for i in range(n):
		B.append([0] * n)
	for i in range(n):
		for j in range(n):
			B[i][j] = A[j][i]
	return B

def solve(n):
	A = []
	for i in range(n):
		A.append([0] * n)
	for i in range(n):
		for j in range(n):
			A[i][j] = i * n + j + 1
	for i in range(n):
		if i % 2 == 1:
			A[i] = A[i][::-1]
	return transpose(A)

def main():
	ans = solve(int(input()))
	for i in range(len(ans)):
		print(' '.join(list((str(a) for a in ans[i]))))
main()


brother = int(input())

def main():
	candybag = []
	for x in range(0, pow(brother, 2)):
		candybag.append(x)
		candybag[x] = x + 1
	for x in range(0, int(pow(brother, 2) / 2)):
		print(candybag[x], candybag[len(candybag) - 1 - x])
main()


n = int(input())
part = n * (1 + n * n) // 2
bags = [1] * (n * n)
k = n // 2
for i in range(0, n * n):
	bags[i] += i
rev_bags = bags[::-1]
for i in range(0, n):
	print(' '.join((str(s) for s in bags[i * k:(i + 1) * k] + rev_bags[i * k:(i + 1) * k])))


n = int(input())
for i in range(1, int(n * n / 2) + 1, int(n / 2)):
	c = 0
	while c < int(n / 2):
		print(i, int(n * n) - i + 1, end=' ')
		c += 1
		i += 1
	print()


t = int(input())
a = []
for i in range(1, t * t + 1):
	a.append(i)
c = 0
b = []
for j in range(len(a) // 2):
	b.append(int(a[j]))
	b.append(int(a[len(a) - 1 - j]))
	c = c + 1
	if c == t / 2:
		print(*b)
		c = 0
		b = []


t = int(input())
low = 1
high = t ** 2
i = 0
high_index = high
low_index = 1
for _ in range(t):
	for h in range(t // 2):
		print(high_index, end=' ')
		high_index -= 1
	for j in range(t // 2):
		print(low_index, end=' ')
		low_index += 1
	print(' ')


n = int(input())
a = []
for i in range(1, n ** 2 + 1):
	a.append(i)
ans = []
for i in range(n):
	ans.append([])
for i in range(1, n ** 2 + 1, n):
	for j in range(i, i + n):
		ans[j - i].append(j)
	ans = list(ans[n - 1:]) + list(ans[0:n - 1])
for item in ans:
	print(item[0], end='')
	for i in range(1, n):
		print(' ' + str(item[i]), end='')
	print('')


n = int(input())
candy_bags = n ** 2
a = list(range(1, candy_bags + 1))
each_person = candy_bags // (2 * n)
for i in range(n):
	astr = ''
	for j in range(each_person):
		astr += '{} {} '.format(a.pop(0), a.pop())
	print(astr)


n = int(input())
l = n * n + 1
k = 1
for i in range(n):
	row = []
	for j in range(n // 2):
		row.append(str(k))
		row.append(str(l - k))
		k += 1
	print(' '.join(row))


from sys import stdout
n = int(input())
for j in range(n):
	for i in range(j + 1, n ** 2 // 2 + 1, n):
		stdout.write('%d ' % i)
	for x in range(n // 2 + 1, n + 1):
		stdout.write('%d ' % (n * x - j))
	stdout.write('\n')


n = int(input())
head = 1
tail = n * n
for _ in range(n):
	for i in range(n // 2):
		print(head + i, tail - i, end=' ')
	head += n // 2
	tail -= n // 2


from sys import stdout
n = int(input())
f = [1 + i * (n + 1) for i in range(n)]
print(*f)
for i in range(1, n):
	for j in range(n):
		if f[j] + i > (j + 1) * n:
			stdout.write(str(f[j - 1] + i + 1) + ' ')
		else:
			stdout.write(str(f[j] + i) + ' ')
	stdout.write('\n')


import sys
input = sys.stdin.readline
from operator import mul
from functools import reduce

def inp():
	return int(input())

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

def insr():
	s = input()
	return list(s[:len(s) - 1])

def invr():
	return map(int, input().split())

def main():
	n = inp()
	list1 = []
	for i in range(n * n // 2):
		list1.append(i + 1)
		list1.append(n * n - i)
	cnt = 0
	for i in range(n):
		for j in range(n):
			print(list1[i * n + j], end=' ')
		print()
main()


n = int(input())
x = n ** 2
output = []
current = 0
for i in range(x // 2):
	output.append(i + 1)
	output.append(x - i)
	current += 2
	if current == n:
		print(' '.join((str(i) for i in output)))
		current = 0
		output = []


from copy import copy
n = int(input())
b = n * (1 + n ** 2) // 2

def new(x, l):
	if x == 0:
		return ([], l)
	for i in l:
		g = copy(l)
		g.remove(i)
		g.reverse()
		if i <= x:
			b = new(x - i, g)
			return ([i] + b[0], b[1])
h = list(range(1, n ** 2 + 1))
h.reverse()
while h:
	(a, h) = new(b, h)
	print(*a)


n = int(input())
aux = []
for i in range(n):
	aux.append(n * [0])
a = 1
for i in range(n // 2):
	for j in range(n):
		aux[j][i] = a
		a += 1
for i in range(n // 2, n):
	for j in range(n - 1, -1, -1):
		aux[j][i] = a
		a += 1
for i in range(n):
	print(' '.join(map(str, aux[i])))


n = int(input())
m = n * n
l = [i for i in range(1, m + 1)]
ne = sum(l) // n
while len(l) > 0:
	print(l[0], l[len(l) - 1])
	l.pop()
	l.pop(0)


n = int(input())
l = list(range(1, n + 1))
c = 1
for i in range(n):
	l = []
	for j in range(n // 2):
		l.append('{0} {1} '.format(c, n ** 2 - c + 1))
		c += 1
	print(''.join(l))


n = int(input())
d = {}
for i in range(n):
	d[i + 1] = []
for j in range(n):
	left = j * n + 1
	right = (j + 1) * n
	if j % 2 == 0:
		for k in range(left, right + 1):
			d[k - j * n].append(k)
	else:
		for k in range(left, right + 1):
			d[n + 1 - (k - j * n)].append(k)
for key in d:
	print(*d[key])


n = int(input())
m = n // 2
N = n ** 2 + 1
for i in range(n):
	for j in range(i * m + 1, i * m + m + 1):
		print(j, N - j, end='')
		if j == i * m + m:
			print()
		else:
			print(' ', end='')


w = int(input())
for i in range(w * w // 2):
	print(i + 1, w * w - i)


import math
n = int(input())
candylist = []
for i in range(1, n ** 2 + 1):
	candylist.append(i)
for i in range(n):
	for k in range(n // 2):
		print(candylist[0], end=' ')
		if k != n // 2 - 1:
			print(candylist[len(candylist) - 1], end=' ')
		else:
			print(candylist[len(candylist) - 1])
		candylist.pop(0)
		candylist.pop(len(candylist) - 1)


num_brothers = int(input())
candies_brothers = [[0] * num_brothers for dummy in range(num_brothers)]
for bag in range(num_brothers):
	if bag % 2 == 0:
		for brother in range(num_brothers):
			candies_brothers[brother][bag] = bag * num_brothers + brother + 1
	else:
		for brother in range(0, num_brothers):
			candies_brothers[brother][bag] = (bag + 1) * num_brothers - brother
for brother in candies_brothers:
	print(' '.join(map(str, brother)))


n = int(input())
i = 1
n **= 2
while i < n:
	print(i, n, sep=' ')
	i += 1
	n -= 1


from collections import deque
num = int(input())
arr = deque((i for i in range(1, num ** 2 + 1)))
cases = len(arr) // 2
pairs = []
while cases:
	cases -= 1
	pairs.append([arr.popleft(), arr.pop()])
for i in range(num):
	temp = []
	while len(temp) < num:
		temp.extend(pairs.pop())
	print(*temp)


n = int(input())
total = n * n + 1
j = 1
for i in range(n):
	while j <= n * n // 2:
		for k in range(n // 2):
			print(j, total - j, sep=' ', end=' ')
			j += 1
		print()
		break


n = int(input())
for i in range(n):
	j = 1
	ans = []
	for k in range(n):
		ans.append(j + (i + k) % n)
		j += n
	print(' '.join(map(str, ans)))


n = int(input())
(l, r) = (1, n * n)
for i in range(n):
	for j in range(int(n / 2)):
		print(l, end=' ')
		l = l + 1
	for j in range(int(n / 2)):
		print(r, end=' ')
		r = r - 1
	print()


n = int(input())
c = 0
for i in range(n):
	for j in range(n // 2):
		print(c + 1, n * n - c)
		c += 1


n = int(input())
k = n * n
i = 1
while i < k:
	print(f'{i} {k}')
	i += 1
	k -= 1


import time, math
from sys import stdin, stdout

def I():
	return int(stdin.readline())

def In():
	return map(int, stdin.readline().split())

def L():
	return list(map(int, stdin.readline().split()))

def Si():
	return sorted(list(map(int, stdin.readline().split())))

def Si():
	return sorted(list(map(int, stdin.readline().split())), reverse=True)

def P(x):
	return stdout.write(str(x))

def Pi(x, y):
	return stdout.write(str(x) + ' ' + str(y) + ' ')

def solve():
	n = I()
	k = 1
	for i in range(1, n + 1, 1):
		for j in range(0, n // 2):
			Pi(k, n * n - k + 1)
			k += 1
		P('\n')
solve()


n = int(input())
a = 1
b = n * n
for i in range(n):
	x = n
	while x > 0:
		print(a, b, end=' ')
		a += 1
		b -= 1
		x -= 2
	print()


n = int(input())
r = [str(i) for i in range(1, n * n + 1)]
rr = [r.pop() for i in range(n * n // 2)]
for i in range(n):
	s = ''
	for ii in range(n // 2):
		s += r.pop() + ' ' + rr.pop() + ' '
	print(s)


n = int(input())
bags = []
for i in range(1, n ** 2 + 1):
	bags.append(i)
brothers = []
for i in range(n):
	brothers.append([])
i = 0
while i < int(n / 2):
	j = 0
	while j < n:
		brothers[j].append(bags[0])
		brothers[j].append(bags[-1])
		bags.pop(0)
		bags.pop()
		j = j + 1
	i = i + 1
for brother in brothers:
	s = ''
	for bag in brother:
		s += str(bag) + ' '
	print(s)


import sys
from functools import reduce
from collections import Counter
import time
import datetime
from math import sqrt, gcd

def ip():
	return int(sys.stdin.readline())

def sip():
	return sys.stdin.readline()

def mip():
	return map(int, sys.stdin.readline().split())

def mips():
	return map(str, sys.stdin.readline().split())

def lip():
	return list(map(int, sys.stdin.readline().split()))

def matip(n, m):
	lst = []
	for i in range(n):
		arr = lip()
		lst.append(arr)
	return lst

def factors(n):
	return list(set(reduce(list.__add__, ([i, n // i] for i in range(1, int(n ** 0.5) + 1) if n % i == 0))))

def minJumps(arr, n):
	jumps = [0 for i in range(n)]
	if n == 0 or arr[0] == 0:
		return float('inf')
	jumps[0] = 0
	for i in range(1, n):
		jumps[i] = float('inf')
		for j in range(i):
			if i <= j + arr[j] and jumps[j] != float('inf'):
				jumps[i] = min(jumps[i], jumps[j] + 1)
				break
	return jumps[n - 1]

def dic(arr):
	return Counter(arr)

def check_prime(n):
	if n < 2:
		return False
	for i in range(2, int(n ** 0.5) + 1, 2):
		if n % i == 0:
			return False
	return True
n = ip()
z = n * n
count = 1
for i in range(n):
	arr = []
	for i in range(n // 2):
		arr.append(count)
		arr.append(z)
		count += 1
		z -= 1
	print(*arr)


n = int(input())
for i in range(n):
	for j in range(n):
		print(1 + j * n + (i + j) % n, end=' ')
	print()


n = int(input())
(l, h) = (1, n ** 2)
for i in range(n):
	s = ''
	for j in range(n // 2):
		s += str(l) + ' ' + str(h) + ' '
		l += 1
		h -= 1
	print(s)


import math
alph = 'abcdefghijklmnopqrstuvwxyz'
n = int(input())
p = n ** 2
d = 1
for i in range(n):
	for j in range(n // 2):
		print(d, p - d + 1, end=' ')
		d += 1
	print()


n = int(input())
li = [[] for _ in range(n)]
for i in range(1, n * n // 2 + 1):
	li[(i - 1) % n] += [i, n * n - i + 1]
for line in li:
	print(*line)


n = int(input())
(start, endi) = (1, n * n)
for i in range(n):
	for j in range(int(n / 2)):
		print(start, endi, end=' ')
		start = start + 1
		endi = endi - 1
	print()


import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 6)

def in_int():
	return int(input())

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

def in_str():
	s = input()
	return list(s[:len(s) - 1])

def in_ints():
	return map(int, input().split())
mod = 7 + 10 ** 9
n = in_int()
l = 1
h = n ** 2
while l < h:
	for xx in range(n // 2):
		print(l, h, end=' ')
		l += 1
		h -= 1
	print()


n = int(input())
l = [x for x in range(1, n ** 2 + 1)]
for x in range(0, n ** 2 // 2, n // 2):
	k1 = l[x:x + n // 2]
	k2 = l[len(l) - x - n // 2:len(l) - x]
	print(*k1, *k2)


n = int(input())
bags = [i for i in range(1, n * n + 1)]
totalCandy = (1 + n * n) * (n * n) / 2
splitCandy = totalCandy / n
bagList = [[] for i in range(n)]
bagNum = 0
for i in range(int(n * n / 2)):
	bagList[bagNum].append(bags[i])
	bagList[bagNum].append(bags[n * n - i - 1])
	if sum(bagList[bagNum]) == splitCandy:
		print(*bagList[bagNum])
		bagNum += 1


n = int(input())
a = []
b = []
n = n ** 2
for i in range(1, n // 2 + 1):
	if i % 2:
		a.append(i)
		a.append(n - i + 1)
	else:
		b.append(i)
		b.append(n - i + 1)
print(*a)
print(*b)


def __starting_point():
	N = int(input())
	st = 1
	en = N * N
	for i in range(N):
		for j in range(N // 2):
			print(st, end=' ')
			st += 1
			print(en, end=' ')
			en -= 1
		print()
__starting_point()


import sys
input = sys.stdin.readline

def inp():
	return int(input())

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

def insr():
	s = input()
	return list(s[:len(s) - 1])

def invr():
	return map(int, input().split())
n = inp()
perHead = n // 2 * (n * n + 1)
ans = [[0 for i in range(n)] for j in range(n)]
curr = 1
for j in range(n):
	if j % 2 == 0:
		for i in range(n):
			ans[i][j] = curr
			curr += 1
	else:
		for i in range(n - 1, -1, -1):
			ans[i][j] = curr
			curr += 1
for i in range(n):
	print(*ans[i])


n = int(input())
k = 1
while k <= n ** 2 / 2:
	print(k, n ** 2 - k + 1)
	k = k + 1


(n, m) = (int(input()), [])
for i in range(n):
	m.append([0] * n)
if n % 2 == 0:
	for j in range(n):
		for i in range(n):
			m[i][j] = n * j + (n - i if j % 2 == 1 else i + 1)
else:
	(px, py, v) = (0, n // 2, 1)
	while v <= n * n:
		if m[px][py] != 0:
			px = (px + 1) % n
		m[px][py] = v
		(v, px, py) = (v + 1, px - 1, py + 1)
		px = px if px >= 0 else n - 1
		py = py if py <= n - 1 else 0
for i in range(n):
	print(*m[i])


n = int(input())
arr = [x for x in range(1, n * n + 1)]
i = 0
j = len(arr) - 1
while i < j:
	for _ in range(n // 2):
		print(arr[i], end=' ')
		print(arr[j], end=' ')
		i += 1
		j -= 1
	print()


def main():
	n = int(input())
	n_2 = n // 2
	nn = n * n
	print('\n'.join((' '.join((' '.join(map(str, [i + j, nn - (i - 1) - j])) for j in range(n_2))) for i in range(1, nn // 2 + 1, n_2))))
main()


n = int(input())
n2 = n * n
ans = list()
for i in range(1, n2 // 2 + 1):
	ans.append(str(i))
	ans.append(' ')
	ans.append(str(n2 - i + 1))
	ans.append(' ' if i // 2 % n else '\n')
print(''.join(ans))


a = int(input())
b = [''] * a
for i in range(a * a):
	if i // a % 2:
		b[i % a] += str(i + 1) + ' '
	else:
		b[a - i % a - 1] += str(i + 1) + ' '
print('\n'.join(b))


whichBro = int(input())
candyPerBro = int((whichBro ** 3 + whichBro) / 2)
for i in range(1, whichBro + 1):
	sum = 0
	j = i
	while sum < candyPerBro:
		print(str(j) + ' ' + str(whichBro * whichBro + 1 - j) + ' ', end='')
		sum += j
		sum += whichBro * whichBro - j + 1
		j += whichBro
	print()


n = int(input())
goal = n * (n ** 2 + 1) // 2
x = 1
y = n ** 2
flag = True
turn = 1
for i in range(n ** 2):
	if flag:
		print(x, end=' ')
		x += 1
	else:
		print(y, end=' ')
		y -= 1
	if turn % n == 0:
		print()
	flag = not flag
	turn += 1


n = int(input())
ans = [x for x in range(1, n * n + 1)]
for i in range(n * n // 2):
	print(ans[i], ans[n * n - i - 1])


n = int(input())
(k, N) = (n // 2, n ** 2)
for i in range(n):
	for j in range(1, k + 1):
		num = k * i + j
		print(num, N - num + 1, end=' ')
	print()


n = int(input())
pairs = []
for i in range(1, int(n * n / 2 + 1)):
	pairs.append([i, n * n - (i - 1)])
for i in range(n):
	for j in range(int(n / 2)):
		print(pairs[int(i * (n / 2) + j)][0], end=' ')
		print(pairs[int(i * (n / 2) + j)][1], end=' ')
	print()


n = int(input())
a = [i for i in range(1, n ** 2 + 1)]
ans = [[]] * n
for i in range(0, n ** 2, n):
	for j in range(n // 2):
		print(a[j + i], end=' ')
		print(a[::-1][j + i], end=' ')
	print('')


n = int(input())
for i in range(n):
	for j in range(n // 2):
		s = 2 * n * j + i + 1
		e = 2 * n * j + (2 * n - i)
		print(s, e, end=' ')
	print()


n = int(input())
starting = 1
ending = n * n
for _ in range(n):
	print(*[starting + i if i < n // 2 else ending + i - n + 1 for i in range(n)])
	starting += n // 2
	ending -= n // 2


numberBrother = int(input())
numberSet = int(numberBrother / 2)
start = 1
end = int(numberBrother ** 2)
count = 0
while count != numberBrother:
	holder = []
	for counter in range(numberSet):
		holder.append(start)
		holder.append(end)
		start += 1
		end -= 1
	count += 1
	print(*holder, sep=' ')


n = int(input())
i = 1
f = n ** 2
m = 1
M = n ** 2
for k in range(n):
	i = 1
	mensaje = ''
	while i <= n / 2:
		mensaje = mensaje + str(m) + ' ' + str(M) + ' '
		m += 1
		M = M - 1
		i += 1
	print(mensaje)


n = int(input())
n2 = n ** 2
for i in range(n2 // 2):
	print('%d %d' % (i + 1, n2 - i))


n = int(input())
z = 1
k = pow(n, 2)
p = n
while n != 0:
	c = [0 for i in range(p)]
	for i in range(len(c)):
		if i % 2 == 0:
			c[i] = z
			z += 1
		else:
			c[i] = k
			k -= 1
	print(*c)
	n -= 1


n = int(input())
n2 = n ** 2
a = [[] for i in range(n)]
t = 0
for i in range(int(n2 / n)):
	for x in range(n):
		t += 1
		a[x if i % 2 else n - x - 1].append(str(t))
for r in a:
	print(' '.join(r))


n = int(input())
a = int(n * n / 2)
(i, j) = (1, n * n)
while i <= a and j >= a:
	print(i, j)
	(i, j) = (i + 1, j - 1)


n = int(input())
A = []
for i in range(1, n ** 2 + 1):
	A.append(i)
l = n * n
i = 0
for _ in range(n):
	for p in range(n // 2):
		print(A[i], A[l - i - 1], end=' ')
		i += 1
	print()


n = int(input())
arr = [i for i in range(1, n ** 2 + 1)]
temp = []
(start, end) = (0, len(arr) - 1)
while start < end:
	temp.append(arr[start])
	temp.append(arr[end])
	if sum(temp) == sum(arr) / n:
		print(' '.join((str(i) for i in temp)))
		temp = []
	start += 1
	end -= 1


from sys import stdin

def main():
	n = int(stdin.readline().strip())
	l = [0] * n
	nn = n * n
	for i in range(1, n + 1):
		for (j, k) in zip(range(0, n, 2), range(i, i + nn // 2, n)):
			l[j] = k
			l[j + 1] = nn - k + 1
		print(*l)
main()


n = int(input())
p = n * (n ** 2 + 1) // 2
arr = [k for k in range(1, n ** 2 + 1)]
m = n // 2
for i in range(n):
	print(*arr[m * i:m * (i + 1)], *arr[n ** 2 - m * (i + 1):n ** 2 - m * i], sep=' ')


n = int(input())
arr = [i for i in range(1, n ** 2 + 1)]
arr1 = []
for i in range(len(arr) // 2):
	arr1.append(str(arr[i]))
	arr1.append(str(arr[0 - (i + 1)]))
s = 0
e = n
while True:
	print(' '.join(arr1[s:e]))
	s = e
	e = s + n
	if e > n ** 2:
		break


n = int(input())
p = 1
q = n ** 2
for i in range(n):
	for j in range(n // 2):
		print(p, q, end=' ')
		p += 1
		q -= 1
	print()


import sys
fin = sys.stdin

class problem:

	def init(self):
		pass

	def read_input(self):
		self.n = int(fin.readline())

	def write_output(self):
		pass

	def solve(self):
		res = [[] for i in range(self.n)]
		for i in range(self.n ** 2 // 2):
			res[i % self.n] += [i + 1, self.n ** 2 - i]
		for r in res:
			print(' '.join(map(str, r)))

def main():
	p = problem()
	p.init()
	p.read_input()
	p.solve()
	p.write_output()
main()


n = int(input())
s = ''
lis = []
for i in range(1, n * n + 1):
	lis.append(i)
t = 1
i = 0
j = len(lis)
a = int(n / 2)
b = int(j - n / 2)
while t <= n:
	s1 = lis[i:a]
	s2 = lis[b:j]
	i = int(i + n / 2)
	a = int(a + n / 2)
	b = int(b - n / 2)
	j = int(j - n / 2)
	res = s1 + s2
	for p in res:
		print(p, end=' ')
	print()
	t += 1


n = int(input())
a_n = [[0 for j in range(n)] for i in range(n)]
t = 1
for i in range(n):
	for j in range(n):
		a_n[i][j] = t
		t += 1
for i in range(n):
	o = 0
	for j in range(n):
		print(a_n[j][(i + o) % n], end=' ')
		o += 1
	print()


n = int(input())
i = 1
while True:
	if i > n ** 2 - i + 1:
		break
	print(i, n ** 2 - i + 1)
	i += 1


n = int(input())
li = [i for i in range(1, n ** 2 + 1)]
j = []
ans = []
count = 0
k = []
for i in range(0, n ** 2 // 2):
	j.append([li[i], li[-i - 1]])
for i in j:
	k += i
	count += 1
	if count == n // 2:
		ans.append(k)
		k = []
		count = 0
for i in ans:
	print(*i)


n = int(input())
a = [[0] * n for i in range(n)]
for i in range(n):
	p = []
	for j in range(n):
		p.append(n * i + j + 1)
	for j in range(n):
		a[j][i] = p[(i + j) % n]
for i in range(n):
	print()
	for j in range(n):
		print(a[i][j], end=' ')


def main():
	n = int(input())
	bags = n * n
	lb = 1
	rb = bags
	while lb < rb:
		print(lb, rb)
		lb += 1
		rb -= 1
	return
main()


import math
from collections import defaultdict, Counter, deque
INF = float('inf')

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

def primeFactor(n):
	if n % 2 == 0:
		return 2
	i = 3
	while i ** 2 <= n:
		if n % i == 0:
			return i
		i += 1
	return n

def main():
	n = int(input())
	s = n * (n ** 2 + 1) // 2
	arr = [i for i in range(1, n ** 2 + 1)]
	pairs = []
	i = 0
	j = len(arr) - 1
	while i < j:
		pairs.append([arr[i], arr[j]])
		i += 1
		j -= 1
	i = 0
	s = n // 2
	while i < len(pairs):
		for p in pairs[i:i + s]:
			print(*p, end=' ')
		print()
		i += s
t = 1
for _ in range(t):
	main()


n = int(input())

def restar2(L):
	for k in range(len(L)):
		L[k] = str(int(L[k]) - len(L))

def sumar2(L):
	for k in range(len(L)):
		L[k] = str(int(L[k]) + len(L))

def string(L):
	for k in range(len(L)):
		L[k] = str(L[k])
	return L
L = [k for k in range(1, n // 2 + 1)]
L1 = [n ** 2 - k for k in range(n // 2)]
for j in range(n):
	s = string(L1)
	r = string(L)
	print(' '.join(r + s))
	sumar2(L)
	restar2(L1)


import sys
n = int(sys.stdin.readline())
n2 = n ** 2
for i in range(int(n2 / 2)):
	print(str(i + 1) + ' ' + str(n2 - i))


x = int(input())
for i in range(x):
	t = i + 1
	print(i + 1, end=' ')
	for j in range(x - 1):
		if j % 2 == 0:
			t = t + 2 * x - (2 * i + 1)
			print(t, end=' ')
		else:
			t = t + 2 * i + 1
			print(t, end=' ')
	print()


n = int(input())
list = []
for i in range(n):
	list.append([])
x = 1
for i in range(n // 2):
	for l in list:
		l.append(x)
		x += 1
	for l in list[::-1]:
		l.append(x)
		x += 1
for l in list:
	for i in l:
		print(str(i) + ' ', end='')
	print()


x = int(input())
sq = x ** 2
c = 0
a = 1
for i in range(x):
	xx = ''
	for j in range(x // 2):
		xx += str(a) + ' '
		a += 1
	for j in range(x // 2):
		xx += str(sq - c) + ' '
		c += 1
	print(xx)


n = int(input())
ans = []
i = 1
nn = n * n
for _ in range(n):
	s = []
	for _ in range(n // 2):
		s += [str(i)]
		s += [str(nn - i + 1)]
		i += 1
	ans += [' '.join(s)]
print('\n'.join(ans))


number_of_brothers = int(input())
total_bags = number_of_brothers * number_of_brothers
for i in range(number_of_brothers):
	for j in range(1, number_of_brothers // 2 + 1):
		one_bag = number_of_brothers // 2 * i + j
		print(one_bag, total_bags - one_bag + 1, end=' ')
	print('')


n = int(input())
c = [[] for _ in range(n)]
for i in range(0, n ** 2 // 2):
	c[i % n].append(i + 1)
	c[i % n].append(n ** 2 - i)
for e in c:
	e.sort()
	print(*e)


brother = eval(input())
candybag = brother ** 2
totalcandy = 0
n = 1
while n <= candybag:
	totalcandy = n + totalcandy
	n = n + 1
avercan = totalcandy / brother
smallcan = 1
largecan = n - 1
smalloop = 1
largeloop = n - 1
line = brother / 2
n = brother
while n > 0:
	while line > 0:
		print(smalloop, largeloop, ' ', end='')
		smalloop = smalloop + brother
		largeloop = largeloop - brother
		line = line - 1
	line = brother / 2
	smallcan = smallcan + 1
	smalloop = smallcan
	largecan = largecan - 1
	largeloop = largecan
	print()
	n = n - 1


n = int(input())
i = 0
while i + 1 < n * n - i:
	print(str(i + 1) + ' ' + str(n * n - i))
	i += 1


x = int(input())
y = x ** 2
p = 1
for i in range(x):
	for j in range(0, x // 2):
		print(p, y, end=' ')
		p += 1
		y -= 1
	print('')


def solve(n):
	start = 1
	end = n * n
	halfN = n // 2
	while n:
		line = ''
		i = 0
		while i < halfN:
			line += str(start) + ' '
			start += 1
			i += 1
		i = 0
		while i < halfN:
			line += str(end) + ' '
			end -= 1
			i += 1
		n -= 1
		print(line)
n = int(input())
solve(n)


n = int(input())
left = 1
right = n ** 2
for i in range(n):
	for j in range(n // 2):
		print(left, right, end=' ')
		(left, right) = (left + 1, right - 1)
	print()


n = int(input())
l = list(range(1, n ** 2 + 1))
for i in range(int(len(l) / 2)):
	if i == 0:
		print(str(l[i]) + ' ' + str(l[-1:][0]))
	else:
		print(str(l[i]) + ' ' + str(l[(i + 1) * -1:][0]))


n = int(input())
a = []
for i in range(1, n ** 2 + 1):
	a.append(i)
ans = []
for i in range(0, n ** 2 // 2, n // 2):
	put = []
	for j in range(i, i + n // 2):
		put.append(a[j])
		put.append(a[len(a) - 1 - j])
	ans.append(put)
for i in range(len(ans)):
	for j in range(0, n):
		print(ans[i][j], end=' ')
	print()


import sys, threading, os.path
import collections, heapq, math, bisect
import string
from platform import python_version
import itertools
sys.setrecursionlimit(10 ** 6)
threading.stack_size(2 ** 27)

def main():
	if os.path.exists('input.txt'):
		input = open('input.txt', 'r')
	else:
		input = sys.stdin
	n = int(input.readline())
	sol = []
	x = 1
	for i in range(n):
		templis = []
		for j in range(int(n / 2)):
			templis.append(x)
			x += 1
		sol.append(templis)
	x = pow(n, 2)
	res = ''
	for i in range(n):
		for j in range(int(n / 2)):
			sol[i].append(x)
			x -= 1
		for v in sol[i]:
			res += str(v) + ' '
		if i + 1 < n:
			res += '\n'
	output = res
	if os.path.exists('output.txt'):
		open('output.txt', 'w').writelines(str(output))
	else:
		sys.stdout.write(str(output))
main()


n = int(input()) ** 2
a = [i for i in range(1, n + 1)]
(i, j) = (0, n - 1)
while i < j:
	print(a[i], a[j])
	i += 1
	j -= 1


import math, string, itertools, fractions, heapq, collections, re, array, bisect, sys, random, time, copy, functools
sys.setrecursionlimit(10 ** 7)
inf = 10 ** 20
eps = 1.0 / 10 ** 10
mod = 10 ** 9 + 7
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1)]

def LI():
	return [int(x) for x in sys.stdin.readline().split()]

def LI_():
	return [int(x) - 1 for x in sys.stdin.readline().split()]

def LF():
	return [float(x) for x in sys.stdin.readline().split()]

def LS():
	return sys.stdin.readline().split()

def I():
	return int(sys.stdin.readline())

def F():
	return float(sys.stdin.readline())

def S():
	return input()

def pf(s):
	return print(s, flush=True)

def main():

	def f(n):
		t = sum(range(1, n ** 2 + 1)) // n
		u = set()
		ta = [[] for _ in range(n)]
		for i in range(1, n ** 2 + 1):
			ti = (i - 1) % n
			if (i - 1) // n % 2 == 1:
				ti = n - ti - 1
			ta[ti].append(i)
		for i in range(n):
			r = ta[i]
			if sum(r) != t:
				print(i, t, sum(r))
				return None
		return ta
	n = I()
	rr = f(n)
	return '\n'.join(map(lambda x: ' '.join(map(str, x)), rr))
print(main())


n = int(input())
bags = n * n
arr = [[0] * n for x in range(n)]
i = 1
r = 0
c = 0
direction = 1
while i < bags:
	if direction:
		while r < n:
			arr[r][c] = i
			r += 1
			i += 1
		direction ^= 1
	else:
		while r > 0:
			arr[r - 1][c] = i
			r -= 1
			i += 1
		direction ^= 1
	c += 1
for row in arr:
	for col in row:
		print(col, end=' ')
	print()


n = int(input())
a = [[]] * n
b = list(range(1, n ** 2 + 1))
for i in range(0, n, 2):
	a[i] = b[:n]
	b = b[n:]
	a[i + 1] = b[:n][::-1]
	b = b[n:]
for i in range(n):
	print(*[t[i] for t in a])


n = int(input())
count = 1
for i in range(n):
	line = []
	for j in range(n // 2):
		line.append('{0} {1} '.format(count, n ** 2 - count + 1))
		count += 1
	print(''.join(line))


import sys
n = int(sys.stdin.readline())
bags = [i for i in range(1, n * n + 1)]
i = 0
j = n * n - 1
for b in range(n * (n // 2)):
	print(bags[i], bags[j])
	i += 1
	j -= 1


n = int(input())
m = n // 2
c = 0
if n == 1:
	print(1, 1)
for i in range(n):
	for j in range(m):
		print(c + 1, n * n - c, end=' ')
		c = c + 1
	print()


n = int(input())
print(*[' '.join(map(str, list(range(n // 2 * i + 1, n // 2 * (i + 1) + 1)) + list(range(n * n - n // 2 * (i + 1) + 1, n * n - n // 2 * i + 1)))) for i in range(n)], sep='\n')


n = int(input())
c = 1
d = n ** 2
for i in range(0, n):
	r = []
	for j in range(0, n // 2):
		r.append(c)
		r.append(d)
		c += 1
		d -= 1
	print(*r)


n = int(input())
arr1 = [x for x in range(1, n * n + 1)]
arr2 = [x for x in range(n * n, 0, -1)]
k = 0
for i in range(n):
	s = ''
	for j in range(n // 2):
		s += str(arr1[k * n // 2 + j]) + ' '
	for j in range(n // 2):
		s += str(arr2[k * n // 2 + j]) + ' '
	print(s)
	k += 1


n = int(input())
a = list(range(1, n ** 2 + 1))
m = 0
for i in range(len(a) // 2):
	print(a[i], a[len(a) - 1 - i], end=' ')
	m += 1
	if m == n // 2:
		m = 0
		print('\n')


n = int(input())
s = []
for i in range(0, n, 2):
	s.append([])
	for j in range(n):
		s[-1].append(i * n + j + 1)
for i in range(1, n, 2):
	s.append([])
	for j in range(n - 1, -1, -1):
		s[-1].append(i * n + j + 1)
for i in range(n):
	res = ''
	for j in range(n):
		res += str(s[j][i]) + ' '
	print(res)


n = int(input())
(x, y, a, b) = (1, n // 2 + 1, n * n, n * n - n // 2)
for i in range(n):
	for j in range(x, y):
		print(j, end=' ')
	x += n // 2
	y += n // 2
	for k in range(a, b, -1):
		print(k, end=' ')
	print()
	a -= n // 2
	b -= n // 2


a = int(input())
b = [*range(1, a * a + 1)]
(j, k) = (0, a * a)
for i in range(a):
	print(*b[j:j + a // 2], *b[k - a // 2:k])
	j = j + a // 2
	k = k - a // 2


n = int(input())
for i in range(n):
	l = []
	for j in range(n):
		x = n * j
		if (i + j + 1) % n == 0:
			z = n
		else:
			z = (i + j + 1) % n
		y = x + z
		l.append(y)
	print(*l)


n = int(input())
li = [i for i in range(1, n * n + 1)]
(index_start, index_end) = (0, n * n - 1)
for i in range(n):
	for j in range(n // 2):
		print(li[index_start], end=' ')
		print(li[index_end], end=' ')
		index_start += 1
		index_end -= 1
	print('')


n = int(input())
offset = int(n / 2)
list = []
front = 1
last = n * n
for i in range(n):
	for j in range(offset):
		print(front, end=' ')
		front += 1
	for j in range(offset):
		print(last, end=' ')
		last -= 1
	print()


import sys
n = int(input())
a = [[] for i in range(n)]
for i in range(int(n ** 2 / 2)):
	a[i % n].append(i + 1)
for i in range(int(n ** 2), int(n ** 2 / 2), -1):
	a[(n - i) % n].append(i)
for i in a:
	for k in i:
		print(k, end=' ')
	print()


z = int(input())
lst = []
for t in range(z):
	lst.append([])
a = 0
for i in range(1, z ** 2 + 1):
	lst[a].append(i)
	if i % z == 0:
		a += 1
		if a > z // 2:
			lst[a - 1].reverse()
for i in range(z):
	for e in lst:
		print(e[i], end=' ')
	print()


n = int(input())
a = [i for i in range(1, n ** 2 + 1)]
right = 0
left = n ** 2 - 1
for i in range(1, n ** 2 + 1):
	if i % 2 == 1:
		print(a[right], end=' ')
		right += 1
	else:
		print(a[left], end=' ')
		left -= 1
	if i % n == 0:
		print()


n = int(input())
(t, p) = (list(range(1, n ** 2 + 1)), [])
for i in range(n):
	x = i * n
	p += t[x + n - i:x + n] + t[x:x + n - i]
for i in range(n):
	print(' '.join((str(p[j * n + i]) for j in range(n))))


n = int(input())
bratia = [[] for i in range(n + 1)]
smer = 1
for sada in range(n):
	for i in range(n):
		i += 1
		cukrikov = sada * n + i
		bratia[smer * i].append(cukrikov)
	smer *= -1
for brat in bratia[1:]:
	print(' '.join(map(str, brat)))


N = int(input())
if N % 2 == 0:
	bags = [[] for i in range(N)]
	mid = N * N // 2
	for i in range(mid):
		bags[i % N].append(mid + i + 1)
		bags[i % N].append(mid - i)
	for bag in bags:
		print(*bag)
else:
	count = (N - 1) // 2
	mid = (N * N + 1) // 2
	LHS = (N + 1) // 2
	RHS = N - LHS
	S = (N + 1) * (2 * N + 1) // 6
	bags = [[] for i in range(count)]
	for i in range(count):
		LS = LHS * ((mid - i - 1 + (mid - i - 1 - (N - 1) * (LHS - 1))) // 2)
		for j in range(LHS):
			bags[i].append(mid - i - 1 - (N - 1) * j)
		for j in range(RHS // 2):
			bags[i].append(N * N - i, S - LS - N * N + i)
	print(bags)


n = int(input())
res = []
for i in range(1, n ** 2 // 2 + 1):
	res.extend([i, n ** 2 + 1 - i])
	if i % (n // 2) == 0:
		for r in res:
			print(r, end=' ')
		print()
		res = []


n = int(input())
n2 = n * n
inc = int(n / 2)
for i in range(0, n * inc, inc):
	for j in range(1, int(n2 / n / 2) + 1):
		print(i + j, end=' ')
		print(n2 - j - i + 1, end=' ')
	print()


a = int(input())
b = a * a
k = 0
n = 1
m = a ** 2
z = 0
for i in range(a):
	p = []
	while k < m:
		p.append(n)
		n = n + 1
		k = k + 1
		if k == a // 2:
			k = 0
			break
	while k < m:
		p.append(m - z)
		z = z + 1
		k = k + 1
		if k == a // 2:
			k = 0
			break
	s = str(p[0])
	for i in range(1, len(p)):
		s = s + ' ' + str(p[i])
	print(s)


n = int(input())
for i in range(1, n + 1):
	a = [i]
	for j in range(1, n):
		if a[-1] == n * j:
			a.append(a[-1] + 1)
		else:
			a.append(a[-1] + n + 1)
	print(*a)


n = int(input())
l = []
for i in range(1, n ** 2 + 1):
	l.append((i, n ** 2 - i + 1))
for j in range(n):
	for i in range(n // 2):
		print(*l[0], end=' ')
		l.remove(l[0])
	print()


n = int(input())
mtx = []
for i in range(1, n + 1):
	v = [i for i in range((i - 1) * n + 1, (i - 1) * n + n + 1)]
	mtx.append(v)
for i in range(0, n):
	for j in range(0, n):
		print(mtx[j][(j + i) % n], end=' ')
	print('')


n = int(input())
l = [str(x) + ' ' + str(n ** 2 - x + 1) for x in range(1, n ** 2 // 2 + 1)]
for i in range(0, n ** 2 // 2, n // 2):
	print(' '.join(l[i:i + n // 2]))


import sys
n_bags = int(sys.stdin.readline())
candies = []
total = 0
for (i, value) in enumerate(range(n_bags ** 2)):
	total += value + 1
	candies.append(value + 1)
values = []
(start, end) = (0, len(candies) - 1)
while start <= end:
	values.append([])
	values[len(values) - 1].append(candies[start])
	values[len(values) - 1].append(candies[end])
	start += 1
	end -= 1
target = total // n_bags
n_bags_each = target // (values[0][0] + values[0][1])
for i in range(0, len(values), n_bags_each):
	for j in range(n_bags_each):
		sys.stdout.write(str(values[i + j][0]) + ' ')
		sys.stdout.write(str(values[i + j][1]) + ' ')
	print('')


n = int(input()) ** 2
for x in range(1, n // 2 + 1):
	print(x, n - x + 1)


inp = int(input())
for i in range(inp * inp // 2):
	print(str(i + 1) + ' ' + str(inp ** 2 - i))


n = int(input())
L = [[] for _ in range(n)]
j = 0
z = 1
for i in range(1, n * n + 1):
	L[j] += [i]
	j += z
	if j == n:
		j -= 1
		z = -z
	if j == -1:
		j += 1
		z = -z
for i in range(n):
	for x in L[i]:
		print(x, end=' ')
	print()


n = int(input())
nums = [i for i in range(1, n ** 2 + 1)]
bro1 = []
i = 0
j = len(nums) - 1
while i != j and i < j:
	bro1.append(nums[i])
	bro1.append(nums[j])
	i += 2
	j -= 2
bro2 = []
i = 1
j = len(nums) - 2
while i != j and i < j:
	bro2.append(nums[i])
	bro2.append(nums[j])
	i += 2
	j -= 2
for num in bro1:
	print(num, end=' ')
print('')
for num in bro2:
	print(num, end=' ')


def single_integer():
	return int(input())

def multi_integer():
	return map(int, input().split())

def string():
	return input()

def multi_string():
	return input().split()
n = single_integer()
t = n ** 2
ans = list()
for i in range(t):
	ans.append((i + 1, t - i))
i = 0
while i < t // 2:
	for k in range(i, i + n // 2):
		print(*ans[k], end=' ')
	i += n // 2
	print()


from sys import stdin
n = int(stdin.readline().rstrip())
s = 0
l = []
for i in range(1, n * n + 1):
	l.append(i)
for i in range(n * n // 2):
	print(str(l[i]) + ' ' + str(l[n * n - 1 - i]))


n = int(input())
for i in range(n):
	temp = []
	for j in range(i * n // 2, (i + 1) * n // 2):
		temp.append(j + 1)
		temp.append(n ** 2 - j)
	print(' '.join((str(temp[k]) for k in range(n))))


n = int(input())
(n2, count) = (n ** 2 + 1, 1)
for i in range(n):
	for j in range(n // 2):
		print(count, n2 - count, end=' ')
		count += 1
	print(end='\n')


n = int(input().strip())
i = 1
j = n ** 2
while i < j:
	arr = [i, j]
	for x in range(n // 2 - 1):
		i += 1
		j -= 1
		arr.append(i)
		arr.append(j)
	i += 1
	j -= 1
	print(*arr)


def get_candies(n):
	result = []
	bags = list(range(1, n ** 2 + 1))
	for i in range(n):
		each = []
		for times in range(int(n / 2)):
			each.append(bags[0])
			each.append(bags[-1])
			bags = bags[1:len(bags) - 1]
		each.sort()
		result.append(each)
	return result

def main():
	n = int(input())
	result = get_candies(n)
	for i in range(len(result)):
		string = ''
		for value in result[i]:
			string += str(value)
			string += ' '
		print(string)
main()


n = int(input())
i = 1
j = n ** 2
while i < j:
	print(i, j)
	i += 1
	j -= 1


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


n = input()
n = int(n)
n2 = n ** 2
for i in range(1, int(n2 / 2) + 1, 2):
	for j in range(i, i + 2):
		print('{one} {two} '.format(one=j, two=n2 - j + 1), end='')
	print()


n = int(input())
arr = []
j = 1
for i in range(n):
	arr.append([])
	for _ in range(n):
		arr[i].append(j)
		j += 1
k = 0
s_set = []
for i in range(n):
	s = ''
	for j in range(n):
		s += str(arr[j][(j + k) % n]) + ' '
	k += 1
	s_set.append(s)
for s in s_set:
	print(s)


n = int(input())
l = []
for i in range(1, n ** 2 + 1):
	l.append(i)
while len(l) != 0:
	for i in range(n // 2):
		print(l[0], l[-1], end=' ')
		l.remove(l[0])
		l.remove(l[-1])
	print('')


x = int(input())
for i in range(x ** 2 // 2):
	print(i + 1, x ** 2 - i)


n = int(input())
a = [int(x) for x in range(1, n ** 2 + 1)]
b = []
for i in range(0, n ** 2 // 2, n // 2):
	c = []
	for h in range(i, i + n // 2):
		c.append(a[h])
		c.append(a[len(a) - 1 - h])
	b.append(c)
for i in range(len(b)):
	print(' '.join((str(x) for x in b[i])))


n = int(input())
l = list(range(1, n ** 2 + 1))
(s, e) = (0, n ** 2 - 1)
for _ in range(n):
	print(*l[s:s + n // 2], *l[e - n // 2 + 1:e + 1])
	s += n // 2
	e -= n // 2


n = int(input())
first = 1
m = first
last = n * n
h = last
for i in range(n):
	while first < last:
		print(first, last, end=' ')
		first += n
		last -= n
	first = m + 1
	m = first
	last = h - 1
	h = last
	print()


num = int(input())
arr = [x for x in range(1, num ** 2 + 1)]
for x in range(len(arr) // 2):
	print(arr[x], arr[~x])


n = int(input())
fair = n * n * (n * n + 1) / (2 * n)
bro = [[] for i in range(n)]
upwards = True
for i in range(0, n * n):
	if upwards:
		bro[i % n].append(i + 1)
	else:
		bro[(-i - 1) % n].append(i + 1)
	if i % n == n - 1:
		upwards = not upwards
for b in bro:
	print(' '.join(map(str, b)))


n = int(input())
p = [str(i) for i in range(1, n ** 2 + 1)]
res = []
for i in range(n):
	(l1, l2) = (p[:n // 2], p[len(p) - n // 2:])
	res.append(l1 + l2)
	p = p[n // 2:len(p) - n // 2]
for x in res:
	print(' '.join(x))


n = int(input())
square = [[i for i in range(i, n * n + 1, n)] for i in range(1, n + 1)]
start = [0, 0]
for _ in range(n):
	(a, b) = start
	for i in range(n):
		print(square[a % n][b % n], end=' ')
		a += 1
		b += 1
	print()
	start[0] += 1


n = int(input())
i = 1
j = n ** 2
while i <= n:
	k = 0
	while k < n // 2:
		print(k * n + i, end=' ')
		k = k + 1
	k = 0
	while k < n // 2:
		print(-k * n + j, end=' ')
		k = k + 1
	print()
	i = i + 1
	j = j - 1


n = int(input())
ans = 0
res = pow(n, 2) // 2
i = 1
j = n ** 2
while i <= res and j >= res:
	print(i, j)
	i += 1
	j -= 1


n = int(input())
cnt1 = 1
cnt2 = n ** 2
arr = []
for i in range(n * n // 2):
	arr.append([cnt1, cnt2])
	cnt1 += 1
	cnt2 -= 1
for i in range(0, len(arr), n // 2):
	for j in range(n // 2):
		print(arr[i + j][0], arr[i + j][1], sep=' ', end=' ')
	print('')


n = int(input())
numbers = [x for x in range(1, n ** 2 + 1)]
start = 0
end = n ** 2 - 1
while start < end:
	print(numbers[start], numbers[end])
	start += 1
	end -= 1


n = input()
n = int(n)
bags = range(n * n)
coord = []
for _ in range(n):
	coord.append((_, _))
for _ in range(n):
	for (x, y) in coord:
		if x is 0:
			print(bags[x * n + (y + _) % n] + 1, end='')
		else:
			print(' ', bags[x * n + (y + _) % n] + 1, sep='', end='')
	print()


n = int(input())
d = [i for i in range(1, pow(n, 2) + 1)]
total = (pow(n, 2) + 1) * n // 2
for i in range(n - 1):
	t = 0
	ans = []
	while t < n - 1:
		if t % 2 == 0:
			ans.append(d.pop(0))
		else:
			ans.append(d.pop())
		t += 1
	z = sum(ans)
	ans.append(total - z)
	d.remove(total - z)
	print(*ans)
print(*d)


a = int(input())
k = a ** 2
half = int(a / 2)
sweets = [x for x in range(1, k + 1)]
for x in range(a):
	print(*sweets[:half], *sweets[-half:])
	sweets[:half] = []
	sweets[-half:] = []


from itertools import permutations
from collections import defaultdict
from math import *
import os
import sys
from io import BytesIO, IOBase
from heapq import nlargest
from bisect import *
import copy
import itertools
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))

def input():
	return sys.stdin.readline().rstrip('\r\n')
n = int(input())
lp = n * n
fp = 1
for i in range(n):
	for i in range(n // 2):
		print(fp, end=' ')
		fp += 1
	for i in range(n // 2):
		print(lp, end=' ')
		lp -= 1
	print()


n = int(input())
bags = []
for i in range(1, n * n + 1):
	bags.append(i)
for i in range(n):
	out = ''
	for j in range(n // 2):
		out += str(bags.pop()) + ' ' + str(bags.pop(0)) + ' '
	print(out[:-1])


w = int(input())
l = []
for x in range(1, int(w ** 2) // 2 + 1):
	l.append(str(x))
	l.append(str(int(w ** 2) + 1 - x))
for x in range(0, int(w ** 2), w):
	a = ' '.join(l[x:x + w])
	print(a)


n = int(input())
p = n ** 2
x = list(range(1, int(p / 2) + 1))
y = list(reversed(range(int(p / 2) + 1, p + 1)))
zipped = zip(x, y)
for (i, k) in zipped:
	print(i, k)


from sys import stdin, stdout
import math
from itertools import permutations, combinations
from collections import defaultdict
from bisect import bisect_left

def L():
	return list(map(int, stdin.readline().split()))

def In():
	return map(int, stdin.readline().split())

def I():
	return int(stdin.readline())
P = 1000000007
n = I()
arr = [[] for i in range(n)]
i = 1
while i <= n * n:
	for j in range(n):
		arr[j].append(i)
		i += 1
	for j in range(n - 1, -1, -1):
		arr[j].append(i)
		i += 1
for i in range(n):
	for j in range(n):
		print(arr[i][j], end=' ')
	print()


n = int(input())
t = [i for i in range(1, n ** 2 + 1)]
a = t[0:len(t) // 2]
b = t[len(t) // 2:][::-1]
l = n // 2
m = n ** 2
for k in range(0, l * n, l):
	print(*a[k:k + n // 2] + b[k:k + n // 2])


x = int(input())
y = x ** 2
z = y // 2
c = [int(i) for i in range(1, y + 1)]
for i in range(1, x + 1):
	a = []
	b = []
	for i in range(i, z + 1, x):
		a.append(i)
		b.append(i)
	for i in a:
		b.append(y - c.index(i))
	for i in b:
		print(i, end=' ')
	print()


n = int(input())
a = list(range(1, n ** 2 + 1))
for i in range(n ** 2 // 2):
	b = []
	b.append(a[i])
	b.append(a[-(i + 1)])
	c = str(b)
	d = c.replace(',', '')
	print(d[1:-1])


answer = int(input())
w = answer * answer
for o in range(int(answer / 2 * answer)):
	print(o + 1, w - o)


n = int(input())
start = 1
end = n * n
for i in range(1, n + 1):
	bro = []
	for j in range(n // 2):
		bro.append(start)
		start += 1
	for j in range(n // 2):
		bro.append(end)
		end -= 1
	print(' '.join(map(str, bro)))


n = int(input())
i = 1
j = 0
while i < n ** 2 and j < n:
	print(' '.join(map(str, range(i, i + n // 2))), ' '.join(map(str, range(n ** 2 - i + 2 - n // 2, n ** 2 - i + 2))))
	i += n // 2
	j += 1


sa = int(input())
a = []
b = []
for x in range(1, sa ** 2 + 1):
	if x <= sa ** 2 / 2:
		a.append(x)
	else:
		b.append(x)
b.reverse()
maximum = sa
count = 0
string = ''
while len(a) != 0:
	string = ''
	for x in range(int(maximum / 2)):
		string += str(a[0])
		a.remove(a[0])
		string += ' '
		string += str(b[0])
		b.remove(b[0])
		string += ' '
	print(string)


n = int(input())
t = n ** 2
i = 1
a = []
while i <= n:
	a.clear()
	j = i
	while j <= t // 2:
		a.append(j)
		a.append(t - j + 1)
		j += n
	for j in a:
		print(j, end=' ')
	print()
	i += 1


n = int(input())
lists = []
for i in range(n):
	temp = list(range(i * n + 1, (i + 1) * n + 1))
	lists.append(temp)
for x in range(n):
	for z in range(n):
		locx = z % n
		locy = (x + z) % n
		print(lists[locx][locy], end=' ')
	print()


a = int(input())
for i in range(a):
	b = []
	for j in range(a):
		b += [a * j + (j + i) % a + 1]
	print(' '.join(map(str, b)))


n = int(input())
l = list(range(1, n ** 2 + 1))
c = 0
while l != []:
	print(l.pop(0), end=' ')
	print(l.pop(), end=' ')
	c = c + 2
	if c == n:
		print()
		c = 0


n = int(input())
i = 1
j = n * n
while j - i + 1 >= n:
	lst = []
	while len(lst) != n:
		lst.append(str(i))
		lst.append(str(j))
		i = i + 1
		j = j - 1
	print(' '.join(lst))


n = int(input())
seq = []
limit = n ** 2 + 1
bags = n ** 2 // n
for i in range(n):
	s = ''
	for j in range(bags // 2):
		n1 = j + 1 + n * i
		n2 = limit - n1
		s += str(n1) + ' ' + str(n2) + ' '
	seq.append(s)
for i in range(n):
	print(seq[i][:-1])


n = int(input())
b = n ** 2
l = [int(x) for x in range(1, b + 1)]
ar = []
i = 0
j = -1
while i < b // 2:
	ar.append(l[i])
	ar.append(l[j])
	i += 1
	j -= 1
ans = []
i = 0
j = n
while i <= b - n:
	ans.append(ar[i:j])
	i = j
	j += n
i = 0
while i < n:
	j = 0
	while j < n:
		print(ans[i][j], end=' ')
		if j == 3:
			print()
		j += 1
	i += 1


n = input()
n = int(n)
bags = []
for i in range(n ** 2):
	bags.append(i + 1)
start = 0
end = -1
step = int(n / 2)
for i in range(n):
	for j in range(start, start + step):
		print(bags[j], end=' ')
	start += step
	for j in range(end, end - step, -1):
		print(bags[j], end=' ')
	end -= step
	print('')


n = int(input())
t = 1
v = 0
for i in range(n ** 2 // 2):
	print(t, n ** 2 - v)
	t = t + 1
	v = v + 1


n = int(input())
l = []
for i in range(1, n * n + 1):
	l.append(i)
h = n // 2
beg = 0
ending = len(l) - 1
for i in range(n):
	t = beg + h
	while beg < t:
		print(l[beg], end=' ')
		beg += 1
	t = ending - h
	while ending > t:
		print(l[ending], end=' ')
		ending -= 1
	print()


n = int(input())
arr = [i for i in range(0, n ** 2 + 2)]
i = 1
while i <= n ** 2 // 2:
	j = 0
	while j < n // 2:
		print(arr[i], arr[-i - 1], end=' ')
		i += 1
		j += 1
	print()


n = int(input())
matrix = []
turn = 1
for i in range(1, n * n + 1, n):
	if turn == 1:
		matrix.append(list(range(i, i + n)))
		turn = 0
	else:
		matrix.append(list(range(i, i + n))[::-1])
		turn = 1
res = []
col = len(matrix[0])
row = len(matrix)
for i in range(col):
	res.append([matrix[j][i] for j in range(row)])
for row in res:
	print(*row)


n = int(input())
a = 2 * n - 1
b = 1
x = 1
for _ in range(n):
	print(*(x + (i + 1) // 2 * a + i // 2 * b for i in range(n)))
	x += 1
	a -= 2
	b += 2


n = int(input())
ave = (n * n * n + n) / 2
a = [i for i in range(1, n * n + 1)]
for j in range(n):
	for k in range(int(n / 2)):
		print(a.pop(0))
		print(a.pop())


import sys
n = int(sys.stdin.readline())
result = [[] for i in range(n)]
flag = False
for i in range(n ** 2):
	if i % n == 0:
		flag = False if flag else True
	if flag:
		result[i % n].append(i + 1)
	else:
		result[n - 1 - i % n].append(i + 1)
for i in range(n):
	print(' '.join([str(x) for x in result[i]]))


N = int(input())
M = N * N // 2
candies = [[] for i in range(N)]
for i in range(M):
	j = 2 * i // N
	n = M - abs(j - M)
	candies[j].append(i + 1)
	candies[j].append(N * N - i)
for i in range(N):
	print(*candies[i])


n = int(input())
s = int(n * n * (n * n + 1) / 2)
each_gets = s // n
res = []
used = set()
cur = []
for x in range(0, n * n):
	i = n * n - x
	j = each_gets // (n // 2) - i
	if j not in used and i not in used:
		used.add(i)
		used.add(j)
		cur.append(i)
		cur.append(j)
		if len(cur) == n:
			res.append(cur)
			cur = []
for thing in res:
	print(' '.join(map(str, thing)))


n = int(input())
x = [i for i in range(1, n ** 2 + 1)]
for i in range(len(x) // 2):
	print(x[i], x[-i - 1])


n = int(input())
a = (*range(1, n * n + 1),)
k = n // 2
i = 0
for _ in [0] * n:
	print(*a[i:i + k] + a[-i - k:n * n - i])
	i += k


n = int(input())
tmp = n ** 2
j = 1
while tmp > j:
	print(j, tmp)
	j += 1
	tmp -= 1


n = int(input())
nigger = [number for number in range(1, n * n + 1)]
for i in range(1, n + 1):
	print(' '.join(map(str, nigger[:n // 2] + nigger[-n // 2:])))
	nigger = nigger[n // 2:-n // 2]


n = int(input())
l = [''] * n
j = 0
for i in range(1, n * n // 2 + 1):
	l[j] += str(i) + ' '
	j = (j + 1) % n
for i in range(n * n // 2 + 1, n * n + 1):
	l[n - j - 1] += str(i) + ' '
	j = (j + 1) % n
for i in range(n):
	print(l[i])


n = int(input())
for i in range(n):
	off = i + 1
	for j in range(n):
		print(n * j + off, end=' ')
		off += 1
		if off == n + 1:
			off = 1
	print()


import sys, math

def file():
	sys.stdin = open('input.py', 'r')
	sys.stdout = open('output.py', 'w')

def get_array():
	l = list(map(int, input().split()))
	return l

def main():
	n = int(input())
	(a, b) = (1, n ** 2)
	for i in range(n):
		for j in range(math.floor(n // 2)):
			print(a, b, end=' ')
			a += 1
			b -= 1
		print()
main()


n = int(input().strip())
l = [''] * n
j = 0
k = 0
for i in range(1, n ** 2 // 2 + 1):
	j += 1
	l[k] = l[k] + str(i) + ' '
	if j == n // 2:
		j = 0
		k += 1
j = 0
k = 0
for i in range(n ** 2, n ** 2 // 2, -1):
	j += 1
	l[k] = l[k] + str(i) + ' '
	if j == n // 2:
		j = 0
		k += 1
for i in range(n):
	print(l[i])


n = int(input())
total = n ** 2 + 1
cursor = 1
for i in range(n):
	for j in range(n // 2):
		print('{} {}'.format(cursor, total - cursor), end=' ')
		cursor += 1
	print()


inp = int(input())
ls = [i for i in range(1, inp * inp + 1)]
for i in range(0, int(inp * inp / 2), int(inp / 2)):
	for j in range(int(inp / 2)):
		print(ls[j + i], ls[inp * inp - j - 1 - i], end=' ')
	print()


import math
from decimal import *
getcontext().prec = 30
n = int(input())
curr = 1
for i in range(n):
	l = list()
	while len(l) < n:
		l.append(curr)
		l.append(n * n + 1 - curr)
		curr += 1
	print(*l)


n = int(input())
i = 0
a = 1
b = n * n
while i < n:
	j = 0
	while j < n / 2:
		print(a, ' ', end='')
		print(b, ' ', end='')
		a += 1
		b -= 1
		j += 1
	print()
	i += 1


n = int(input())
a = n * n
l = []
for j in range(1, a + 1):
	l.append(j)
m = l.copy()
l.reverse()
k = []
for i in range(int(a / 2)):
	k.append(m[i])
	k.append(l[i])
d = 0
for x in range(n):
	for y in range(n):
		print(k[d], end=' ')
		d += 1
	print()


import sys
x = int(input())
x2 = int(x ** 2)
groups = []
for i in range(int(x2 / 2)):
	groups.append([i + 1, x2 - i])
i = 0
for g in groups:
	sys.stdout.write(str(g[0]) + ' ' + str(g[1]) + ' ')
	i = i + 2
	if i == x:
		sys.stdout.write('\n')
		i = 0


import sys
import time
num_input = int(input())
a = 1
b = num_input * num_input
for i in range(1, num_input + 1):
	for j in range(1, num_input + 1):
		if j % 2 == 1:
			print(a, end=' ')
			a += 1
		else:
			print(b, end=' ')
			b -= 1
	print()