In order to do some research, n^2 labs are built on different heights of a mountain. Let's enumerate them with integers from 1 to n^2, such that the lab with the number 1 is at the lowest place, the lab with the number 2 is at the second-lowest place, …, the lab with the number n^2 is at the highest place.

To transport water between the labs, pipes are built between every pair of labs. A pipe can transport at most one unit of water at a time from the lab with the number u to the lab with the number v if u > v.

Now the labs need to be divided into n groups, each group should contain exactly n labs. The labs from different groups can transport water to each other. The sum of units of water that can be sent from a group A to a group B is equal to the number of pairs of labs (u, v) such that the lab with the number u is from the group A, the lab with the number v is from the group B and u > v. Let's denote this value as f(A,B) (i.e. f(A,B) is the sum of units of water that can be sent from a group A to a group B).

For example, if n=3 and there are 3 groups X, Y and Z: X = \{1, 5, 6\}, Y = \{2, 4, 9\} and Z = \{3, 7, 8\}. In this case, the values of f are equal to:

  * f(X,Y)=4 because of 5 → 2, 5 → 4, 6 → 2, 6 → 4, 
  * f(X,Z)=2 because of 5 → 3, 6 → 3, 
  * f(Y,X)=5 because of 2 → 1, 4 → 1, 9 → 1, 9 → 5, 9 → 6, 
  * f(Y,Z)=4 because of 4 → 3, 9 → 3, 9 → 7, 9 → 8, 
  * f(Z,X)=7 because of 3 → 1, 7 → 1, 7 → 5, 7 → 6, 8 → 1, 8 → 5, 8 → 6, 
  * f(Z,Y)=5 because of 3 → 2, 7 → 2, 7 → 4, 8 → 2, 8 → 4. 



Please, divide labs into n groups with size n, such that the value min f(A,B) over all possible pairs of groups A and B (A ≠ B) is maximal.

In other words, divide labs into n groups with size n, such that minimum number of the sum of units of water that can be transported from a group A to a group B for every pair of different groups A and B (A ≠ B) as big as possible.

Note, that the example above doesn't demonstrate an optimal division, but it demonstrates how to calculate the values f for some division.

If there are many optimal divisions, you can find any.

Input

The only line contains one number n (2 ≤ n ≤ 300).

Output

Output n lines:

In the i-th line print n numbers, the numbers of labs of the i-th group, in any order you want.

If there are multiple answers, that maximize the minimum number of the sum of units of water that can be transported from one group the another, you can print any.

Example

Input


3


Output


2 8 5
9 3 4
7 6 1

Note

In the first test we can divide 9 labs into groups \{2, 8, 5\}, \{9, 3, 4\}, \{7, 6, 1\}.

From the first group to the second group we can transport 4 units of water (8 → 3, 8 → 4, 5 → 3, 5 → 4).

From the first group to the third group we can transport 5 units of water (2 → 1, 8 → 7, 8 → 6, 8 → 1, 5 → 1).

From the second group to the first group we can transport 5 units of water (9 → 2, 9 → 8, 9 → 5, 3 → 2, 4 → 2).

From the second group to the third group we can transport 5 units of water (9 → 7, 9 → 6, 9 → 1, 3 → 1, 4 → 1).

From the third group to the first group we can transport 4 units of water (7 → 2, 7 → 5, 6 → 2, 6 → 5).

From the third group to the second group we can transport 4 units of water (7 → 3, 7 → 4, 6 → 3, 6 → 4).

The minimal number of the sum of units of water, that can be transported from one group to another is equal to 4. It can be proved, that it is impossible to make a better division.

Source: codeforces | Difficulty: EASY
Tags: Greedy algorithms

Implementation

Constructive algorithms


Solutions:
n = int(input())
a = [[] for i in range(n)]
j = 0
k = 1
cnt = 0
for i in range(n):
	for j in range(n):
		cnt += 1
		if i % 2 == 0:
			a[j].append(cnt)
		else:
			a[-j - 1].append(cnt)
for i in range(n):
	print(*a[i])


read = lambda : [int(i) for i in input().split()]
n = int(input())
ans = [[] for _ in range(n)]
for i in range(n * n):
	idx = i % n if i // n % 2 == 0 else n - 1 - i % n
	ans[idx].append(i + 1)
for i in range(n):
	print(' '.join(map(str, ans[i])))


import sys
input = sys.stdin.readline
n = int(input())
if n % 2 == 0:
	for i in range(n):
		for j in range(n // 2):
			print(n // 2 * i + j + 1, end=' ')
		for j in range(n // 2):
			print(n * n - i * (n // 2) - j, end=' ')
		print()
else:
	for i in range(n):
		for j in range(n // 2):
			print(n // 2 * i + j + 1, end=' ')
		for j in range(n // 2):
			print(n * n - n - i * (n // 2) - j, end=' ')
		print(n * n - i, end=' ')
		print()


from collections import defaultdict as dc
from collections import deque as dq
from bisect import bisect_left, bisect_right, insort_left
import sys
import math
mod = 10 ** 9 + 7

def bs(a, x):
	i = bisect_left(a, x)
	if i != len(a) and a[i] == x:
		return i
	else:
		return -1

def inp():
	p = sys.stdin.readline()
	return p

def line():
	p = list(map(int, inp().split()))
	return p

def ans(a, b):
	c = 0
	if a * 2 > b:
		x = b // 2
		b = b % 2
		c = c + x * 2 + x
		a = a - x
	else:
		x = a
		a = 0
		b = b - x * 2
		c = c + x * 2 + x
	return (a, b, c)

def ans1(a, b, c):
	an = 0
	for i in range(0, b + 1, 2):
		an = max(an, ans(a, i)[2] + ans(b - i, c)[2])
	return an
n = int(inp())
a = [[0 for i in range(n)] for i in range(n)]
i = 0
k = 1
while i < n:
	if i % 2 == 0:
		j = 0
		while j < n:
			a[j][i] = k
			k += 1
			j += 1
	else:
		j = n - 1
		while j >= 0:
			a[j][i] = k
			k += 1
			j -= 1
	i += 1
for i in range(n):
	print(*a[i])


n = int(input())
result = []
for i in range(n):
	temp = []
	for j in range(n):
		temp.append(0)
	result.append(temp)
l = 0
r = 0
i = 0
while i < n * n:
	if l == 0:
		while l < n:
			result[l][r] = i + 1
			i += 1
			l += 1
		l -= 1
	else:
		while l >= 0:
			result[l][r] = i + 1
			i += 1
			l -= 1
		l += 1
	r += 1
for i in range(n):
	for j in range(n):
		print(result[i][j], end=' ')
	print('')


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


from collections import deque as de
import math
from sys import stdin, stdout
import re
from collections import Counter as cnt
from functools import reduce
from itertools import groupby as gb
from bisect import bisect_left as bl, bisect_right as br

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

class My_stack:

	def __init__(self):
		self.data = []

	def my_push(self, x):
		return self.data.append(x)

	def my_pop(self):
		return self.data.pop()

	def my_peak(self):
		return self.data[-1]

	def my_contains(self, x):
		return self.data.count(x)

	def my_show_all(self):
		return self.data

	def isEmpty(self):
		return len(self.data) == 0
arrStack = My_stack()

def decimalToBinary(n):
	return bin(n).replace('0b', '')

def binarytodecimal(n):
	return int(n, 2)

def isPrime(n):
	if n <= 1:
		return False
	if n <= 3:
		return True
	if n % 2 == 0 or n % 3 == 0:
		return False
	i = 5
	while i * i <= n:
		if n % i == 0 or n % (i + 2) == 0:
			return False
		i = i + 6
	return True

def get_prime_factors(number):
	prime_factors = []
	while number % 2 == 0:
		prime_factors.append(2)
		number = number / 2
	for i in range(3, int(math.sqrt(number)) + 1, 2):
		while number % i == 0:
			prime_factors.append(int(i))
			number = number / i
	if number > 2:
		prime_factors.append(int(number))
	return prime_factors

def get_frequency(list):
	dic = {}
	for ele in list:
		if ele in dic:
			dic[ele] += 1
		else:
			dic[ele] = 1
	return dic

def Log2(x):
	return math.log10(x) / math.log10(2)

def getProduct(n):
	product = 1
	while n != 0:
		product = product * (n % 10)
		n = n // 10
	return product

def lcm(x, y):
	lcm = x * y // math.gcd(x, y)
	return lcm

def isPowerOfTwo(n):
	return math.ceil(Log2(n)) == math.floor(Log2(n))

def checkisap(list):
	d = list[1] - list[0]
	for i in range(2, len(list)):
		temp = list[i] - list[i - 1]
		if temp != d:
			return False
	return True

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

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

def ii():
	return int(input())

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

def si():
	return list(map(str, input()))

def indict():
	dic = {}
	for (index, value) in enumerate(input().split()):
		dic[int(index) + 1] = int(value)
	return dic

def frqdict():
	dic = {}
	for (index, value) in enumerate(input().split()):
		if int(value) not in dic:
			dic[int(value)] = 1
		else:
			dic[int(value)] += 1
	return dic
n = ii()
ans = []
row = []
j = 1
for i in range(1, n * n + 1):
	if i % n:
		row.append(i)
	else:
		row.append(i)
		if j % 2 == 0:
			row.reverse()
		ans.append(row)
		j += 1
		row = []
for i in range(n):
	for row in ans:
		print(row[i], end=' ')
	print(end='\n')


n = int(input())
k = [[] for i in range(n)]
c = 0
for i in range(n):
	for j in range(n):
		k[i].append(c + j + 1)
	c += n
for i in range(n):
	for j in range(n):
		if j % 2 == 0:
			print(k[j][i], end=' ')
		else:
			print(k[j][n - 1 - i], end=' ')
	print('')


def create(n):
	res = [[0] * n for _ in range(n)]
	cur = 1
	for j in range(n):
		for i in range(n - 1, -1, -1) if j & 1 else range(n):
			res[i][j] = cur
			cur += 1
	return res
n = int(input())
res = create(n)
for l in res:
	print(*l)


R = lambda : map(int, input().split())
(n,) = R()
for i1 in range(n):
	t = n // 2
	for i2 in range(n - t):
		print(n * i2 + i1 + 1, ' ', end='')
	for i2 in range(n - t, n):
		print(n * i2 + n - i1, ' ', end='')
	print()


import os
import sys
from io import BytesIO, IOBase
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')
n = int(input())
ans = [[] for s in range(n)]
mod1 = [s for s in range(n)]
mod2 = [s for s in range(n - 1, -1, -1)]
mod = mod1 + mod2
for j in range(n ** 2):
	ans[mod[j % len(mod)]].append(j + 1)
for s in range(len(ans)):
	print(*ans[s])


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


n = int(input())
l = [[] for i in range(n)]
zigzag = 1
for j in range(n):
	if zigzag % 2 == 1:
		for i in range(n):
			l[i].append(str(i + (zigzag - 1) * n + 1))
	else:
		for i in range(-1, -(n + 1), -1):
			l[i].append(str(-i + (zigzag - 1) * n))
	zigzag += 1
for jk in l:
	print(' '.join(jk))


import sys, math, queue, collections
MOD = 10 ** 9 + 7
sys.setrecursionlimit(1000000)
n = int(input())
ans = [[0 for i in range(n)] for i in range(n)]
lab = 1
for j in range(n):
	if j % 2 == 1:
		for i in reversed(range(n)):
			ans[i][j] = lab
			lab += 1
	else:
		for i in range(n):
			ans[i][j] = lab
			lab += 1
for row in ans:
	print(*row)


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


from math import *
sInt = lambda : int(input())
mInt = lambda : map(int, input().split())
lInt = lambda : list(map(int, input().split()))
n = sInt()
a = [[0 for p in range(n)] for _ in range(n)]
(c, cc) = (1, 1)
for i in range(n):
	if cc % 2 == 1:
		for j in range(0, n, 1):
			a[j][i] = c
			c += 1
	else:
		for j in range(n - 1, -1, -1):
			a[j][i] = c
			c += 1
	cc += 1
for i in range(n):
	print(*a[i], sep=' ')


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


n = int(input().strip())
res = [[] for _ in range(n)]
up = True
for i in range(n * n):
	if i % n == 0:
		if up:
			up = False
		else:
			up = True
	if up:
		res[i % n].append(i + 1)
	else:
		res[n - i % n - 1].append(i + 1)
for i in range(n - 1, -1, -1):
	print(' '.join([str(x) for x in res[i]]))


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


n = int(input())
l = [[] for _ in range(n)]
f = 1
k = 1
for i in range(n):
	for j in range(n):
		if f:
			l[j].append(k)
		else:
			l[n - j - 1].append(k)
		k = k + 1
	f = not f
for i in range(n):
	print(*l[i])


import sys
import os
from io import IOBase, BytesIO

def main():
	n = int(input())
	arr = [[0] * n for _ in range(n)]
	x = 1
	f = 0
	for j in range(n):
		if f == 0:
			for i in range(n):
				arr[i][j] = x
				x += 1
		else:
			for i in range(n - 1, -1, -1):
				arr[i][j] = x
				x += 1
		f = 1 - f
	for i in range(n):
		print(*arr[i])
BUFSIZE = 8192

class FastIO(BytesIO):
	newlines = 0

	def __init__(self, file):
		self._file = file
		self._fd = file.fileno()
		self.writable = 'x' in file.mode or 'w' in file.mode
		self.write = super(FastIO, self).write if self.writable else None

	def _fill(self):
		s = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
		self.seek((self.tell(), self.seek(0, 2), super(FastIO, self).write(s))[0])
		return s

	def read(self):
		while self._fill():
			pass
		return super(FastIO, self).read()

	def readline(self):
		while self.newlines == 0:
			s = self._fill()
			self.newlines = s.count(b'\n') + (not s)
		self.newlines -= 1
		return super(FastIO, self).readline()

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

class IOWrapper(IOBase):

	def __init__(self, file):
		py2 = round(0.5)
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		if py2 == 1:
			self.write = self.buffer.write
			self.read = self.buffer.read
			self.readline = self.buffer.readline
		else:
			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 get_array():
	return list(map(int, sys.stdin.readline().split()))

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

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


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


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


import sys
import bisect
from collections import deque
Ri = lambda : [int(x) for x in sys.stdin.readline().split()]
ri = lambda : sys.stdin.readline().strip()

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

def list2d(a, b, c):
	return [[c] * b for i in range(a)]

def list3d(a, b, c, d):
	return [[[d] * c for j in range(b)] for i in range(a)]

def list4d(a, b, c, d, e):
	return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]

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

def INT():
	return int(input())

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

def LIST(N=None):
	return list(MAP()) if N is None else [INT() for i in range(N)]

def Yes():
	print('Yes')

def No():
	print('No')

def YES():
	print('YES')

def NO():
	print('NO')
INF = 10 ** 18
MOD = 10 ** 9 + 7
n = int(ri())
lis = [[] for i in range(n)]
ite = 1
while ite < n * n + 1:
	for i in range(0, n):
		lis[i].append(ite)
		ite += 1
	if ite < n * n + 1:
		for i in range(n - 1, -1, -1):
			lis[i].append(ite)
			ite += 1
for i in lis:
	print(*i)


from typing import List

def labs(n: int) -> List[List[int]]:
	list_of_lists = [[i * n + j + 1 for j in range(n)] for i in range(n)]
	for i in range(0, n, 2):
		list_of_lists[i] = list_of_lists[i][::-1]
	return [[list_of_lists[j][i] for j in range(n)] for i in range(n)]

def test():
	assert labs(3) == [[3, 4, 9], [2, 5, 8], [1, 6, 7]]
n = int(input())
list_of_lists = labs(n)
for i in range(n):
	print(' '.join(map(str, list_of_lists[i])))


n = int(input())
ans = []
for i in range(n):
	ans.append([0] * n)
k = 1
i = 0
j = 0
way = 1
for k in range(1, n * n + 1):
	ans[i][j] = k
	i += way
	if i == n or i == -1:
		way = -way
		if way == -1:
			i = n - 1
		else:
			i = 0
		j += 1
for i in range(n):
	for j in range(n):
		print(ans[i][j], end=' ')
	print()


n = int(input())
ans = [[0 for i in range(n)] for i in range(n)]
col = 0
cur = 1
row = 0
down = True
while cur <= n ** n and col < n:
	ans[row][col] = cur
	if cur % n == 0:
		col += 1
		down = not down
	elif down:
		row = (row + 1) % n
	else:
		row = (row - 1) % n
	cur += 1
for i in range(n):
	print(' '.join(list(map(str, ans[i]))))


n = int(input())
ans = [[0] * n for _ in range(n)]
st = 1
col = 0
while st < n * n:
	for i in range(n):
		ans[i][col] = st
		st += 1
	col += 1
	if col < n:
		for i in range(n - 1, -1, -1):
			ans[i][col] = st
			st += 1
		col += 1
for i in range(n):
	print(*ans[i])


n = int(input())
a = []
for i in range(1, n + 1):
	a.append([])
k = 0
count = 0
count2 = 0
i = 1
z = 0
c1 = 1
c2 = n ** 2
while True:
	f = 1
	a[k].append(i)
	if z == 0:
		c1 += 1
		i += 1
	if z == 1:
		c2 -= 1
		i -= 1
	k += 1
	if count == n - 1:
		k = 0
		f = 0
		count = 0
		if z == 0:
			z = 1
			i = c2
		elif z == 1:
			i = c1
			z = 0
	if f == 1:
		count += 1
	if c1 == c2:
		a[k].append(i)
		break
for i in range(len(a)):
	print(*a[i])


from itertools import chain
OFFSET = 1
n = int(input())
n2 = n // 2
nn2 = n * n2
nmd2 = n % 2
nn = n ** 2
for i in range(n):
	print(*map(OFFSET.__add__, chain(range(i * n2, (i + 1) * n2), range(nn2 + i, nn2 + i + nmd2), range(nn - (i + 1) * n2, nn - i * n2))))


def solution(s) -> None:
	print(1)

def main():
	t = int(input())
	j = 1
	cur = 0
	row = 0
	s = [[] for i in range(t)]
	while j < t * t + 1:
		if cur == 0:
			for i in range(t):
				s[row + i].append(j + i)
		else:
			for i in range(t):
				s[row + i].append(j + t - i - 1)
		j = j + t
		cur = 1 - cur
	print('\n'.join(map(lambda x: ' '.join(map(str, x)), s)))
main()


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


n = int(input())
for i in range(1, n + 1):
	cur = i
	s = str(i) + ' '
	for k in range(n - 1):
		if k % 2 == 0:
			cur += 1 + 2 * (n - i)
		else:
			cur += 1 + 2 * (i - 1)
		s += str(cur) + ' '
	print(s)


n = int(input())
ans = []
for i in range(n):
	if i % 2 == 1:
		ans.append(list(range(n * i + 1, n + n * i + 1)))
		ans[-1].reverse()
	else:
		ans.append(list(range(n * i + 1, n + n * i + 1)))
lol = []
for i in range(n):
	kek = []
	for j in range(n):
		kek.append(ans[j][i])
	lol.append(kek)
for i in lol:
	print(*i)


n = int(input())
ans = []
for i in range(n):
	s = []
	ans.append(s)
dr = 1
ptr = 0
for i in range(1, n ** 2 + 1):
	ans[ptr].append(i)
	if dr == 1:
		ptr += 1
		if ptr >= n:
			ptr -= 1
			dr = -1
	else:
		ptr -= 1
		if ptr < 0:
			ptr += 1
			dr = 1
for i in range(n):
	print(*ans[i])


mod = 10 ** 9 + 7
from sys import stdin, stdout
import bisect
import sys
sys.setrecursionlimit(10 ** 6)
from bisect import bisect_left as bl
from bisect import bisect_right as br
import itertools
import collections
import math
import heapq
from random import randint as rn

def modinv(n, p):
	return pow(n, p - 2, p)

def ncr(n, r, p):
	t = fact[n] * (ifact[r] * ifact[n - r] % p) % p
	return t

def cin():
	return map(int, sin().split())

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

def sin():
	return input()

def inin():
	return int(input())

def GCD(x, y):
	while y:
		(x, y) = (y, x % y)
	return x

def af(n):
	x = 1
	a = [1]
	for i in range(1, n):
		a.append(a[-1] * i)
	return a

def cc(n, r, fact):
	return fact[n] // (fact[r] * fact[n - r])

def main():
	n = inin()
	a = []
	b = []
	for i in range(n):
		a.append(b[:])
	x = 1
	for i in range(n):
		for j in range(n):
			if i % 2 == 0:
				a[j % n].append(x)
			else:
				a[n - j % n - 1].append(x)
			x += 1
	for i in a:
		print(*i)
py2 = round(0.5)
if py2:
	from future_builtins import ascii, filter, hex, map, oct, zip
	range = xrange
import os, sys
from io import IOBase, BytesIO
BUFSIZE = 8192

class FastIO(BytesIO):
	newlines = 0

	def __init__(self, file):
		self._file = file
		self._fd = file.fileno()
		self.writable = 'x' in file.mode or 'w' in file.mode
		self.write = super(FastIO, self).write if self.writable else None

	def _fill(self):
		s = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
		self.seek((self.tell(), self.seek(0, 2), super(FastIO, self).write(s))[0])
		return s

	def read(self):
		while self._fill():
			pass
		return super(FastIO, self).read()

	def readline(self):
		while self.newlines == 0:
			s = self._fill()
			self.newlines = s.count(b'\n') + (not s)
		self.newlines -= 1
		return super(FastIO, self).readline()

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

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		if py2:
			self.write = self.buffer.write
			self.read = self.buffer.read
			self.readline = self.buffer.readline
		else:
			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')
import sys

class ostream:

	def __lshift__(self, a):
		sys.stdout.write(str(a))
		return self
cout = ostream()
endl = '\n'

def readnumbers(zero=0):
	conv = ord if py2 else lambda x: x
	A = []
	numb = zero
	sign = 1
	i = 0
	s = sys.stdin.buffer.read()
	try:
		while True:
			if s[i] >= b'0'[0]:
				numb = 10 * numb + conv(s[i]) - 48
			elif s[i] == b'-'[0]:
				sign = -1
			elif s[i] != b'\r'[0]:
				A.append(sign * numb)
				numb = zero
				sign = 1
			i += 1
	except:
		pass
	if s and s[-1] >= b'0'[0]:
		A.append(sign * numb)
	return A
main()


n = int(input())
result = [[] for _ in range(n)]
x = n ** 2
turn = 0
flag = 0
for i in range(x):
	result[turn].append(i + 1)
	if flag == 0:
		if turn < n - 1:
			turn += 1
		else:
			flag = 1
	elif turn > 0:
		turn -= 1
	else:
		flag = 0
for item in result:
	print(*item, sep=' ')


n = int(input())
ans = [0] * n ** 2
cnt = n // 2
l = 0
r = n ** 2 - 1
for i in range(n):
	for _ in range(cnt):
		ans[l] = i + 1
		l += 1
	for _ in range(cnt):
		ans[r] = i + 1
		r -= 1
if n % 2 == 1:
	for i in range(n):
		ans[l] = i + 1
		l += 1
ans = [0] + ans
ans = sorted(zip(ans, range(len(ans))))
ans = list(zip(*ans))
for i in range(n):
	print(*ans[1][i * n + 1:(i + 1) * n + 1])


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


n = int(input())
rev = False
l = []
for i in range(n):
	if rev:
		l.append(list(reversed([str(1 + i * n + j) for j in range(n)])))
	else:
		l.append([str(1 + i * n + j) for j in range(n)])
	rev = not rev
for i in range(n):
	print(' '.join([l[j][i] for j in range(n)]))


n = int(input())
a = []
b = []
temp = 1
for i in range(n):
	b = []
	for j in range(n):
		b.append(temp)
		temp += 1
	a.append(b)
for i in range(n):
	if i % 2 == 1:
		a[i].reverse()
for i in range(n):
	for j in range(n):
		print(a[j][i], end=' ')
	print()


def main():
	import sys
	input = sys.stdin.readline
	n = int(input())
	res = [[] for _ in [0] * n]
	if n % 2 == 0:
		for i in range(n // 2):
			for j in range(n):
				res[j].append(n * i + j + 1)
				res[j].append(n * (n - i) - j)
	else:
		for i in range(n // 2):
			for j in range(n):
				res[j].append(n * i + j + 1)
				res[j].append(n * (n - i) - j)
		for i in range(n):
			res[i].append(n // 2 * n + i + 1)
	for i in range(n):
		for j in range(n - 1):
			print(res[i][j], end=' ')
		print(res[i][-1])
main()


from collections import deque
n = int(input())
nn = n ** 2
m = int(n // 2)
result = [] * n
for i in range(n):
	tmp = deque()
	if i % 2 == 0:
		for j in range(n):
			tmp.append(nn)
			nn -= 1
	else:
		for j in range(n):
			tmp.appendleft(nn)
			nn -= 1
	result.append(tmp)
for i in range(n):
	tmp = []
	for j in range(n):
		tmp.append(str(result[j][i]))
	print(' '.join(tmp))


n = int(input())
groups = [[] for _ in range(n)]
index = 0
for i in range(1, n ** 2 + 1):
	groups[index].append(i)
	if index >= 0:
		index += 1
		if index == n:
			index = -1
	else:
		index -= 1
		if index == -n - 1:
			index = 0
for elem in groups:
	print(' '.join(list(map(str, elem))))


n = int(input())
l = [[0 for x in range(n)] for y in range(n)]
flag = 1
v = 1
i = 0
j = 0
while v <= n * n:
	l[i][j] = v
	if flag == 1:
		i += 1
	else:
		i -= 1
	v += 1
	if i == n or i == -1:
		j += 1
		if i == n:
			i -= 1
		else:
			i += 1
		flag = (flag + 1) % 2
for i in range(n):
	for j in range(n):
		print(l[i][j], end=' ')
	print('\n', end='')


n = int(input())
l = []
x = 1
value = 0
for i in range(1, n ** 2 + 1):
	if i <= n:
		l.append([])
	l[value].append(i)
	if x:
		value += 1
	else:
		value -= 1
	if value == n or value == -1:
		if value == n:
			value -= 1
		else:
			value += 1
		x = 1 - x
for i in l:
	for j in i:
		print(j, end=' ')
	print('')


n = int(input())
arr = list(range(1, n ** 2 + 1))
final = []
for i in range(0, len(arr), n):
	final.append(arr[i:i + n])
for i in range(len(final)):
	if i % 2 == 0:
		final[i] = list(reversed(final[i]))
ans = []
for i in range(len(final)):
	temp = []
	for j in range(len(final)):
		temp.append(final[j][i])
	ans.append(temp)
for j in ans:
	print(*j)


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


n = int(input())
lst = []
f = 0
i = 1
while i <= n * n:
	if f == 0:
		lst.append([j for j in range(i, i + n)])
		i = i + n
		f = 1
	else:
		lst.append([j for j in range(i + n - 1, i - 1, -1)])
		i = i + n
		f = 0
for i in range(n):
	for j in range(n):
		print(lst[j][i], end=' ')
	print()


a = int(input())
dp = [[0 for i in range(a)] for i in range(a)]
count = 1
for i in range(a):
	for j in range(a):
		if i % 2 == 0:
			dp[j][i] = count
			count += 1
		else:
			dp[a - j - 1][i] = count
			count += 1
for i in range(len(dp)):
	x = dp[i]
	print(' '.join(map(str, x)))


import sys
import collections
input = sys.stdin.readline

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

def rint():
	return int(input().strip())

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

def gcd(a, b):
	if a == 0:
		return b
	return gcd(a % b, a)
n = rint()
index = 1
ans = [[0 for _ in range(n)] for _ in range(n)]
for i in range(n):
	tmp = [0] * n
	for j in range(n):
		tmp[j] = str(index)
		index += 1
	if i % 2:
		ans[i] = list(reversed(tmp))
	else:
		ans[i] = tmp
result = zip(*ans)
for i in result:
	print(' '.join(i))


import sys, math, itertools
from collections import Counter, deque, defaultdict
from bisect import bisect_left, bisect_right
from heapq import heappop, heappush, heapify
mod = 10 ** 9 + 7
INF = float('inf')

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

def inpl():
	return list(map(int, sys.stdin.readline().split()))
n = inp()
now = 1
res = [[-1] * n for _ in range(n)]
for i in range(n):
	for j in range(n):
		res[i][j] = now
		now += 1
	if i % 2 == 0:
		res[i] = res[i][::-1]
ans = [[-1] * n for _ in range(n)]
for i in range(n):
	for j in range(n):
		ans[i][j] = res[j][i]
for x in ans:
	print(*x)


n = int(input())
s = dict()
for i in range(1, n + 1):
	s[i] = []
godown = True
at = 1
for i in range(1, n ** 2 + 1):
	s[at].append(i)
	if i % n == 0:
		godown = not godown
		continue
	if godown:
		at += 1
	else:
		at -= 1
for i in s.values():
	for j in i:
		print(j, '', end='')
	print()


from sys import stdin, stdout, setrecursionlimit
from functools import lru_cache, cmp_to_key
from heapq import merge, heapify, heappop, heappush, nlargest
from math import *
from collections import defaultdict as dd, deque, Counter as C
from itertools import combinations as comb, permutations as perm, accumulate
from bisect import bisect_left as bl, bisect_right as br, bisect
from time import perf_counter
from fractions import Fraction
import copy
import time
setrecursionlimit(10 ** 9)
starttime = time.time()
mod = int(pow(10, 9) + 7)
mod2 = 998244353

def data():
	return input()

def num():
	return int(input())

def L():
	return list(sp())

def LF():
	return list(spf())

def sl():
	return list(ssp())

def sp():
	return map(int, data().split())

def spf():
	return map(int, input.readline().split())

def ssp():
	return map(str, data().split())

def l1d(n, val=0):
	return [val for i in range(n)]

def l2d(n, m, val=0):
	return [l1d(n, val) for j in range(m)]

def pmat(A):
	for ele in A:
		print(*ele, end='\n')

def pmat2(A):
	for ele in A:
		for j in ele:
			print(j, end='')
		print()

def iseven(n):
	return n % 2 == 0

def seive(r):
	prime = [1 for i in range(r + 1)]
	prime[0] = 0
	prime[1] = 0
	for i in range(r + 1):
		if prime[i]:
			for j in range(2 * i, r + 1, i):
				prime[j] = 0
	return prime

def main():
	n = int(input())
	ans = []
	curr = []
	for i in range(1, n ** 2 + 1):
		curr.append(i)
		if len(curr) == n:
			if len(ans) % 2 == 0:
				ans.append(curr)
			else:
				curr.reverse()
				ans.append(curr)
			curr = []
	for i in range(n):
		for j in range(n):
			print(ans[j][i], end=' ')
		print()
main()
endtime = time.time()


n = int(input())
lis = [[0] * n for i in range(n)]
i = 0
k = n * n
c = 0
while i < n:
	j = 0
	while j < n:
		if c % 2 == 0:
			lis[j][i] = j + 1 + c * n
		else:
			lis[-j - 1][i] = j + 1 + c * n
		j += 1
	c += 1
	i += 1
for i in lis:
	print(*i)


n = int(input())
ans = [[None] * n for i in range(n)]
goDown = 1
cur = 1
for c in range(n):
	if goDown:
		for r in range(n):
			ans[r][c] = cur
			cur += 1
		goDown ^= 1
	else:
		for r in range(n - 1, -1, -1):
			ans[r][c] = cur
			cur += 1
		goDown ^= 1
for i in range(n):
	row = ans[i]
	print(' '.join((str(n) for n in row)))


n = int(input())
ans = []
cc = 1
for i in range(n):
	ans.append([])
for i in range(n):
	if i % 2 == 0:
		for j in range(n):
			ans[j].append(cc)
			cc += 1
	else:
		for j in range(n - 1, -1, -1):
			ans[j].append(cc)
			cc += 1
for i in range(n):
	for j in range(n):
		print(ans[i][j], end=' ')
	print()


n = int(input())
matrix = [[0 for j in range(n)] for i in range(n)]
flag = True
val = 1
for i in range(n):
	if flag:
		for j in range(n):
			matrix[j][i] = val
			val += 1
		flag = False
	else:
		for j in range(n - 1, -1, -1):
			matrix[j][i] = val
			val += 1
		flag = True
for i in range(n):
	for j in range(n):
		print(matrix[i][j], end=' ')
	print()


n = int(input())
arr = []
c = 1
flag = 1
i = 0
while i < n:
	i += 1
	temp = [x for x in range(c, c + n)]
	if flag:
		arr.append(temp)
		flag ^= 1
	else:
		arr.append(temp[::-1])
		flag ^= 1
	c += n
for x in range(n):
	for y in range(x, n):
		(arr[x][y], arr[y][x]) = (arr[y][x], arr[x][y])
for row in arr:
	for item in row:
		print(item, end=' ')
	print()


import sys
ip = lambda : sys.stdin.readline().rstrip()
n = int(ip())
a = [list() for _ in range(n)]
(t, idx) = (1, 0)
for i in range(1, n ** 2 + 1):
	if idx == n:
		idx = 0
		t ^= 1
	if t:
		a[idx].append(i)
	else:
		a[n - 1 - idx].append(i)
	idx += 1
for i in a:
	print(*i)


import os
import sys
from io import BytesIO, IOBase
from collections import Counter
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 gcd(a, b):
	if a == 0:
		return b
	return gcd(b % a, a)

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

def main():
	n = int(input())
	ans = [[0 for i in range(n)] for j in range(n)]
	c = 1
	f = 0
	for j in range(n):
		if f == 0:
			for i in range(n):
				ans[i][j] = c
				c += 1
		else:
			for i in range(n - 1, -1, -1):
				ans[i][j] = c
				c += 1
		f ^= 1
	for i in ans:
		print(*i)
	return
main()


n = int(input())
list1 = []
for i in range(n):
	list1.append([])
k = 0

def f(x):
	a = x % n
	b = (x - 1) // n % 2
	if b == 1:
		a = (1 + n - a) % n
	if a == 0:
		a += n
	return a - 1
for i in range(1, n ** 2 + 1):
	list1[f(i)].append(i)
for i in range(n):
	for k in range(n):
		if k != n - 1:
			print(list1[i][k], end=' ')
		else:
			print(list1[i][k], end='\n')


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


import sys
import math
import bisect
from sys import stdin, stdout
from math import gcd, floor, sqrt, log2, ceil
from collections import defaultdict as dd
from bisect import bisect_left as bl, bisect_right as br
from bisect import insort
from collections import Counter
from collections import deque
from heapq import heappush, heappop, heapify
from itertools import permutations, combinations
mod = int(1000000000.0) + 7
ip = lambda : int(stdin.readline())
inp = lambda : map(int, stdin.readline().split())
ips = lambda : stdin.readline().rstrip()
out = lambda x: stdout.write(str(x) + '\n')
t = 1
for _ in range(t):
	n = ip()
	ans = [[None] * n for i in range(n)]
	ct = 1
	for i in range(n):
		if i & 1 == 0:
			for j in range(n):
				ans[j][i] = ct
				ct += 1
		else:
			for j in range(n - 1, -1, -1):
				ans[j][i] = ct
				ct += 1
	for i in ans:
		print(*i)


from sys import stdin
from collections import deque, Counter, defaultdict, OrderedDict
import sys
import math, os
import operator
import random
from fractions import Fraction
import functools
import bisect
import itertools
from heapq import *
import time
import random
import bisect
import copy
n = int(input())
s = []
matrix = []
i = 1
c = 1
while i <= n * n:
	s.append(i)
	c += 1
	if c == n + 1:
		c = 1
		matrix.append(s)
		s = []
	i += 1
for i in range(n):
	crux = []
	which = i
	for j in range(n):
		which = abs(n - which - 1)
		crux.append(matrix[j][which])
	print(' '.join(map(str, crux)))


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


MOD = 10 ** 9 + 7
I = lambda : list(map(int, input().split()))
(n,) = I()
ans = [[] for i in range(n)]
k = 0
f = 1
for i in range(1, n ** 2 + 1):
	ans[k].append(i)
	k += f
	if k == n:
		k -= 1
		f = -1
	elif k == -1:
		k = 0
		f = 1
for i in ans:
	print(*i)


from collections import deque
n = int(input())
labs = [deque([l * n + i for i in range(0, n)]) for l in range(0, n)]
rem = n
while rem:
	front = True
	for l in range(0, n):
		gr = labs[l]
		v = None
		if front:
			v = gr[0]
			gr.popleft()
		else:
			v = gr[-1]
			gr.pop()
		print(v + 1, end='')
		if l + 1 != n:
			print(' ', end='')
		front = not front
	print('')
	rem -= 1


n = int(input())
g = [[] for _ in range(n)]
i = 0
a = 1
for v in range(n * n):
	g[i].append(v + 1)
	if a == 1 and i == n - 1:
		a = -1
		i += 1
	if a == -1 and i == 0:
		a = 1
		i -= 1
	i += a
for i in g:
	print(' '.join(map(str, i)))


a = int(input())
M = []
L = []
for i in range(a):
	M.append([])
	L.append([0] * a)
counter = 0
j = 1
while counter != a:
	for t in range(a):
		M[counter].append(j)
		j += 1
	if counter % 2 != 0:
		M[counter] = M[counter][::-1]
	counter += 1
for t in range(len(M)):
	for s in range(len(M)):
		L[t][s] = M[s][t]
for num in L:
	print(*num)


import sys
input = sys.stdin.buffer.readline
n = int(input())
ans = [[] for _ in range(n)]
down = True
for i in range(n):
	if down:
		for j in range(n):
			ans[j].append(i * n + j + 1)
		down = False
	else:
		for j in range(n):
			ans[j].append(i * n + (n - j))
		down = True
for line in ans:
	print(' '.join([str(item) for item in line]))


def main():
	n = int(input())
	s = []
	j = 1
	y = 0
	for i in range(n):
		if y == 0:
			s.append(range(j, j + n))
		else:
			s.append(range(j + n - 1, j - 1, -1))
		y = -1 - y
		j = j + n
	print('\n'.join(map(lambda x: ' '.join(map(str, x)), zip(*s))))
main()


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


n = int(input())
l = [[] for i in range(n)]
i = 1
flag = True
while i < n * n:
	tflag = True
	if flag == True:
		flag = False
		tflag = False
		for j in range(n):
			l[j].append(i)
			i += 1
	if flag == False and tflag == True:
		flag = True
		for j in range(n):
			l[n - j - 1].append(i)
			i += 1
for i in range(n):
	for j in range(n):
		print(l[i][j], end=' ')
	print()


a = []
n = int(input())
k = 1
for i in range(n):
	l = []
	for j in range(n):
		l.append(k)
		k += 1
	if not i % 2 == 0:
		a.append(l[::-1])
	else:
		a.append(l[:])
	l.clear()
new_a = zip(*a)
for i in new_a:
	print(*i)


n = int(input())
result = [list() for x in range(n)]
k = 0
i = 1
k = 0
add = 1
up = 1
while i <= n ** 2:
	result[k].append(i)
	k += up
	if i % n == 0 and up == 1:
		k = n - 1
		up = -1
	elif i % n == 0 and up == -1:
		k = 0
		up = 1
	i += 1
for i in result:
	for j in i:
		print(j, end=' ')
	print()


def next_ind(ind, reverse, n):
	if ind == 0:
		return (ind + 1, False)
	elif ind == n - 1:
		return (ind - 1, True)
	if reverse:
		return (ind - 1, True)
	else:
		return (ind + 1, False)
n = int(input())
arr = [[] for i in range(n)]
mul = 0
for i in range(n):
	if i % 2 == 0:
		start = mul * n + 1
		for j in range(n):
			arr[j].append(start)
			start += 1
	else:
		start = (mul + 1) * n
		for j in range(n):
			arr[j].append(start)
			start -= 1
	mul += 1
for i in arr:
	print(*i)


n = int(input())
p = [[0 for col in range(n)] for row in range(n)]
p[0][0] = 1
for i in range(1, n):
	if i % 2 == 1:
		p[0][i] = (i + 1) * n
	else:
		p[0][i] = p[0][i - 1] + 1
for i in range(n):
	for j in range(1, n):
		if i % 2 == 0:
			p[j][i] = p[j - 1][i] + 1
		else:
			p[j][i] = p[j - 1][i] - 1
for i in range(n):
	for j in range(n - 1):
		print(p[i][j], end=' ')
	print(p[i][n - 1])


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


n = int(input())
res = []
l = range(1, n + 1)
m = pow(n, 2)
for i in range(1, n + 1):
	pos = l.index(i)
	revpos = n - 1 - pos
	res.append([i])
	for j in range(2, n + 1):
		if j % 2 == 0:
			res[i - 1].append(l[revpos] + (j - 1) * n)
		else:
			res[i - 1].append(l[pos] + (j - 1) * n)
for i in res:
	for j in i:
		print(j, end=' ')
	print()


n = int(input())
dir = 1
val = 1
l = [[] for _ in range(n)]
for i in range(n):
	for j in range(n):
		l[j if dir == 1 else n - 1 - j].append(val)
		val += 1
	dir *= -1
for i in range(n):
	print(*l[i])


n = int(input())
k = list(range(1, n ** 2 + 1))
l = [[] for i in range(n)]
if n % 2 == 0:
	num = int(n / 2)
	p1 = 0
	p2 = len(k) - 1
	for i in range(n):
		l[i] += k[p1:p1 + num]
		l[i] += k[p2 + 1 - num:p2 + 1]
		p1 += num
		p2 -= num
else:
	num = int(n / 2)
	orta = int(len(k) / 2)
	p1 = 0
	p2 = len(k) - 1
	kl = 1
	for i in range(n):
		l[i] += k[p1:p1 + num]
		l[i] += k[p2 + 1 - num:p2 + 1]
		l[i] += [k[orta]]
		p1 += num
		p2 -= num
		if i % 2 == 0:
			orta += kl
			kl += 1
		else:
			orta -= kl
			kl += 1
for i in l:
	print(*i)


N = int(input())
lis = [[0] * N for i in range(N)]
cnt = 1
for i in range(N):
	for j in range(N):
		lis[i][j] = cnt
		cnt += 1
for i in range(N):
	if i % 2 == 1:
		lis[i].reverse()
lis2 = [[0] * N for i in range(N)]
for i in range(N):
	for j in range(N):
		lis2[j][i] = lis[i][j]
for i in range(N):
	print(' '.join(map(str, lis2[i])))


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


import sys
import os
import io
from sys import stdin
from math import log, gcd, ceil
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop
import math
from bisect import bisect_left, bisect_right
if os.path.exists('input.txt'):
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')

def ncr(n, r, p):
	num = den = 1
	for i in range(r):
		num = num * (n - i) % p
		den = den * (i + 1) % p
	return num * pow(den, p - 2, p) % p

def primeFactors(n):
	l = []
	while n % 2 == 0:
		l.append(2)
		n = n / 2
	for i in range(3, int(math.sqrt(n)) + 1, 2):
		while n % i == 0:
			l.append(int(i))
			n = n / i
	if n > 2:
		l.append(n)
	return list(set(l))

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

def countdig(n):
	c = 0
	while n > 0:
		n //= 10
		c += 1
	return c

def si():
	return input()

def prefix_sum(arr):
	r = [0] * (len(arr) + 1)
	for (i, el) in enumerate(arr):
		r[i + 1] = r[i] + el
	return r

def divideCeil(n, x):
	if n % x == 0:
		return n // x
	return n // x + 1

def ii():
	return int(input())

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

def ws(s):
	sys.stdout.write(s + '\n')

def wi(n):
	sys.stdout.write(str(n) + '\n')

def wia(a):
	sys.stdout.write(' '.join([str(x) for x in a]) + '\n')
t = 1
for _ in range(t):
	n = ii()
	l = [[] for i in range(n + 1)]
	ptr = 0
	x = 0
	for i in range(0, n * n):
		l[ptr].append(i + 1)
		if x == 0:
			ptr += 1
		else:
			ptr -= 1
		if ptr == n:
			x = 1
			ptr -= 1
		if ptr == -1:
			x = 0
			ptr += 1
	for i in range(0, len(l)):
		print(*l[i])


def main():
	n = int(input())
	ans = []
	curr = []
	for i in range(1, n ** 2 + 1):
		curr.append(i)
		if len(curr) == n:
			if len(ans) % 2 == 0:
				ans.append(curr)
			else:
				curr.reverse()
				ans.append(curr)
			curr = []
	for i in range(n):
		for j in range(n):
			print(ans[j][i], end=' ')
		print()
main()


n = int(input())
l = [0] * (n * n)
j = 1
k = 0
f = 0
p = 1
while j <= n * n:
	if j == 1:
		l[k] = j
		k += n
	elif k >= n * (n - 1):
		if f == 0:
			l[k] = j
			f = 1
		elif f == 1:
			k += 1
			l[k] = j
			k -= n
			p = -1
			f = 0
	elif k < n:
		if f == 0:
			l[k] = j
			f = 1
		elif f == 1:
			k += 1
			l[k] = j
			k += n
			p = 1
			f = 0
	else:
		f = 0
		if p == 1:
			l[k] = j
			k += n
		else:
			l[k] = j
			k -= n
	j += 1
for j in range(n * n):
	print(l[j], end=' ')
	if j > 0 and (j + 1) % n == 0:
		print()


from math import floor, ceil
n = int(input())
m = list()
for i in range(n):
	if i % 2 == 0:
		m.append(list(range(i * n, i * n + n)))
	else:
		m.append(list(range(i * n, i * n + n))[::-1])
for i in range(n):
	for j in range(n):
		print(m[j][i] + 1, end=' ')
	print()


t = int(input())
ans = []
for i in range(t):
	row = []
	for j in range(t):
		row.append(i * t + j)
	if i % 2 == 1:
		row = row[::-1]
	ans.append(row)
for i in range(t):
	coeff = 1
	offset = 0
	for j in range(t):
		print(coeff * ans[j][i] + offset + 1, end=' ')
	print()


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


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


from sys import stdin
input = stdin.readline
n = int(input())
a = [i for i in range(1, n ** 2 + 1)]
for i in range(n, n ** 2, n * 2):
	a = a[:i] + a[i:i + n][::-1] + a[i + n:]
for i in range(n):
	print(*[a[i + j * n] for j in range(n)])


x = int(input())
c = [[] for i in range(x + 2)]
for i in range(1, x + 1):
	for j in range(1, x + 1):
		if i % 2:
			c[j].append(str((i - 1) * x + j))
		else:
			c[x - j + 1].append(str((i - 1) * x + j))
for i in range(1, x + 1):
	print(' '.join(c[i]))


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


import sys
input = sys.stdin.readline
n = int(input())
ANS = [[0] * n for i in range(n)]
score = 1
for i in range(n):
	if i % 2 == 0:
		for j in range(n):
			ANS[j][i] = score
			score += 1
	else:
		for j in range(n - 1, -1, -1):
			ANS[j][i] = score
			score += 1
for ans in ANS:
	print(*ans)


n = int(input())
a = [[0 for x in range(n)] for _ in range(n)]
cnt = 1
flag = 0
for i in range(n):
	if flag == 0:
		for j in range(n):
			a[i][j] = cnt
			cnt += 1
		flag = 1
	else:
		for j in range(n - 1, -1, -1):
			a[i][j] = cnt
			cnt += 1
		flag = 0
for i in range(n):
	for j in range(i + 1, n):
		(a[i][j], a[j][i]) = (a[j][i], a[i][j])
for i in range(n):
	print(*a[i])


n = int(input())
result = [[0 for i in range(n)] for j in range(n)]
(k, flag) = (1, 1)
for i in range(n):
	for j in range(n):
		if flag == 1:
			result[j][i] = k
		else:
			result[n - j - 1][i] = k
		k += 1
	flag = 2 if flag == 1 else 1
for i in range(n):
	print(' '.join(map(str, result[i])))


a = int(input())
c = []
for i in range(a):
	c += [[0] * a]
(i, j, k) = (0, 0, a * a)
while i < a:
	p = ''
	if j == 0:
		for p in range(a):
			c[p][i] = k
			k -= 1
		j = 1
	else:
		for p in range(a - 1, -1, -1):
			c[p][i] = k
			k -= 1
		j = 0
	i += 1
for i in c:
	print(*i)


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


import sys
input = lambda : sys.stdin.readline()
MOD = 1000000007
ii = lambda : int(input())
si = lambda : input()
dgl = lambda : list(map(int, input()))
f = lambda : list(map(int, input().split()))
il = lambda : list(map(int, input().split()))
ls = lambda : list(input())
n = ii()
l = [[] for i in range(n)]
for i in range(n * n):
	if i // n & 1:
		l[-(i % n + 1)].append(i + 1)
	else:
		l[i % n].append(i + 1)
for i in l:
	print(*i)


n = int(input())
a = [0] * n * n
index = n * n - 1
for i in range(n, 0, -1):
	if i % 2 == 0:
		for j in range(n, 0, -1):
			a[index] = j
			index -= 1
	else:
		for j in range(n):
			a[index] = j + 1
			index -= 1
x = {}
for (el, gr) in enumerate(a):
	if gr not in x:
		x[gr] = []
	x[gr].append(el + 1)
for item in x.values():
	print(' '.join(map(str, item)))


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


n = int(input())
a = [[] for _ in range(n)]
for i in range(n):
	direction = i % 2 == 0
	for j in range(1, n + 1):
		if direction:
			a[j - 1].append(str(n * i + j))
		else:
			a[n - j].append(str(n * i + j))
for group in a:
	print(' '.join(group))


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


from sys import stdin, stdout
import math, sys, heapq
from itertools import permutations, combinations
from collections import defaultdict, deque, OrderedDict
from os import path
import random
import bisect as bi

def yes():
	print('YES')

def no():
	print('NO')
if path.exists('input.txt'):
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')

	def I():
		return int(input())

	def In():
		return map(int, input().split())
else:

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

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

def dict(a):
	d = {}
	for x in a:
		if d.get(x, -1) != -1:
			d[x] += 1
		else:
			d[x] = 1
	return d

def find_gt(a, x):
	i = bi.bisect_left(a, x)
	if i != len(a):
		return i
	else:
		return -1

def main():
	try:
		n = I()
		l = []
		ans = [l.copy() for x in range(n)]
		q = 0
		i = n ** 2
		for x in range(n):
			if q == 0:
				for y in range(n - 1, -1, -1):
					ans[y].append(i)
					i -= 1
				q = 1
			else:
				for y in range(n):
					ans[y].append(i)
					i -= 1
				q = 0
		for x in ans:
			print(*x)
	except:
		pass
M = 998244353
P = 1000000007
for _ in range(1):
	main()


def main():
	t = int(input().strip())
	col = [[0] * t for x in range(t)]
	k = 0
	num = 1
	for i in range(t):
		if k % 2 == 0:
			for j in range(t):
				col[i][j] = num
				num += 1
		else:
			for j in range(t - 1, -1, -1):
				col[i][j] = num
				num += 1
		k += 1
	for j in range(t):
		for i in range(t):
			print(col[i][j], end=' ')
		print()
main()


n = int(input())
j = 0
a = [[] for k in range(n)]
d = 1
for i in range(1, n ** 2 + 1):
	prev = j
	a[j].append(i)
	j += d
	if j == n - 1 or j == 0:
		d = 0
	if d == 0 and j == n - 1 and (prev == j):
		d = -1
	if d == 0 and j == 0 and (prev == j):
		d = 1
for i in a:
	print(*i)


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


n = int(input())
m = []
for i in range(n):
	m.append([0] * n)
num = 1
f = 1
for j in range(n):
	if f:
		for i in range(n):
			m[i][j] = num
			num += 1
		f = 0
		continue
	for i in range(n - 1, -1, -1):
		m[i][j] = num
		num += 1
	f = 1
for i in range(n):
	print(*m[i])


from __future__ import division, print_function
from fractions import Fraction
import sys
import os
from io import BytesIO, IOBase
from itertools import *
import bisect
from heapq import *
from math import *
from copy import *
from collections import deque
from collections import Counter as counter
from itertools import combinations as comb
from itertools import permutations as permutate
from bisect import bisect_left as bl
from bisect import bisect_right as br
from bisect import bisect
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')

def print(*args, **kwargs):
	(sep, file) = (kwargs.pop('sep', ' '), kwargs.pop('file', sys.stdout))
	at_start = True
	for x in args:
		if not at_start:
			file.write(sep)
		file.write(str(x))
		at_start = False
	file.write(kwargs.pop('end', '\n'))
	if kwargs.pop('flush', False):
		file.flush()
if sys.version_info[0] < 3:
	(sys.stdin, sys.stdout) = (FastIO(sys.stdin), FastIO(sys.stdout))
else:
	(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
from types import GeneratorType

def iterative(f, stack=[]):

	def wrapped_func(*args, **kwargs):
		if stack:
			return f(*args, **kwargs)
		to = f(*args, **kwargs)
		while True:
			if type(to) is GeneratorType:
				stack.append(to)
				to = next(to)
				continue
			stack.pop()
			if not stack:
				break
			to = stack[-1].send(to)
		return to
	return wrapped_func
mod = 1000000007

def inp():
	return sys.stdin.readline().rstrip('\r\n')

def out(var):
	sys.stdout.write(str(var))

def lis():
	return list(map(int, inp().split()))

def stringlis():
	return list(map(str, inp().split()))

def sep():
	return map(int, inp().split())

def strsep():
	return map(str, inp().split())

def zerolist(n):
	return [0] * n

def nextline():
	out('\n')

def testcase(t):
	for p in range(t):
		solve()

def printlist(a):
	for p in range(0, len(a)):
		out(str(a[p]) + ' ')

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

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 ncr(n, r):
	return factorial(n) // (factorial(r) * factorial(max(n - r, 1)))

def isPrime(n):
	if n <= 1:
		return False
	if n <= 3:
		return True
	if n % 2 == 0 or n % 3 == 0:
		return False
	i = 5
	while i * i <= n:
		if n % i == 0 or n % (i + 2) == 0:
			return False
		i = i + 6
	return True

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 solve():
	n = int(inp())
	grid = [[0 for i in range(n)] for j in range(n)]
	for i in range(n):
		for j in range(n):
			if j % 2 == 0:
				grid[i][j] = j * n + i
			else:
				grid[n - 1 - i][j] = j * n + i
	for i in range(n):
		print(' '.join((str(grid[i][j] + 1) for j in range(n))))
testcase(1)


n = int(input())
lists = []
for i in range(n):
	lists.append([])
forward = False
for i in range(n ** 2):
	if i != 0 and i % n == 0:
		forward = not forward
	if forward:
		lists[i % n].append(i + 1)
	else:
		lists[n - 1 - i % n].append(i + 1)
for list_ in lists:
	for item in list_:
		print(item, end=' ')
	print()


n = int(input())
b = 1
ans = [[] for i in range(n)]
for i in range(n):
	idx = i * n + 1 if b else (i + 1) * n
	for j in range(n):
		ans[j].append(idx)
		idx = idx + 1 if b else idx - 1
	b = not b
for i in range(n):
	print(' '.join((str(j) for j in ans[i])))


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


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


from math import *
from sys import *
from heapq import *
from collections import defaultdict
from itertools import permutations
import os, sys
from io import IOBase, BytesIO
M = 10 ** 9 + 7

def expi(bas, exp):
	t = 1
	while exp > 0:
		if exp % 2 != 0:
			t = t * bas % N
		bas = bas * bas % N
		exp = int(exp / 2)
	return t % N

def graph_as_tree_1_root():
	n = int(input())
	dict = defaultdict(list)
	for _ in range(n - 1):
		(x, y) = list(map(int, input().split()))
		dict[x].append(y)
		dict[y].append(x)
	tree = [[1]]
	temp = [1]
	vall = 0
	seen = set([i for i in range(2, n + 1)])
	lol = []
	while len(seen) > 0:
		lol = list(seen)
		tt = []
		for x in temp:
			aa = []
			for val in dict[x]:
				if val in seen:
					aa += [val]
					seen.remove(val)
			dict[x] = aa
			tt += aa
		tree.append(tt)
		temp = tt
		vall += 1
	for x in lol:
		dict[x] = []
	print(tree, dict)

def pow(a, b):
	res = 1
	while b > 0:
		if b & 1:
			res *= a
		a *= a
		b >>= 1
	return res

def powmod(a, b, m):
	res = 1
	while b > 0:
		if b & 1:
			res = res * a % m
		a *= a
		b >>= 1
	return res

def inv(a, m):
	return powmod(a, m - 2, m)

def alldivisors(n):
	list = []
	arr = []
	for i in range(1, int(sqrt(n) + 1)):
		if n % i == 0:
			if n / i == i:
				arr += [i]
			else:
				arr += [i]
				list.append(n // i)
	arr += list[::-1]
	return arr

def primefactorisation(n):
	potentional_p = 3
	itog_list = defaultdict(int)
	if n % 2 == 0:
		itog_list[2] = 0
	while n % 2 == 0:
		n = n // 2
		itog_list[2] += 1
	while n - 1:
		if potentional_p > n ** 0.5:
			itog_list[n] += 1
			return itog_list
		while n % potentional_p == 0:
			n = n // potentional_p
			itog_list[potentional_p] += 1
		potentional_p += 2
	return itog_list

def main():
	n = int(input())
	a = []
	delta = 2 * n - 1
	cc = 1
	for i in range(n):
		temp = [cc]
		prev = cc
		fl = 1
		while prev <= n * n:
			if fl == 1:
				prev = prev + delta
				fl = -1
			else:
				prev += 2 * n - delta
				fl = 1
			temp.append(prev)
		a.append(temp)
		cc += 1
		delta -= 2
	for x in a:
		print(*x[:-1])
BUFSIZE = 8192

class FastIO(BytesIO):
	newlines = 0

	def __init__(self, file):
		self._file = file
		self._fd = file.fileno()
		self.writable = 'x' in file.mode or 'w' in file.mode
		self.write = super(FastIO, self).write if self.writable else None

	def _fill(self):
		s = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
		self.seek((self.tell(), self.seek(0, 2), super(FastIO, self).write(s))[0])
		return s

	def read(self):
		while self._fill():
			pass
		return super(FastIO, self).read()

	def readline(self):
		while self.newlines == 0:
			s = self._fill()
			self.newlines = s.count(b'\n') + (not s)
		self.newlines -= 1
		return super(FastIO, self).readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.getvalue())
			(self.truncate(0), self.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()


def solve(n):
	ans = []
	for i in range(n):
		if i % 2 == 0:
			ans.append(list(range(1 + i * n, (i + 1) * n + 1)))
		else:
			ans.append(list(range(1 + i * n, (i + 1) * n + 1))[::-1])
	for i in range(n):
		for j in range(i + 1, n):
			(ans[i][j], ans[j][i]) = (ans[j][i], ans[i][j])
	for i in ans:
		print(' '.join([str(j) for j in i]))

def main():
	n = int(input())
	solve(n)
main()


import sys
input = sys.stdin.readline

def main():
	n = int(input())
	a = [[0 for i in range(n)] for j in range(n)]
	x = 0
	y = 0
	henka = 1
	for i in range(1, n * n + 1):
		a[x][y] = i
		x += henka
		if x == n:
			x -= 1
			henka = -1
			y += 1
		elif x < 0:
			x = 0
			henka = 1
			y += 1
	for i in range(n):
		print(*a[i])
main()


import sys
n = int(input())
m = [[0] * n for _ in range(n)]
i = 0
j = 0
di = 1
for v in range(n * n, 0, -1):
	m[i][j] = v
	i += di
	if i == n:
		j += 1
		di = -1
		i = n - 1
	elif i == -1:
		j += 1
		di = 1
		i = 0
for i in range(n):
	print(' '.join(map(str, m[i])))


n = int(input())
l = [list() for i in range(n)]
for i in range(n):
	if i & 1:
		j = n - 1
		while j >= 0:
			l[j].append(i * n + n - j)
			j -= 1
	else:
		j = 0
		while j < n:
			l[j].append(i * n + j + 1)
			j += 1
print(*(' '.join(map(str, i)) for i in l), sep='\n')


n = int(input())
pipe = [[] for j in range(n)]
x = 1
for i in range(n):
	if i & 1:
		for j in range(n):
			pipe[j % n].append(x)
			x += 1
	else:
		for j in range(n):
			pipe[n - j % n - 1].append(x)
			x += 1
for i in range(n):
	for j in range(n):
		print(pipe[i][j], end=' ')
	print()


n = int(input())
res = []
for i in range(n):
	row = list(range(n * i + 1, n * (i + 1) + 1))
	if i % 2 == 1:
		row = row[::-1]
	res.append(row)
for row in list(zip(*res)):
	print(*row)


n = int(input())
arr = [x[:] for x in [[0] * n] * n]

def pr():
	for i in range(n):
		for j in range(n):
			print(arr[i][j], end=' ')
		print()
for i in range(n):
	if i % 2 == 0:
		for j in range(n):
			arr[j][i] = i * n + j + 1
	else:
		for j in range(n):
			arr[j][i] = i * n + (n - 1 - j) + 1
pr()


n = int(input())
ans = []
for i in range(n):
	ans.append([])
t = 1
cnt = 1
while True:
	if cnt > n:
		break
	for i in range(n):
		ans[i].append(t)
		t += 1
	cnt += 1
	if cnt > n:
		break
	for i in range(n - 1, -1, -1):
		ans[i].append(t)
		t += 1
	cnt += 1
for i in range(n):
	print(*ans[i])


from math import ceil
n = int(input())
ans = [list() for i in range(n)]
for i in range(1, n ** 2 + 1):
	if ceil(i / n) % 2 == 1:
		ans[i % n - 1].append(i)
	elif i % n == 0:
		ans[0].append(i)
	else:
		ans[n - i % n].append(i)
for x in ans:
	print(*x)


import sys
import itertools
import math
import collections
from collections import Counter

def pow(x, y, mod):
	r = 1
	x = x % mod
	while y > 0:
		if y & 1:
			r = r * x % mod
		y = y >> 1
		x = x * x % mod
	return r

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 * 2, n + 1, p):
				prime[i] = False
		p += 1
	prime[0] = prime[1] = False
	r = [p for p in range(n + 1) if prime[p]]
	return r

def divs(n, start=1):
	r = []
	for i in range(start, int(math.sqrt(n) + 1)):
		if n % i == 0:
			if n / i == i:
				r.append(i)
			else:
				r.extend([i, n // i])
	return r

def cdiv(n, k):
	return n // k + (n % k != 0)

def ii():
	return int(input())

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

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

def lcm(a, b):
	return abs(a * b) // math.gcd(a, b)

def prr(a, sep=' '):
	print(sep.join(map(str, a)))

def dd():
	return collections.defaultdict(int)
n = ii()
r = [[0] * n for i in range(n)]
a = [[0, n, 1], [n - 1, -1, -1]]
t = 0
c = 1
for j in range(n):
	k = a[t]
	for i in range(k[0], k[1], k[2]):
		r[i][j] = c
		c += 1
	t = 1 - t
for i in r:
	prr(i)


n = int(input())
groups = []
for i in range(n):
	groups.append([])
i = 0
while i <= n * n:
	j = 0
	while j <= n and i <= n * n:
		if j == n:
			groups[n - 1].append(i + 1)
		else:
			groups[j].append(i + 1)
		i += 1
		j += 1
	j = n - 2
	while j >= 0 and i <= n * n:
		if j == -1:
			groups[0].append(i + 1)
		else:
			groups[j].append(i + 1)
		i += 1
		j -= 1
for i in range(n):
	for j in range(len(groups[i])):
		res = groups[i][j]
		if res <= n * n:
			print(res, end=' ')
	print()


import sys
from math import *

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

def mint():
	return int(minp())

def mints():
	return map(int, minp().split())
n = mint()
a = [0] * n
for i in range(n):
	for j in range(0, n, 2):
		a[j] = i + 1 + n * j
	for j in range(1, n, 2):
		a[j] = n - i + n * j
	print(' '.join(map(str, a)))


n = int(input())
i = 1
arr = [int(x) for x in range(n)]
for x in range(n):
	arr[x] = list()
while i < n * n:
	for j in range(n):
		if i > n * n:
			break
		arr[j].append(i)
		i += 1
	for j in range(n - 1, -1, -1):
		if i > n * n:
			break
		arr[j].append(i)
		i += 1
for x in range(n):
	s = arr[x]
	for j in s:
		print(j, end=' ')
	print()


n = int(input())
x = n ** 2
y = x // 2
l = []
for i in range(1, y + 1, n):
	q = []
	for j in range(i, i + n):
		q.append(j)
	l.append(q)
for i in range(l[-1][-1] + 1, x, n):
	q = []
	for j in range(i, n + i):
		q.append(j)
	q = q[::-1]
	l.append(q)
b = list(map(list, zip(*l)))
for i in b:
	for j in i:
		print(j, end=' ')
	print()


import sys
from heapq import heappop
from heapq import heappush
from heapq import heapify
from bisect import insort
from bisect import bisect_right
from bisect import bisect_left
from sys import stdin, stdout
from collections import defaultdict
inp = lambda : int(stdin.readline())
sip = lambda : input()
mulip = lambda : map(int, input().split())
lst = lambda : list(map(int, stdin.readline().split()))
slst = lambda : list(sip())
arr2d = lambda x: [[int(j) for j in input().split()] for i in range(x)]
odds = lambda l: len(list(filter(lambda x: x % 2 != 0, l)))
evens = lambda l: len(list(filter(lambda x: x % 2 == 0, l)))
mod = pow(10, 9) + 7
n = inp()
A = [[0] * n for i in range(n)]
x = 1
for j in range(n):
	for i in range(n):
		if j % 2 == 0:
			A[i][j] = x
		else:
			A[n - 1 - i][j] = x
		x += 1
for i in A:
	print(*i)


import os
import sys
from io import BytesIO, IOBase
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():
	pass

def binary(n):
	return bin(n).replace('0b', '')

def decimal(s):
	return int(s, 2)

def pow2(n):
	p = 0
	while n > 1:
		n //= 2
		p += 1
	return p

def isPrime(n):
	if n == 1:
		return False
	else:
		root = int(n ** 0.5)
		root += 1
		for i in range(2, root):
			if n % i == 0:
				return False
		return True

def lts(l):
	s = ''.join(map(str, l))
	return s

def stl(s):
	l = list(s)
	return l

def sq(a, target, arr=[]):
	s = sum(arr)
	if s == target:
		return arr
	if s >= target:
		return
	for i in range(len(a)):
		n = a[i]
		remaining = a[i + 1:]
		ans = sq(remaining, target, arr + [n])
		if ans:
			return ans

def SieveOfEratosthenes(n):
	cnt = 0
	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
	for p in range(2, n + 1):
		if prime[p]:
			cnt += 1
	return cnt

def nCr(n, r):
	f = math.factorial
	return f(n) // f(r) // f(n - r)
mod = int(1000000000.0) + 7

def ssinp():
	return input()

def iinp():
	return int(input())

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

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

def p(xyz):
	print(xyz)

def p2(a, b):
	print(a, b)
import math
n = iinp()
l = [[] for j in range(n)]
f = c = 0
for i in range(n * n, 0, -1):
	if f == 0:
		l[c].append(i)
		c += 1
		if c == n:
			c = n - 1
			f = 1
	elif f == 1:
		l[c].append(i)
		c -= 1
		if c == -1:
			c = 0
			f = 0
for i in l:
	print(*i)


n = int(input())
num = n * n
res = [[] for i in range(n)]
for i in range(0, num):
	if n > i % (n * 2):
		res[i % n].append(i + 1)
	else:
		res[n - 1 - i % n].append(i + 1)
for x in res:
	print(' '.join(list(map(str, x))))


def multiLineArrayOfArraysPrint(arr):
	print('\n'.join([' '.join([str(x) for x in y]) for y in arr]))
n = int(input())
arr = [[0 for _ in range(n)] for __ in range(n)]
v = 1
startj = 0
endj = n - 1
jinc = 1
for i in range(n):
	for j in range(startj, endj + jinc, jinc):
		arr[j][i] = v
		v += 1
	(startj, endj, jinc) = (endj, startj, -jinc)
multiLineArrayOfArraysPrint(arr)


import math
import sys
try:
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')
except:
	input = sys.stdin.readline

def takeInput():
	return [int(x) for x in input().strip().split()]
n = int(input())
a = [[] for i in range(n)]
number = 1
for i in range(n):
	if i % 2 == 0:
		for j in range(n):
			a[j].append(number)
			number += 1
	else:
		for j in range(n - 1, -1, -1):
			a[j].append(number)
			number += 1
for i in range(n):
	print(*a[i])


n = int(input())
aux = []
for i in range(n):
	xx = [x for x in range(i * n + 1, i * n + n + 1)]
	if i & 1:
		xx = xx[::-1]
	aux.append(xx)
for i in range(n):
	ans = []
	for j in range(n):
		ans.append(aux[j][i])
	print(*ans)


n = int(input())
list1 = list()
for i in range(n):
	list1.append([])
t = 1
while t <= n * n:
	for j in range(n):
		list1[j].append(t)
		t += 1
	if t >= n * n:
		break
	for j in range(n):
		list1[n - j - 1].append(t)
		t += 1
for i in range(n):
	print(*list1[i])


n = int(input())
res = [[] for _ in range(n)]
dest = lambda x: x % n if x // n % 2 == 0 else n - x % n - 1
for i in range(0, n ** 2):
	res[dest(i)].append(i + 1)
for x in res:
	print(' '.join(map(str, x)))


n = int(input())
grp = [[] for i in range(n)]
nums = [i + 1 for i in range(n ** 2)]
flag = 1
j = 0
for i in range(n ** 2):
	grp[j].append(nums[i])
	if flag == 1:
		j += 1
		if j >= n:
			j -= 1
			flag = 0
	else:
		j -= 1
		if j <= -1:
			j += 1
			flag = 1
for i in grp:
	for j in i:
		print(j, end=' ')
	print('')


n = int(input())
t = 2 * n + 1
for i in range(n):
	p = i + 1
	ans = ''
	o = 0
	for j in range(n):
		ans += ' ' + str(p)
		if o == 0:
			p += t - 2 * (i + 1)
			o = 1
		else:
			p += t - 2 * (n - i)
			o = 0
	print(ans)


n = int(input())
matrix = []
for row in range(n):
	matrix.append([0 for i in range(n)])
a = n ** 2
for col in range(n):
	if col % 2 == 0:
		for row in range(n):
			matrix[row][col] = str(a)
			a -= 1
	else:
		for row in reversed(range(n)):
			matrix[row][col] = str(a)
			a -= 1
for i in matrix:
	print(' '.join(i))


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


n = int(input())

def printSet(i, n):
	global flag
	print(i, end=' ')
	cur = i
	for k in range(n - 1):
		if k % 2 == 0:
			cur += 1 + 2 * (n - i)
		else:
			cur += 1 + 2 * (i - 1)
		print(cur, end=' ')
for i in range(1, n + 1):
	printSet(i, n)
	print()


from collections import OrderedDict
n = int(input())
array = list(range(1, n + 1))
answer = OrderedDict()
x = 1
while x < n + 1:
	answer[x] = []
	x += 1
current = n * n
flag = 5
while True:
	if current < 1:
		break
	if flag == 5:
		x = 1
		while x < n + 1:
			answer[x].append(current)
			current -= 1
			x += 1
		flag = 6
	else:
		x = n
		while x > 0:
			answer[x].append(current)
			current -= 1
			x -= 1
		flag = 5
for it in answer:
	print(*answer[it])


import sys, atexit
from io import BytesIO
inp = BytesIO(sys.stdin.buffer.read())
input = lambda : inp.readline().decode('ascii')
buf = BytesIO()
atexit.register(lambda : sys.__stdout__.buffer.write(buf.getvalue()))
n = int(input())
ans = [[] for i in range(n)]
j = 0
t = 1
for i in range(n ** 2):
	ans[j].append(i + 1)
	if t:
		j += 1
	if j == n:
		t = 1 - t
	if not t:
		j -= 1
	if j == -1:
		t = 1 - t
		j += 1
for i in ans:
	print(*i)


n = int(input())
arr = []
for i in range(n):
	row = []
	j_range = range(1, n + 1)
	if i & 1:
		j_range = reversed(j_range)
	for j in j_range:
		row.append(i * n + j)
	arr.append(row)
for i in range(n):
	for j in range(n):
		print(arr[j][i], end=' ')
	print()


from sys import stdout
printn = lambda x: stdout.write(x)
inn = lambda : int(input())
inl = lambda : list(map(int, input().split()))
inm = lambda : map(int, input().split())
DBG = True and False
BIG = 999999999
R = 10 ** 9 + 7

def ddprint(x):
	if DBG:
		print(x)
n = inn()
g = [[] for i in range(n)]
for i in range(n):
	for j in range(n):
		suf = j if i % 2 == 0 else n - 1 - j
		k = n * i + j + 1
		ddprint('i {} j {} suf {} k {}'.format(i, j, suf, k))
		g[suf].append(k)
for i in range(n):
	for j in range(n):
		printn(('' if j == 0 else ' ') + str(g[i][j]))
	print('')


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


n = int(input())
k = list(range(1, n ** 2 + 1))
num = int(n / 2)
l = 0
r = n ** 2 - 1
m = int(len(k) / 2)
j = 1
for i in range(n):
	print(*k[l:l + num], end=' ')
	print(*k[r + 1 - num:r + 1], end=' ')
	l += num
	r += -num
	if n % 2 == 1:
		print(k[m], end=' ')
		if i % 2 == 0:
			m += j
			j += 1
		else:
			m -= j
			j += 1
	print()


n = int(input())
ans = []
for i in range(n):
	ka = [0] * n
	ans.append(ka)
cnt = 0
start = 0
yo = 0
ha = 1
while cnt != n:
	if start == 0:
		for j in range(n):
			ans[j][cnt] = ha
			ha += 1
	else:
		for j in range(n - 1, -1, -1):
			ans[j][cnt] = ha
			ha += 1
	yo += 1
	if yo % 2 == 0:
		start = 0
	else:
		start = n - 1
	cnt += 1
for i in ans:
	print(*i)


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


n = int(input())
l = [[] for i in range(n)]
for i in range(n):
	for j in range(n):
		temp = i * n + (j + 1)
		if i % 2:
			l[j].append(temp)
		else:
			l[n - 1 - j].append(temp)
for i in l:
	print(*i)


import sys
n = int(sys.stdin.readline())
a = n ** 2
count = 1
ans = [[-1 for _ in range(n)] for x in range(n)]
z = True
for i in range(n):
	if z:
		z = False
		for j in range(n):
			ans[j][i] = count
			count += 1
	else:
		z = True
		for j in range(n - 1, -1, -1):
			ans[j][i] = count
			count += 1
for i in range(n):
	print(*ans[i])


n = int(input())
c = 1
p = 0
a = [[0 for i in range(n)] for i in range(n)]
for i in range(n):
	p ^= 1
	for j in range(n):
		if p:
			a[j][i] = c
		else:
			a[n - j - 1][i] = c
		c += 1
for i in a:
	print(*i)


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


import sys
input = sys.stdin.buffer.readline
n = int(input())
res = [[] for _ in range(n)]
for i in range(n):
	for j in range(n):
		if i % 2:
			res[n - j - 1].append(i * n + j + 1)
		else:
			res[j].append(i * n + j + 1)
for r in res:
	print(*r)


n = int(input(''))
labs = n * n
countdown = labs
lists = [[] for i in range(n)]
curr = 0
up = True
while countdown > 0:
	lists[curr].append(countdown)
	countdown -= 1
	if up:
		if curr == n - 1:
			up = False
		else:
			curr += 1
	elif curr == 0:
		up = True
	else:
		curr -= 1
for i in lists:
	for entry in i:
		print(entry, end=' ')
	print('')


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


n = int(input())
counter = 1
B = [[0 for j in range(n)] for i in range(n)]
counter = 1
for c in range(n):
	if c % 2 == 0:
		for r in range(n):
			B[r][c] = counter
			counter += 1
	else:
		for r in range(n - 1, -1, -1):
			B[r][c] = counter
			counter += 1
for row in B:
	for c in row:
		print(c, end=' ')
	print()


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


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


n = int(input())
cnt = 1
matrix = []
matrix2 = []
for k in range(n):
	matrix.append([0] * n)
	matrix2.append([0] * n)
for i in range(n):
	for j in range(n):
		matrix[i][j] = cnt
		cnt += 1
for i in range(n):
	if i % 2 == 1:
		matrix[i] = matrix[i][::-1]
for i in range(n):
	for j in range(n):
		matrix2[i][j] = matrix[j][i]
for i in range(n):
	print(*matrix2[i])


n = int(input())
A = [[None for i in range(n + 1)] for j in range(n + 1)]
temp = 1
for i in range(1, n + 1):
	if i % 2 == 1:
		for j in range(1, n + 1):
			A[j][i] = temp
			temp += 1
	else:
		for j in reversed(range(1, n + 1)):
			A[j][i] = temp
			temp += 1
for i in range(1, n + 1):
	for j in range(1, n + 1):
		print(A[i][j], end=' ')
	print()


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


import math
n = int(input())
A = [i for i in range(int(math.pow(n, 2)))]
l = 1
r = len(A)
j = 0
D = {}
for i in range(1, n + 1):
	D.update({i: []})
while l < r:
	if j % 2 == 0:
		for i in range(1, n + 1):
			D[i].append(l)
			l += 1
	else:
		for i in range(1, n + 1):
			D[i].append(r)
			r -= 1
	j += 1
for i in sorted(D.keys()):
	print(*D[i], sep=' ')


n = int(input())
arr = [[] for _ in range(n)]
turn = 1
num = 1
count = 0
j = 0
for i in range(1, n ** 2 + 1):
	if turn == 1:
		arr[j % n].append(i)
	else:
		arr[n - (j + n) % n - 1].append(i)
	j += 1
	if j % n == 0 and turn == 1:
		turn = -1
	elif j % n == 0 and turn == -1:
		turn = 1
for i in range(n):
	print(*arr[i])


n = int(input())
number = [i for i in range(1, n ** 2 + 1)]
summa = 0
for i in number:
	summa += i
summa = summa / n
group1 = []
valid = 0
while len(number) != 0:
	group1 = []
	while len(group1) < n - 1:
		group1.append(number[0])
		group1.append(number[-1])
		del number[0]
		del number[-1]
	if len(group1) != n:
		group1.append(number[len(number) // 2])
		del number[len(number) // 2]
	answer = ''
	for i in group1:
		answer += str(i) + ' '
	print(answer)


n = int(input())
a = []
for i in range(n):
	a.append([])
p = 1
t = 0
d = 1
while p <= n * n:
	a[t].append(p)
	p += 1
	if not 0 <= t + d < n:
		d *= -1
	else:
		t += d
for x in a:
	print(*x)


x = int(input())
l = [[0 for i in range(x)] for j in range(x)]
p = 1
switch = 1
for i in range(0, x):
	for j in range(0, x):
		if switch == 1:
			l[j][i] = p
		else:
			l[x - j - 1][i] = p
		p += 1
	switch = 2 if switch == 1 else 1
for i in range(x):
	print(' '.join(map(str, l[i])))


n = int(input())
l = [[0] * n for i in range(n)]
k = n ** 2
for i in range(n):
	if i + 1 & 1:
		for j in range(n):
			l[j][i] = k
			k -= 1
	else:
		p = k - n + 1
		for j in range(n):
			l[j][i] = p
			p += 1
			k -= 1
for i in range(n):
	for j in range(n):
		print(l[i][j], end=' ')
	print()


import sys
input = sys.stdin.buffer.readline
from collections import defaultdict

def getlist():
	return list(map(int, input().split()))
con = 1000000007

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


n = int(input())
for i in range(1, n + 1):
	x = i
	for j in range(n):
		if j == 0:
			print(x, end=' ')
			y = x
		elif j % 2 != 0:
			s = 2 * n - 1 + y - 2 * (x - 1)
			print(s, end=' ')
			y = s
		elif j % 2 == 0:
			print(y + 1 + 2 * (x - 1), end=' ')
			y = y + 1 + 2 * (x - 1)
	print()


n = int(input())
l = [[] for i in range(n)]
i = 0
key = 0
go = 0
j = n * n
while j > 0:
	for k in range(n):
		l[k].append(j)
		j -= 1
	for k in range(n - 1, -1, -1):
		l[k].append(j)
		j -= 1
for i in l:
	for j in range(n):
		print(i[j], end=' ')
	print()


from sys import stdin
n = int(stdin.readline().rstrip())
l = [[0 for i in range(n)] for j in range(n)]
p = n ** 2
for i in range(n):
	if i % 2 != 1:
		for j in range(n):
			l[i][j] = p
			p -= 1
	else:
		for j in range(n - 1, -1, -1):
			l[i][j] = p
			p -= 1
for i in range(n):
	for j in range(n):
		print(str(l[j][i]) + ' ', end=' ')
	print()


n = int(input())
m = []
for _ in range(n):
	m.append([0] * n)
i = 0
j = 0
for t in range(n * n):
	m[i][j] = t + 1
	if j % 2 == 0:
		if i < n - 1:
			i += 1
		else:
			j += 1
	elif 0 < i:
		i -= 1
	else:
		j += 1
for i in m:
	for j in i:
		print(j, end=' ')
	print('')


from sys import stdin
import math
N = int(stdin.readline())
e = 1
for i in range(N):
	for j in range(N):
		if j % 2 == 0:
			print(N * j + e, end=' ')
		else:
			print(N * (j + 1) - (e - 1), end=' ')
	e += 1
	print()


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


n = int(input())
l = [[] for i in range(n)]
for i in range(n):
	for j in range(n):
		if i % 2 == 0:
			l[j].append(j + 1 + n * i)
		else:
			l[n - j - 1].append(j + 1 + n * i)
for i in range(n):
	for j in range(len(l[i])):
		l[i][j] = str(l[i][j])
	s = ' '.join(l[i])
	print(s)


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


from collections import defaultdict, deque
from itertools import permutations
from sys import stdin, stdout
from bisect import bisect_left, bisect_right
from copy import deepcopy
int_input = lambda : int(stdin.readline())
string_input = lambda : stdin.readline()
multi_int_input = lambda : map(int, stdin.readline().split())
multi_input = lambda : stdin.readline().split()
list_input = lambda : list(map(int, stdin.readline().split()))
string_list_input = lambda : list(string_input())
MOD = pow(10, 9) + 7
n = int_input()
final = [0] * n
for i in range(n):
	final[i] = []
k = 0
count = 0
l = 0
for i in range(1, n ** 2 + 1):
	final[l].append(i)
	count += 1
	if count == n:
		count = 0
		if k == 0:
			k = 1
		else:
			k = 0
	elif k == 0:
		l = (l + 1) % n
	elif k == 1:
		l = (l - 1) % n
for i in range(n):
	print(*final[i])


import sys
import math
from collections import defaultdict
from itertools import combinations
from itertools import permutations
input = lambda : sys.stdin.readline().rstrip()
read = lambda : map(int, input().split())

def write(*args, sep='\n'):
	for i in args:
		sys.stdout.write('{}'.format(i) + sep)
INF = float('inf')
MOD = int(1000000000.0 + 7)
n = int(input())
arr = [[-1] * n for i in range(n)]
cnt = 1
for j in range(n):
	x = range(n) if j % 2 == 0 else reversed(range(n))
	for i in x:
		arr[i][j] = cnt
		cnt += 1
[print(*i) for i in arr]


def ii():
	return int(input())

def fi():
	return float(input())

def si():
	return input()

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

def li():
	return list(mi())
n = ii()
a = 1
l = [[0] * 301 for i in range(301)]
b = n * n
for i in range(n):
	for j in range(n):
		if i % 2 == 0:
			l[i][j] = a
			a += 1
		else:
			l[i][j] = b
			b -= 1
for i in range(n):
	for j in range(n):
		print(l[j][i], end=' ')
	print()


n = int(input())
l = ['' for _ in range(n)]
f = False
for i in range(0, n * n):
	if i % n == 0:
		f = not f
	if f:
		l[i % n] += str(i + 1) + ' '
	else:
		l[n - 1 - i % n] += str(i + 1) + ' '
for x in l:
	print(x)


def rint():
	return int(input())

def rints():
	return list(map(int, input().split()))
n = rint()
g = [[] for _ in range(n)]
for i in range(n):
	for j in range(n):
		if i % 2 == 0:
			g[j].append(i * n + j + 1)
		else:
			g[n - 1 - j].append(i * n + j + 1)
for gi in g:
	print(' '.join(map(str, gi)))


import sys
input = sys.stdin.readline
n = int(input())
ans = []
s = 1
for i in range(n):
	temp = list(range(s, s + n))
	s += n
	if i % 2:
		ans.append(temp[::-1])
	else:
		ans.append(temp)
for i in zip(*ans):
	print(*i)


import io, sys, atexit, os
import math as ma
from sys import exit
from decimal import Decimal as dec
from itertools import permutations
from itertools import combinations

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

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

def nu():
	return int(input())

def find_gcd(x, y):
	while y:
		(x, y) = (y, x % y)
	return x

def lcm(x, y):
	gg = find_gcd(x, y)
	return x * y // gg

def fox(a, b):
	xp = b // 2
	ox = min(xp, a)
	oz = a - ox
	oi = b - ox * 2
	return (oz, oi, ox * 3)
mm = 1000000007

def solve():
	t = 1
	for tt in range(t):
		n = nu()
		x = [0] * n
		for i in range(n):
			x[i] = [0] * n
		j = 0
		i = 0
		cc = 1
		while j < n:
			if j % 2 == 0:
				while i < n:
					x[i][j] = cc
					cc += 1
					i += 1
				i -= 1
				j += 1
			else:
				while i >= 0:
					x[i][j] = cc
					cc += 1
					i -= 1
				i += 1
				j += 1
		for i in range(n):
			print(*x[i])
solve()


import sys
input = sys.stdin.readline
sys.setrecursionlimit(100000)

def getN():
	return int(input())

def getList():
	return list(map(int, input().split()))
import math

def main():
	n = getN()
	labs = [[] for i in range(n)]
	for i in range(1, n ** 2 + 1):
		target = (i - 1) % n
		if (i - 1) // n % 2 == 1:
			target = n - 1 - target
		labs[target].append(i)
	for lab in labs:
		print(*lab)
main()


import sys
import os
from io import BytesIO, IOBase
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')
mod = 10 ** 9 + 7

def lcm(x, y):
	return x * y / gcd(x, y)

def fact(x, mod=mod):
	ans = 1
	for i in range(1, x + 1):
		ans = ans * i % mod
	return ans

def arr2D(n, m, default=0):
	return [[default for j in range(m)] for i in range(n)]

def arr3D(n, m, r, default=0):
	return [[[default for k in range(r)] for j in range(m)] for i in range(n)]

def sortDictV(x):
	return {k: v for (k, v) in sorted(x.items(), key=lambda item: item[1])}

class DSU:

	def __init__(self, length):
		self.length = length
		self.parent = [-1] * self.length

	def getParent(self, node, start):
		if node >= self.length:
			return False
		if self.parent[node] < 0:
			if start != node:
				self.parent[start] = node
			return node
		return self.getParent(self.parent[node], start)

	def union(self, node1, node2):
		parent1 = self.getParent(node1, node1)
		parent2 = self.getParent(node2, node2)
		if parent1 == parent2:
			return False
		elif self.parent[parent1] <= self.parent[parent2]:
			self.parent[parent1] += self.parent[parent2]
			self.parent[parent2] = parent1
		else:
			self.parent[parent2] += self.parent[parent1]
			self.parent[parent1] = parent2
		return True

	def getCount(self, node):
		return -self.parent[self.getParent(node, node)]

def exact(num):
	if abs(num - round(num)) <= 10 ** (-9):
		return round(num)
	return num

def solve(n):
	num = list(range(1, n * n + 1))
	lst = []
	for i in range(n):
		lst.append([])
	maxx = n * n
	minn = 1
	while minn < maxx:
		for i in range(n):
			lst[i].append(minn)
			lst[i].append(maxx)
			minn += 1
			maxx -= 1
	if n % 2:
		for i in lst:
			for j in range(len(i)):
				if j != n:
					print(i[j], end=' ')
			print()
	else:
		for i in lst:
			for j in i:
				print(j, end=' ')
			print()
n = int(input())
solve(n)


n = int(input())
delta = []
for i in range(1, n + 1):
	delta.append(i)
res = [[0] * n for i in range(n)]
flag = 0
for j in range(n):
	k = 0
	flag = flag ^ 1
	if flag == 1:
		for i in range(n):
			res[i][j] = delta[k]
			k += 1
	if flag == 0:
		for i in range(n - 1, -1, -1):
			res[i][j] = delta[k]
			k += 1
	for i in range(n):
		delta[i] += n
for i in range(n):
	for j in range(n):
		print(res[i][j], end=' ')
	print('')


n = int(input())
flag = 0
cnt = 1
ans = []
for i in range(n):
	temp = []
	for j in range(n):
		temp.append(0)
	ans.append(temp)
for i in range(n):
	for j in range(n):
		if flag == 0:
			ans[j][i] = cnt
		else:
			ans[n - 1 - j][i] = cnt
		cnt += 1
	if flag == 0:
		flag = 1
	else:
		flag = 0
for i in ans:
	print(*i)


n = int(input())
ans = [[] * 1 for i in range(n)]
v = 1
nap = 0
s = 0
for i in range(1, n * n + 1):
	ans[s].append(i)
	if nap == 0:
		s += 1
	else:
		s -= 1
	if s == n:
		nap = 1
		s -= 1
	elif s == -1:
		nap = 0
		s += 1
for i in range(n):
	print(*ans[i])


def mp():
	return map(int, input().split())
n = int(input())
a = [[0] * n for i in range(n)]
for i in range(n):
	if i % 2:
		for j in range(n):
			a[j][i] = i * n + j + 1
	else:
		for j in range(n - 1, -1, -1):
			a[j][i] = i * n + (n - j - 1) + 1
for i in a:
	print(*i)


n = int(input())
arr = []
for i in range(0, n):
	arr.append([j + i * n for j in range(1, n + 1)])
out_arr = [[] for i in range(n)]
for i in range(n):
	for j in range(n):
		if j % 2 == 0:
			out_arr[i].append(str(arr[j][i]))
		else:
			out_arr[i].append(str(arr[j][n - i - 1]))
for i in out_arr:
	print(' '.join(i))


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


import sys
import math as mt
input = sys.stdin.buffer.readline
mod = 10 ** 9 + 7
t = 1
for __ in range(t):
	n = int(input())
	to = n * n
	d = {}
	for i in range(n):
		d[i] = []
	cnt = 1
	i = 0
	ch = 0
	while cnt < n * n:
		if ch % 2 == 0:
			i = 0
			while i < n:
				d[i].append(cnt)
				cnt += 1
				i += 1
		else:
			i = n - 1
			while i >= 0:
				d[i].append(cnt)
				cnt += 1
				i -= 1
		ch += 1
	for i in range(n):
		print(*d[i])


import sys

def input():
	return sys.stdin.readline()[:-1]

def main():
	n = int(input())
	t = [[0 for l in range(n)] for k in range(n)]
	for q in range(n):
		for p in range(n):
			if p % 2 == 0:
				t[p][q] = n * p + q + 1
			else:
				t[p][-q - 1] = n * p + q + 1
	ans = [[0 for l in range(n)] for k in range(n)]
	for q in range(n):
		for p in range(n):
			ans[p][q] = t[q][p]
	for e in ans:
		print(*e, sep=' ')
main()


n = int(input())
a = list()
for i in range(n):
	a.append([0 for j in range(n)])
up = True
num = 1
for i in range(n):
	if up:
		for j in range(n):
			a[j][i] = num
			num += 1
		up = False
	else:
		j = n - 1
		while j >= 0:
			a[j][i] = num
			num += 1
			j -= 1
		up = True
for i in range(n):
	for j in range(n):
		print(a[i][j], end=' ')
	print()


import os
import sys
from math import *
from collections import *
from fractions import *
from heapq import *
from bisect import *
from io import BytesIO, IOBase

def vsInput():
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')
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')
ALPHA = 'abcdefghijklmnopqrstuvwxyz'
M = 998244353
EPS = 1e-06

def value():
	return tuple(map(int, input().split()))

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

def Int():
	return int(input())

def Str():
	return input()

def arrayS():
	return [i for i in input().split()]
n = Int()
a = [[0 for i in range(n)] for i in range(n)]
c = 1
for i in range(n):
	for j in range(n):
		if i % 2:
			a[i][n - 1 - j] = c
		else:
			a[i][j] = c
		c += 1
for i in range(n):
	for j in range(n):
		print(a[j][i], end=' ')
	print()


n = int(input().strip())
n2 = n ** 2
L = [x for x in range(1, n2 + 1)]
M = [[] for i in range(n)]
i = 0
t = 0
while i < n2:
	if t % 2 == 0:
		for j in range(n):
			M[j].append(str(L[i]))
			i += 1
	else:
		for j in range(n - 1, -1, -1):
			M[j].append(str(L[i]))
			i += 1
	t += 1
for i in M:
	print(' '.join(i))


from collections import defaultdict
a = defaultdict(list)
n = int(input())
k = 1
for i in range(n):
	for j in range(n):
		if (i + 1) % 2 == 0:
			a[n - j - 1].append(k)
			k += 1
		if (i + 1) % 2 != 0:
			a[j].append(k)
			k += 1
for i in range(n):
	print(*a[i])


elem = int(input())
for x in range(elem):
	curr = 0
	ar = []
	for y in range(elem):
		if y % 2 == 0:
			ar.append(curr * elem + x + 1)
			curr = curr + 2
		else:
			ar.append(curr * elem - x)
	print(*ar)


import sys
input = sys.stdin.readline

def ceil(x):
	if x != int(x):
		x = int(x) + 1
	return x

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=None):
	if hi == None:
		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(100000.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())
ans = [[0 for _ in range(n)] for __ in range(n)]
for j in range(n):
	if j & 1:
		start = (j + 1) * n
		for i in range(n):
			ans[i][j] = start
			start -= 1
	else:
		start = j * n + 1
		for i in range(n):
			ans[i][j] = start
			start += 1
for i in ans:
	print(*i)


import sys
try:
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')
except:
	pass
input = sys.stdin.readline
n = int(input())
ans = [[] for _ in range(n)]
for i in range(1, n ** 2 + 1):
	if (i - 1) // n & 1:
		ans[~((i - 1) % n)].append(i)
	else:
		ans[(i - 1) % n].append(i)
for arr in ans:
	print(*arr)


n = int(input())
i = 0
rows = []
for i in range(n):
	rows.append([])
for j in range(n):
	for i in range(n):
		if j % 2 == 0:
			rows[i].append(str(i + j * n + 1))
		else:
			rows[i].append(str(n - i - 1 + j * n + 1))
for row in rows:
	print(' '.join(row))


n = int(input())
r = [[] for i in range(n)]
w = True
t = 0
spisok = [int(i) for i in range(1, n ** 2 + 1)]
for i in range(n):
	if w:
		for j in range(n):
			r[j].append(spisok[t])
			t += 1
		w = False
	else:
		for j in range(n):
			r[n - j - 1].append(spisok[t])
			t += 1
		w = True
for i in r:
	print(*i)


n = int(input())
b = []
for _ in range(n):
	b.append([0] * n)
for i in range(n):
	for j in range(n):
		if i <= n // 2:
			b[j][i] = i * n + j + 1
			b[j][n - i - 1] = (n - i - 1) * n + (n - j)
for i in range(n):
	print(*b[i])


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


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


n = int(input())
A = []
s = 1
for i in range(n):
	if i % 2 == 0:
		v = 1
	else:
		v = -1
	A.append([i for i in range(s, s + n)][::v])
	s += n
B = [[A[-i - 1][-j - 1] for i in range(n)] for j in range(n)]
for i in range(n):
	print(' '.join([str(i) for i in B[i]]))


n = int(input())
l = []
for i in range(n):
	d = []
	for j in range(n):
		d.append(0)
	l.append(d)
f = 0
c = 1
for i in range(n):
	if f % 2 == 0:
		for j in range(n):
			l[j][i] = c
			c += 1
	else:
		for j in range(n - 1, -1, -1):
			l[j][i] = c
			c += 1
	f = 1 - f
for i in range(n):
	print(*l[i])


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


n = int(input())
groups = [[] for i in range(n)]
idx = n - 1
c = -1
for i in range(1, n * n + 1, n):
	if (i - 1) % n == 0:
		idx = n - 1 - idx
		c *= -1
	for j in range(i, i + n):
		groups[n - 1 - idx + c * (i - j)].append(j)
for gp in groups:
	print(*gp)


import sys, math
input = sys.stdin.readline
n = int(input())
a = [[] for i in range(n)]
for i in range(n * n):
	q = i + 1
	if math.ceil(q / n) % 2 != 0:
		w = q % n
		if q % n == 0:
			w = n
		a[w - 1].append(q)
	else:
		w = q % n
		if q % n == 0:
			w = n
		a[n - w].append(q)
for i in range(n):
	print(*a[i])


n = int(input())
ans = [[] for i in range(n)]
flag = 0
for i in range(1, n * n + 1):
	if flag == 0:
		c = i % n
		ans[c - 1].append(i)
		if c == 0:
			flag = 1
	else:
		c = n - i % n
		if c == n:
			flag = 0
			c = 0
		ans[c].append(i)
for op in ans:
	for a in op:
		print(a, end=' ')
	print()


n = int(input())
arr = []
for i in range(n):
	arr.append([])
k = 1
pos = 0
right = 1
while k <= n * n:
	arr[pos].append(k)
	if pos == n - 1 and right == 1:
		right = 0
	elif pos == 0 and right == 0:
		right = 1
	elif right == 1:
		pos += 1
	else:
		pos -= 1
	k += 1
for i in arr:
	print(*i)


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


n = int(input())
arrs = [[None] * n for _ in range(n)]
num = 1
for i in range(n):
	for j in range(n):
		if i % 2 == 0:
			arrs[j][i] = num
		else:
			arrs[n - j - 1][i] = num
		num += 1
for arr in arrs:
	print(*arr)


n = int(input())
ans = [[0 for i in range(n)] for j in range(n)]
i = 1
row = n - 1
col = 0
while i <= n * n:
	ans[row][col] = i
	if i % n == 0:
		col = col + 1
	elif col % 2 == 0:
		row = row + 1
		row = row % n
	else:
		row = row + n - 1
		row = row % n
	i += 1
for row in ans:
	for el in row:
		print(el, end=' ')
	print()


n = int(input())
ans = []
for i in range(1, n + 1):
	arr = []
	for j in range(n):
		if j % 2 == 1:
			arr.append((j // 2 + 1) * 2 * n - i + 1)
		else:
			arr.append(j * n + i)
	print(*arr, sep=' ')


n = int(input())
s = [[] for i in range(n)]
f = [0 for i in range(n * n)]
k = 1
for a in range(n):
	if k % 2 > 0:
		for i in range(n):
			f[a * n + i] = i
	else:
		for i in range(n - 1, -1, -1):
			f[a * n + n - 1 - i] = i
	k += 1
for i in range(n * n):
	s[f[i]].append(i + 1)
for i in range(n):
	for j in range(n):
		print(s[i][j], end=' ')
	print()


n = int(input())
a = []
tiling = [0] * n
for i in range(len(tiling)):
	tiling[i] = i + 1
for i in range(n):
	a.append(tiling.copy())
	tiling = list(reversed(tiling))
newa = []
for i in range(len(a)):
	for j in range(len(a[i])):
		newa.append(a[i][j])
a = newa.copy()
arrAns = []
for i in range(n):
	arrAns.append([])
for i in range(len(a)):
	arrAns[a[i] - 1].append(i + 1)
for i in range(len(arrAns)):
	print(' '.join(list(map(str, arrAns[i]))))


n = int(input(''))
ns = n ** 2
for i in range(1, n + 1, 1):
	c = 0
	d = 2 * (n - i + 1) - 1
	j = i
	while j <= ns:
		print(j, end=' ')
		if c == 0:
			j = j + d
		else:
			j = j + 2 * n - d
		c = c ^ 1
	print('')


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


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


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


n = int(input())
lists = []
for i in range(n):
	lists.append([])
curr = 0
toggle = 1
for i in range(n):
	for j in range(n):
		curr += 1
		if toggle == 1:
			lists[j].append(curr)
		else:
			lists[n - 1 - j].append(curr)
	toggle ^= 1
for lst in lists:
	print(*lst)


n = int(input())
ans = [[] for _ in range(n)]
for i in range(n ** 2):
	j = i % (n * 2)
	if j >= n:
		j = 2 * n - j - 1
	ans[j].append(i + 1)
for i in range(n):
	print(*ans[i])


n = int(input())
groups = []
for _ in range(n):
	groups.append([])
gr = pow(n, 2)
for i in range(gr):
	if i < n * (n // 2):
		groups[i % n].append(i + 1)
	else:
		groups[n - (i % n + 1)].append(i + 1)
for g in groups:
	print(*g)


import sys

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

def list2d(a, b, c):
	return [[c] * b for i in range(a)]

def list3d(a, b, c, d):
	return [[[d] * c for j in range(b)] for i in range(a)]

def list4d(a, b, c, d, e):
	return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]

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

def INT():
	return int(input())

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

def LIST(N=None):
	return list(MAP()) if N is None else [INT() for i in range(N)]

def Yes():
	print('Yes')

def No():
	print('No')

def YES():
	print('YES')

def NO():
	print('NO')
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7
N = INT()
cnt = 1
ans = []
for i in range(N):
	row = []
	for j in range(N):
		row.append(cnt)
		cnt += 1
	if i % 2 == 1:
		row = row[::-1]
	ans.append(row)
ans = list(zip(*ans))
[print(*row) for row in ans]


import sys
readline = sys.stdin.readline
N = int(readline())
Ans = [[] for _ in range(N)]
for i in range(N):
	if i & 1:
		for j in range(N):
			Ans[j].append(1 + i * N + j)
	else:
		for j in range(N):
			Ans[j].append(1 + i * N + (N - 1) - j)
for a in Ans:
	print(*a)


import sys
n = int(sys.stdin.readline())
arr = []
for a in range(n):
	tmp = []
	for b in range(n):
		tmp.append(0)
	arr.append(tmp)
e = 1
ind = 0
while e <= n * n:
	if ind % 2 == 0:
		for f in range(n):
			arr[f][ind] = e
			e += 1
	else:
		for f in range(n - 1, -1, -1):
			arr[f][ind] = e
			e += 1
	ind += 1
for g in range(n):
	for h in range(n):
		print(arr[g][h], end=' ')
	print()


import sys, os, io

def rs():
	return sys.stdin.readline().rstrip()

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

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

def ws(s):
	sys.stdout.write(s + '\n')

def wi(n):
	sys.stdout.write(str(n) + '\n')

def wia(a):
	sys.stdout.write(' '.join([str(x) for x in a]) + '\n')
import math, datetime, functools, itertools
from collections import deque, defaultdict, OrderedDict
import collections

def main():
	starttime = datetime.datetime.now()
	if os.path.exists('input.txt'):
		sys.stdin = open('input.txt', 'r')
		sys.stdout = open('output.txt', 'w')
	for _ in range(1):
		n = ri()
		a = []
		for i in range(n):
			a.append([0] * n)
		c = 0
		for j in range(n):
			if j % 2 == 0:
				for i in range(n):
					c += 1
					a[i][j] = c
			else:
				for i in range(n - 1, -1, -1):
					c += 1
					a[i][j] = c
		for i in a:
			wia(i)
	endtime = datetime.datetime.now()
	time = (endtime - starttime).total_seconds() * 1000
	if os.path.exists('input.txt'):
		print('Time:', time, 'ms')

class FastReader(io.IOBase):
	newlines = 0

	def __init__(self, fd, chunk_size=1024 * 8):
		self._fd = fd
		self._chunk_size = chunk_size
		self.buffer = io.BytesIO()

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, self._chunk_size))
			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, size=-1):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, self._chunk_size if size == -1 else size))
			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()

class FastWriter(io.IOBase):

	def __init__(self, fd):
		self._fd = fd
		self.buffer = io.BytesIO()
		self.write = self.buffer.write

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

class FastStdin(io.IOBase):

	def __init__(self, fd=0):
		self.buffer = FastReader(fd)
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')

class FastStdout(io.IOBase):

	def __init__(self, fd=1):
		self.buffer = FastWriter(fd)
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.flush = self.buffer.flush
sys.stdin = FastStdin()
sys.stdout = FastStdout()
main()


from os import path
import sys
from math import ceil, floor, gcd, log, log2, factorial
from collections import defaultdict, Counter
from itertools import permutations
maxx = float('inf')
I = lambda : int(sys.stdin.buffer.readline())
tup = lambda : map(int, sys.stdin.buffer.readline().split())
lint = lambda : [int(x) for x in sys.stdin.buffer.readline().split()]
S = lambda : sys.stdin.readline().replace('\n', '').strip()

def grid(r, c):
	return [lint() for i in range(r)]
stpr = lambda x: sys.stdout.write(f'{x}' + '\n')
star = lambda x: print(' '.join(map(str, x)))
if path.exists('input.txt'):
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')
n = I()
for i in range(n):
	for j in range(n):
		print(j * n + i + 1, end=' ') if j % 2 == 0 else print((j + 1) * n - i, end=' ')
	print()


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