Read problem statements in [Hindi], [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well.

Chef is working on a small project ― he is building a cyberorganism. In his current design, the cyberorganism is an $N \times N \times N$ cube consisting of $N^{3}$ cells. Let's denote the cells by $(x, y, z)$, where $1 ≤ x, y, z ≤ N$.

Chef is currently working on the cyberorganism's self-defense mechanism against viruses. So far, he has figured out that viruses behave in the following way:
When the cyberorganism is infected by a virus, some of its cells immediately become infected, while the remaining ones stay healthy (so far).
Afterwards, the virus spreads itself. Whenever there is an infected cell $(x, y, z)$, the cells $(x + 1, y, z)$, $(x, y + 1, z)$ and $(x, y, z + 1)$ become infected as well (if they exist, i.e. the infection does not propagate outside the cyberorganism).
The virus continues spreading itself until there are no more cells that can be infected this way.

Chef noticed that it is possible for the cyberorganism to reorganise itself right after the initial infection (before the virus starts spreading). The cyberorganism can use this opportunity to make itself less vulnerable to the virus (i.e. minimise the number of infected cells after the virus finishes spreading).

The cyberorganism can reorganise itself by changing the order of the rows, columns and layers of its cells. In other words, it can choose three permutations $P, Q, R$ of the integers $1$ through $N$ (each permutation can be chosen independently from the other two) and reorganise itself in such a way that for each valid $x, y, z$, the cell $(P_{x}, Q_{y}, R_{z})$ before the reorganisation becomes the cell $(x, y, z)$ afterwards. If this cell was infected before the reorganisation, then it remains infected afterwards, and if it was healthy, it remains healthy afterwards ― only the coordinates of the infected and healthy cells change.

Chef has struggled for some time with an efficient self-defense mechanism and now, he has decided to ask for your help. You are given the coordinates of the cells that are infected initially. Determine how to reorganise the cyberorganism in order to minimise the number of cells that are infected after the virus finishes spreading.

------  Input ------
The first line of the input contains a single integer $N$.
$N^{2}$ lines follow, where each block of $N$ lines describes a layer of the cube. Each of these lines contains a string with length $N$. For each valid $x, y, z$, the $x$-th character on the $(z-1)N+y$-th line is '1' if the cell $(x, y, z)$ is initially infected or '0' if this cell is initially healthy.

------  Output ------
Print three lines.
The first line should contain $N$ space-separated integers $P_{1}, P_{2}, \ldots, P_{N}$.
The second line should contain $N$ space-separated integers $Q_{1}, Q_{2}, \ldots, Q_{N}$.
Finally, the third line should contain $N$ space-separated integers $R_{1}, R_{2}, \ldots, R_{N}$.

------  Constraints ------
$3 ≤ N ≤ 100$
all strings on the input contain only characters '0' and '1'
initially, there is at least one healthy cell

------  Scoring ------
In each test case (and therefore each test file), let $C$ be the number of initially infected cells and $K$ be the number of healthy cells after the virus stops spreading. If $K = 0$, your submission will receive the Wrong Answer verdict. Otherwise, your score for this test case is equal to $K \cdot (\frac{C}{N^{3}})^{1.5}$. The score of a submission is equal to the sum of its scores over all test cases. The goal is to maximise the score of your submission.

There are 20 test files. During the contest, the displayed score will account for exactly four test files (numbered 2, 7, 12 and 17, see the Test Generation section), i.e. your score reflects your submission's performance on 20% (4 / 20) of the test files. However, if your program gets a non-AC verdict on any test file, your submission's verdict will be non-AC. In other words, an AC verdict denotes that your program runs successfully on all the test files. After the end of the contest, your score will be changed to include the sum of your program's scores over the other 16 test files.

------  Example Input ------

3
011
100
010
011
010
100
000
000
010

------  Example Output ------

1 3 2
1 2 3
3 2 1

------  Explanation ------
After reorganising, the state of the cyberorganism is (using the same format as on the input, with an extra line between each two blocks of $N$ lines)

000
000
001

011
001
100

011
100
001

After the virus spreads, the state of the cyberorganism becomes

000
000
001

011
011
111

011
111
111

There are $9$ infected cells in the initial state and $11$ healthy cells in the final state, so the score of this output is $11 \cdot (\frac{9}{3^{3}})^{1.5} \approx 2.117$.

------  Test generation ------
$N = 100$ in all test cases (except for the example).
There are 20 test cases (numbered $0$ through $19$). In all test cases, the strings describing the initial state are generated independently and randomly.
For each valid $k$, each cell in the $k$-th test case is initially infected with probability $P$ or healthy with probability $1-P$, where $P = 0.8^{k + 3}$ is fixed.

Source: codechef | Difficulty: VERY_HARD


Solutions:
n = int(input())
mat = list()
(dpx, dpy, dpz) = (dict(), dict(), dict())
healthy = list()
for i in range(1, n + 1):
	dpx[i] = dpy[i] = dpz[i] = 0
for i in range(1, n + 1):
	mat.append(list())
	for j in range(1, n + 1):
		mat[i - 1].append(list())
		s = input()
		for k in range(1, n + 1):
			mat[i - 1][j - 1].append(int(s[k - 1]))
			if s[k - 1] == '0':
				dpx[j] += 1
				dpy[k] += 1
				dpz[i] += 1
				healthy.append([j, k, i])
(p, q, r) = (list(), list(), list())
for i in sorted(dpx.items(), key=lambda kv: (kv[1], kv[0])):
	p.append(i[0])
for i in sorted(dpy.items(), key=lambda kv: (kv[1], kv[0])):
	q.append(i[0])
for i in sorted(dpz.items(), key=lambda kv: (kv[1], kv[0])):
	r.append(i[0])
for i in range(1, n + 1):
	if i not in p:
		p.append(i)
	if i not in q:
		q.append(i)
	if i not in r:
		r.append(i)
if mat[p[0]][q[0]][r[0]]:
	for i in healthy:
		(t1, t2, t3) = (p.index(i[0]), q.index(i[1]), r.index(i[2]))
		temp = p[0]
		p[0] = i[0]
		p[t1] = temp
		temp = q[0]
		q[0] = i[1]
		q[t2] = temp
		temp = r[0]
		temp = r[0]
		r[0] = i[2]
		r[t3] = temp
print(*p)
print(*q)
print(*r)


n = int(input())
a = [[] for x in range(n)]
for t1 in range(n):
	for t2 in range(n):
		a[t1].append([int(x) for x in input()])
for g in range(3):
	a_x = [[] for x in range(n)]
	for x_axis in range(n):
		for z_axis in range(n):
			li = []
			for y_axis in range(n):
				li.append(a[z_axis][y_axis][x_axis])
			a_x[x_axis].append(li)
	lis = [0 for x in range(n)]
	for x_axis in range(n):
		max1 = n
		for i in range(n):
			if max1 == 0:
				break
			j = 0
			while j < max1:
				if a_x[x_axis][i][j] == 1:
					lis[x_axis] += (max1 - j) * (n - i)
					max1 = j
					break
				j += 1
	listing = []
	for t in range(n):
		listing.append([t, lis[t]])
	listing.sort(key=lambda x: x[1])
	l4 = [str(x[0] + 1) for x in listing]
	print(' '.join(l4))
	a_new = []
	for i in listing:
		a_new.append(a_x[i[0]])
	a = a_new


def merge(arr, l, m, r):
	n1 = m - l + 1
	n2 = r - m
	L = [0] * n1
	R = [0] * n2
	for i in range(0, n1):
		L[i] = arr[l + i]
	for j in range(0, n2):
		R[j] = arr[m + 1 + j]
	i = 0
	j = 0
	k = l
	while i < n1 and j < n2:
		if L[i][0] <= R[j][0]:
			arr[k] = L[i]
			i += 1
		else:
			arr[k] = R[j]
			j += 1
		k += 1
	while i < n1:
		arr[k] = L[i]
		i += 1
		k += 1
	while j < n2:
		arr[k] = R[j]
		j += 1
		k += 1

def mergeSort(arr, l, r):
	if l < r:
		m = l + (r - 1)
		mergeSort(arr, l, m)
		mergeSort(arr, m + 1, r)
		merge(arr, l, m, r)
n = int(input())
l = []
p = [0] * n
q = [n * n] * n
r = [n * n] * n
for i in range(n ** 2):
	if i % n == 0:
		l.append([])
	l[-1].append(list(map(int, list(input()))))
	for i in range(n):
		p[i] += l[-1][-1][i]
for i in range(n):
	p[i] = [p[i], i]
mergeSort(p, 0, n - 1)
for i in range(n):
	for j in range(n):
		for k in range(n):
			if l[j][i][p[k][1]] == 1:
				break
			q[i] -= 1
for i in range(n):
	q[i] = [q[i], i]
mergeSort(q, 0, n - 1)
for i in range(n):
	j = 0
	b = n
	while j < n:
		k = 0
		while k < b:
			if l[i][q[j][1]][p[k][1]] == 1:
				b = k
				break
			r[i] -= 1
			k += 1
		if b == 0:
			break
		j += 1
for i in range(n):
	r[i] = [r[i], i]
mergeSort(r, 0, n - 1)
healthy = 0
h = [n] * n
for i in range(n):
	for j in range(n):
		if j != 0 and h[j] > h[j - 1]:
			h[j] = h[j - 1]
		for k in range(h[j]):
			if l[r[i][1]][q[j][1]][p[k][1]] == 1:
				h[j] = k
				break
			healthy += 1
d = {}
d[healthy] = [p, q, r]
count = 0
while True:
	if count == 100:
		break
	p1 = [n * n] * n
	q1 = [n * n] * n
	r1 = [n * n] * n
	for i in range(n):
		j = 0
		b = n
		while j < n:
			k = 0
			while k < b:
				if l[r[k][1]][q[j][1]][i] == 1:
					b = k
					break
				p1[i] -= 1
				k += 1
			if b == 0:
				break
			j += 1
	for i in range(n):
		p1[i] = [p1[i], i]
	mergeSort(p1, 0, n - 1)
	p = p1
	for i in range(n):
		j = 0
		b = n
		while j < n:
			k = 0
			while k < b:
				if l[r[k][1]][i][p[j][1]] == 1:
					b = k
					break
				q1[i] -= 1
				k += 1
			if b == 0:
				break
			j += 1
	for i in range(n):
		q1[i] = [q1[i], i]
	mergeSort(q1, 0, n - 1)
	q = q1
	for i in range(n):
		j = 0
		b = n
		while j < n:
			k = 0
			while k < b:
				if l[i][q[j][1]][p[k][1]] == 1:
					b = k
					break
				r1[i] -= 1
				k += 1
			if b == 0:
				break
			j += 1
	for i in range(n):
		r1[i] = [r1[i], i]
	mergeSort(r1, 0, n - 1)
	r = r1
	healthy = 0
	h = [n] * n
	for i in range(n):
		for j in range(n):
			if j != 0 and h[j] > h[j - 1]:
				h[j] = h[j - 1]
			for k in range(h[j]):
				if l[r[i][1]][q[j][1]][p[k][1]] == 1:
					h[j] = k
					break
				healthy += 1
	d[healthy] = [p, q, r]
	count += 1
m = max(d.keys())
(p, q, r) = d[m]
for i in range(n):
	print(p[i][1] + 1, end=' ')
print()
for i in range(n):
	print(q[i][1] + 1, end=' ')
print()
for i in range(n):
	print(r[i][1] + 1, end=' ')
print()


N = int(input())
cube = [[[0 for i in range(N)] for j in range(N)] for k in range(N)]
(maxizeros, yz, zz) = (0, -1, -1)
allzeros = []
for z in range(N):
	for y in range(N):
		cinp = list(map(int, input().strip()))
		czeros = 0
		for x in range(N):
			cube[z][y][x] = cinp[x]
			if cinp[x] == 0:
				czeros += 1
				allzeros.append([x, y, z])
		if czeros > maxizeros:
			(maxizeros, yz, zz) = (czeros, y, z)
(Xused, Yused, Zused) = ([False] * N, [False] * N, [False] * N)
(X, Y, Z) = ([], [yz], [zz])
Yused[yz] = Zused[zz] = True
for i in allzeros:
	if i[1] == yz and i[2] == zz:
		X.append(i[0])
		Xused[i[0]] = True
rem = []
for i in range(N):
	if not Xused[i]:
		rem.append(i)
while rem:
	X.append(rem.pop())
(cx, cz) = (X[0], zz)
for i in allzeros:
	if i[1] != yz and i[0] == cx and (i[2] == cz):
		Y.append(i[1])
		Yused[i[1]] = True
rem = []
for i in range(N):
	if not Yused[i]:
		rem.append(i)
while rem:
	Y.append(rem.pop())
rem = []
for i in range(N):
	if not Zused[i]:
		rem.append(i)
while rem:
	Z.append(rem.pop())
for i in X:
	print(i + 1, end=' ')
print()
for i in Y:
	print(i + 1, end=' ')
print()
for i in Z:
	print(i + 1, end=' ')
print()


n = int(input())
cube = []
for i in range(n):
	temp = []
	for j in range(n):
		l = [int(i) for i in input()]
		temp.append(l)
	cube.append(temp)
sheets = {}
cols = {}
rows = {}
for i in range(n):
	ss = 0
	for j in range(n):
		s = 0
		for k in range(n):
			s += cube[i][j][k]
		ss += s
	sheets[i + 1] = ss
r = [i[0] for i in sorted(sheets.items(), key=lambda x: x[1])]
for i in range(n):
	ss = 0
	for j in range(n):
		s = 0
		for k in range(n):
			s += cube[j][i][k]
		ss += s
	rows[i + 1] = ss
q = [i[0] for i in sorted(rows.items(), key=lambda x: x[1])]
for i in range(n):
	ss = 0
	for j in range(n):
		s = 0
		for k in range(n):
			s += cube[k][j][i]
		ss += s
	cols[i + 1] = ss
p = [i[0] for i in sorted(cols.items(), key=lambda x: x[1])]
if cube[p[0] - 1][q[0] - 1][r[0] - 1] == 1:
	p = list(range(1, n + 1))
	q = list(range(1, n + 1))
	r = list(range(1, n + 1))
	flag = False
	for i in range(n):
		for j in range(n):
			for k in range(n):
				if cube[i][j][k] == 0:
					p[k] = 1
					p[0] = k + 1
					q[j] = 1
					q[0] = j + 1
					r[i] = 1
					r[0] = i + 1
					flag = True
					break
			if flag:
				break
		if flag:
			break
print(*p, sep=' ')
print(*q, sep=' ')
print(*r, sep=' ')


import numpy as np
whatever = 1

def index(l, p):
	return [l[i] for i in p]

def rule(score1, score2, score3):
	if whatever == 0:
		return (score3, score2)
	else:
		return score3

def solve(cube):
	tupList = []
	sortedIdx1 = range(n)
	sortedIdx2 = range(n)
	sortedIdx3 = range(n)
	useCube = cube
	nextDimension = 0
	times = 750
	for i in range(times):
		whatever = np.random.choice(2, p=[0.1, 0.9])
		if nextDimension == 0:
			tupList = []
			for i in range(n):
				idx = np.where(useCube[i, :, :] == 1)
				if len(idx[0]) == 0:
					tup = rule(np.inf, np.inf, np.inf)
				else:
					minIdx = min(np.min(idx[0]), np.min(idx[1]))
					arry = (n - idx[0]) * (n - idx[1])
					score = np.max(arry)
					tup = rule(minIdx, -len(idx[0]), -score)
				tupList.append(tup)
			tmpSortedIdx = sorted(range(n), reverse=True, key=tupList.__getitem__)
			sortedIdx1 = index(sortedIdx1, tmpSortedIdx)
			useCube = useCube[tmpSortedIdx, :, :]
		elif nextDimension == 1:
			tupList = []
			for j in range(n):
				idx = np.where(useCube[:, j, :] == 1)
				if len(idx[0]) == 0:
					tup = rule(np.inf, np.inf, np.inf)
				else:
					minIdx = min(np.min(idx[0]), np.min(idx[1]))
					arry = (n - idx[0]) * (n - idx[1])
					score = np.max(arry)
					tup = rule(minIdx, -len(idx[0]), -score)
				tupList.append(tup)
			tmpSortedIdx = sorted(range(n), reverse=True, key=tupList.__getitem__)
			sortedIdx2 = index(sortedIdx2, tmpSortedIdx)
			useCube = useCube[:, tmpSortedIdx, :]
		else:
			tupList = []
			for k in range(n):
				idx = np.where(useCube[:, :, k] == 1)
				if len(idx[0]) == 0:
					tup = rule(np.inf, np.inf, np.inf)
				else:
					minIdx = min(np.min(idx[0]), np.min(idx[1]))
					arry = (n - idx[0]) * (n - idx[1])
					score = np.max(arry)
					tup = rule(minIdx, -len(idx[0]), -score)
				tupList.append(tup)
			tmpSortedIdx = sorted(range(n), reverse=True, key=tupList.__getitem__)
			sortedIdx3 = index(sortedIdx3, tmpSortedIdx)
			useCube = useCube[:, :, tmpSortedIdx]
		step = np.random.choice(2) + 1
		nextDimension = (nextDimension + step) % 3
	return (sortedIdx1, sortedIdx2, sortedIdx3)
n = int(input())
cube = np.zeros((n, n, n), dtype=int)
i = 0
j = 0
k = 0
for _ in range(n * n):
	row = [int(a) for a in input()]
	cube[i][j] = row
	j += 1
	if j == n:
		j = 0
		i += 1
(idx1, idx2, idx3) = solve(cube)
print(' '.join([str(a + 1) for a in idx3]))
print(' '.join([str(a + 1) for a in idx2]))
print(' '.join([str(a + 1) for a in idx1]))


n = int(input())
cube = [[[0 for i in range(n)] for j in range(n)] for k in range(n)]
(zeromax, yz, zz, zero_coord) = (0, -1, -1, [])
for z in range(n):
	for y in range(n):
		xs = list(map(int, input().strip()))
		zercount = 0
		czeros = []
		for x in range(n):
			if xs[x] == 0:
				zercount += 1
				czeros.append(x)
		if zercount > zeromax:
			(yz, zz) = (y, z)
			zero_coord = czeros
			zeromax = zercount
		cube[z][y] = xs
P = []
Q = [yz + 1]
R = [zz + 1]
done = [False] * n
for i in range(len(zero_coord)):
	P.append(zero_coord[i] + 1)
	done[zero_coord[i]] = True
for i in range(n):
	if done[i] == False:
		P.append(i + 1)
for i in range(1, n + 1):
	if i != yz + 1:
		Q.append(i)
	if i != zz + 1:
		R.append(i)
print(*P)
print(*Q)
print(*R)


zmap = {}
xmap = {}
ymap = {}
N = int(input())
Z = []
for z in range(N):
	XY = []
	for _ in range(N):
		a = input()
		La = []
		for i in a:
			La.append(int(i))
		XY.append(La)
	Z.append(XY)
R = [i for i in range(1, N + 1)]
d = {}
for j in range(1, N + 1):
	Layer = Z[j - 1]
	no_of_zero = 0
	no_of_healthy = 0
	limit = N
	vd = N ** 3
	rr = 0
	hd = 0
	remd = 0
	total_virus = 1
	for row in Layer:
		rr += 1
		for c in range(N):
			if row[c] == 1:
				limit = min(limit, c)
				vd = vd + pow(rr ** 2 + c ** 2, 0.5)
				total_virus += 1
			if row[c] == 0:
				hd = hd + pow(rr ** 2 + c ** 2, 0.5)
				if c < limit:
					no_of_zero += 1
					no_of_healthy += 1
					remd = remd + pow(rr ** 2 + c ** 2, 0.5)
				else:
					no_of_zero += 1
	zmap[j] = (-no_of_healthy, -vd / total_virus, -no_of_zero / total_virus)
R = sorted(R, key=lambda x: zmap[x])
NewZ = []
for x in R:
	NewZ.append(Z[x - 1])
Y = []
i = 0
for g in range(N):
	L = []
	for c in range(N):
		L.append(NewZ[c][i])
	Y.append(L)
	i = i + 1
Q = [i for i in range(1, N + 1)]
for j in range(1, N + 1):
	Layer = Y[j - 1]
	no_of_zero = 0
	no_of_healthy = 0
	limit = N
	vd = N ** 3
	rr = 0
	hd = 0
	tv = 1
	remd = 0
	for row in Layer:
		rr = rr + 1
		for c in range(N):
			if row[c] == 1:
				limit = min(limit, c)
				vd = vd + pow(rr ** 2 + c ** 2, 0.5)
				tv += 1
			if row[c] == 0:
				hd = hd + pow(rr ** 2 + c ** 2, 0.5)
				if c < limit:
					no_of_zero += 1
					no_of_healthy += 1
					remd = remd + pow(rr ** 2 + c ** 2, 0.5)
				else:
					no_of_zero += 1
	ymap[j] = (-no_of_healthy, -vd / tv, -no_of_zero / total_virus)
Q = sorted(Q, key=lambda x: ymap[x])
NewY = []
for x in R:
	NewZ.append(Y[x - 1])
X = []
for lay in range(N):
	Layer = []
	for row in range(N):
		J = []
		for hihi in range(N):
			J.append(Y[hihi][row][lay])
		Layer.append(J)
	X.append(Layer)
P = [i for i in range(1, N + 1)]
for j in range(1, N + 1):
	Layer = X[j - 1]
	no_of_zero = 0
	no_of_healthy = 0
	limit = N
	vd = N ** 3
	rr = 0
	hd = 0
	tv = 1
	remd = 0
	for row in Layer:
		rr += 1
		for c in range(N):
			if row[c] == 1:
				limit = min(limit, c)
				vd = vd + pow(rr ** 2 + c ** 2, 0.5)
				tv += 1
			if row[c] == 0:
				hd = hd + pow(rr ** 2 + c ** 2, 0.5)
				if c < limit:
					no_of_zero += 1
					no_of_healthy += 1
					remd += pow(rr ** 2 + c ** 2, 0.5)
				else:
					no_of_zero += 1
	xmap[j] = (-no_of_healthy, -vd / tv, -no_of_zero / tv)
P = sorted(P, key=lambda x: xmap[x])
for _ in range(N - 1):
	print(P[_], end=' ')
print(P[N - 1])
for _ in range(N - 1):
	print(Q[_], end=' ')
print(Q[N - 1])
for _ in range(N - 1):
	print(R[_], end=' ')
print(R[N - 1])


n = int(input())
l = []
p = [0] * n
q = [n * n] * n
r = [n * n] * n
for i in range(n ** 2):
	if i % n == 0:
		l.append([])
	l[-1].append(list(map(int, list(input()))))
	for i in range(n):
		p[i] += l[-1][-1][i]
p = sorted(range(0, n), key=lambda x: p[x])
for i in range(n):
	for j in range(n):
		for k in range(n):
			if l[j][i][p[k]] == 1:
				break
			q[i] -= 1
q = sorted(range(0, n), key=lambda x: q[x])
for i in range(n):
	j = 0
	b = n
	while j < n:
		k = 0
		while k < b:
			if l[i][q[j]][p[k]] == 1:
				b = k
				break
			r[i] -= 1
			k += 1
		if b == 0:
			break
		j += 1
r = sorted(range(0, n), key=lambda x: r[x])
healthy = 0
h = [n] * n
for i in range(n):
	for j in range(n):
		if j != 0 and h[j] > h[j - 1]:
			h[j] = h[j - 1]
		for k in range(h[j]):
			if l[r[i]][q[j]][p[k]] == 1:
				h[j] = k
				break
			healthy += 1
d = {}
d[healthy] = [p, q, r]
count = 0
while True:
	if count == 100:
		break
	p1 = [n * n] * n
	q1 = [n * n] * n
	r1 = [n * n] * n
	for i in range(n):
		j = 0
		b = n
		while j < n:
			k = 0
			while k < b:
				if l[r[k]][q[j]][i] == 1:
					b = k
					break
				p1[i] -= 1
				k += 1
			if b == 0:
				break
			j += 1
	p = sorted(range(0, n), key=lambda x: p1[x])
	for i in range(n):
		j = 0
		b = n
		while j < n:
			k = 0
			while k < b:
				if l[r[k]][i][p[j]] == 1:
					b = k
					break
				q1[i] -= 1
				k += 1
			if b == 0:
				break
			j += 1
	q = sorted(range(0, n), key=lambda x: q1[x])
	for i in range(n):
		j = 0
		b = n
		while j < n:
			k = 0
			while k < b:
				if l[i][q[j]][p[k]] == 1:
					b = k
					break
				r1[i] -= 1
				k += 1
			if b == 0:
				break
			j += 1
	r = sorted(range(0, n), key=lambda x: r1[x])
	healthy = 0
	h = [n] * n
	for i in range(n):
		for j in range(n):
			if j != 0 and h[j] > h[j - 1]:
				h[j] = h[j - 1]
			for k in range(h[j]):
				if l[r[i]][q[j]][p[k]] == 1:
					h[j] = k
					break
				healthy += 1
	d[healthy] = [p, q, r]
	count += 1
m = max(d.keys())
(p, q, r) = d[m]
for i in range(n):
	print(p[i] + 1, end=' ')
print()
for i in range(n):
	print(q[i] + 1, end=' ')
print()
for i in range(n):
	print(r[i] + 1, end=' ')
print()


import random
n = int(input())
a = [[[int(i) for i in input()] for j in range(n)] for k in range(n)]
p = [i + 1 for i in range(n)]
q = [i + 1 for i in range(n)]
r = [i + 1 for i in range(n)]
i1 = 0
p1 = 1
q1 = 1
r1 = 1
maxx = 0
i1 = 0
rl = []
for i in range(n):
	mm = 0
	for j in range(n):
		for k in range(n):
			if a[i][j][k] == 0:
				mm += 1
	rl.append([mm, i + 1])
	if mm > maxx:
		i1 = i
		maxx = mm
rl.sort()
rl = rl[::-1]
if a[0][0][0] == 1 or a[0][0][0] == 0:
	flag = 0
	for j in range(n):
		for k in range(n):
			if a[i1][j][k] == 0 and flag != 1:
				p1 = k + 1
				q1 = j + 1
				r1 = i1 + 1
				flag = 1
	a[r1 - 1][q1 - 1][p1 - 1] = a[0][0][0]
	a[0][0][0] = 0
(r[r1 - 1], r[0]) = (r[0], r[r1 - 1])
(q[q1 - 1], q[0]) = (q[0], q[q1 - 1])
(p[p1 - 1], p[0]) = (p[0], p[p1 - 1])
ny = [q[0]]
nz = [r[0]]
nx = [p[0]]
pos1 = 0
pos2 = 0
for i in range(n):
	if a[r1 - 1][q1 - 1][i] == 0 and i != p1 - 1:
		nx.append(i + 1)
pos1 = len(nx)
for i in range(n, 0, -1):
	if i not in nx:
		nx.append(i)
sl = []
for i in range(n):
	sl.append(i)
sl.remove(q1 - 1)
for _ in range(n - 1):
	maxx = 0
	pos = -1
	for i in range(n):
		ct = 0
		flag = 0
		if a[r1 - 1][i][p1 - 1] != 0 or i == q1 - 1:
			continue
		for j in range(pos1):
			if a[r1 - 1][i][nx[j] - 1] == 0 and a[r1 - 1][ny[_] - 1][nx[j] - 1] == 0:
				ct += 1
			else:
				break
		if i in sl and ct > maxx:
			maxx = ct
			pos = i
	if pos not in sl:
		break
	ny.append(pos + 1)
	sl.remove(pos)
for i in range(n, 0, -1):
	if i not in ny:
		ny.append(i)
st = []
for i in range(n):
	if i != r1 - 1:
		st.append(i)
for _ in range(n - 1):
	maxx = 0
	pos = i
	for i in range(n):
		ct = 0
		flag = 0
		posn = pos1
		if a[i][q1 - 1][p1 - 1] != 0 or i == r1 - 1:
			continue
		for j in range(n):
			for k in range(posn):
				if a[i][ny[j] - 1][nx[k] - 1] == 0 and a[nz[_] - 1][ny[j] - 1][nx[k] - 1] == 0:
					ct += 1
				else:
					posn = k
					break
		if i in st and ct > maxx:
			maxx = ct
			pos = i
	if pos not in st:
		break
	nz.append(pos + 1)
	st.remove(pos)
for i in range(1, n + 1):
	if i not in nz:
		nz.append(i)
for i in nx:
	print(i, end=' ')
print()
for i in ny:
	print(i, end=' ')
print()
for i in nz:
	print(i, end=' ')
print()


n = int(input())
X = []
Y = []
Z = []
mas = []
ma = 0
zc = 0
zb = []
for i in range(n):
	l = []
	c = 0
	for j in range(n):
		s = input()
		c += s.count('0')
		l.append(s)
	mas.append(l)
	zb.append([i + 1, c])
	if c > ma:
		ma = c
		zc = i
yn = 0
ma = 0
zb.sort(key=lambda test: test[1], reverse=True)
for i in range(n):
	s = mas[zc][i]
	c = s.count('0')
	if c > ma:
		ma = c
		yn = i
Y.append(str(yn + 1))
for i in range(n):
	if mas[zc][yn][i] == '0':
		X.append(str(i + 1))
for i in range(n):
	if str(i + 1) not in X:
		X.append(str(i + 1))
for i in range(n):
	if i != yn:
		Y.append(str(i + 1))
for i in range(n):
	Z.append(str(zb[i][0]))
print(' '.join(X))
print(' '.join(Y))
print(' '.join(Z))


import random
N = int(input())
ans = [i for i in range(N, 0, -1)]
for i in range(3):
	for a in ans:
		print(a, end=' ')
	print()


n = int(input())
arr = []
weight = [[[0 for i in range(n)] for i in range(n)] for i in range(n)]
temp2 = [n - i for i in range(n)]
temp3 = [[0 for i in range(n)] for i in range(n)]
for i in range(n):
	temp3[n - 1][i] = temp2[i]
for i in range(n - 2, -1, -1):
	for j in range(n):
		temp3[i][j] = temp3[n - 1][j] * (n - i)
for i in range(n):
	for j in range(n):
		weight[n - 1][i][j] = temp3[i][j]
for i in range(n - 2, -1, -1):
	for j in range(n):
		for k in range(n):
			weight[i][j][k] = weight[n - 1][j][k] * (n - i)
for i in range(n):
	temp = []
	for j in range(n):
		temp.append([int(i) for i in input()])
	arr.append(temp)
third = []
for i in range(n):
	temp = 0
	for j in range(n):
		for k in range(n):
			temp += arr[i][j][k] * weight[i][j][k]
	third.append([i + 1, temp])
second = []
for i in range(n):
	temp = 0
	for j in range(n):
		for k in range(n):
			temp += arr[j][i][k] * weight[j][i][k]
	second.append([i + 1, temp])
first = []
for i in range(n):
	temp = 0
	for j in range(n):
		for k in range(n):
			temp += arr[j][k][i] * weight[j][k][i]
	first.append([i + 1, temp])
first.sort(key=lambda x: x[1])
second.sort(key=lambda x: x[1])
third.sort(key=lambda x: x[1])
ans1 = str(first[0][0])
for i in range(1, n):
	ans1 += ' ' + str(first[i][0])
ans2 = str(second[0][0])
for i in range(1, n):
	ans2 += ' ' + str(second[i][0])
ans3 = str(third[0][0])
for i in range(1, n):
	ans3 += ' ' + str(third[i][0])
print(ans1)
print(ans2)
print(ans3)


n = int(input())
for _ in range(3):
	for i in range(n, 0, -1):
		print(i, end=' ')
	print()


import sys
import numpy as np
N = int(input())
M = np.zeros((N, N, N))
for layer in range(N):
	for row in range(N):
		M[layer][row] = list(map(int, sys.stdin.readline().rstrip()))
P = np.asarray(list(range(N)))
Q = np.asarray(list(range(N)))
R = np.asarray(list(range(N)))
z_sum = np.sum(M == 0, axis=0)
y_sum = np.sum(M == 0, axis=1)
x_sum = np.sum(M == 0, axis=2)
(max_zeros, max_zeros_index) = (0, (0, 0, 0))
for z in range(N):
	for y in range(N):
		for x in range(N):
			if M[z][y][x] == 0:
				zeros = z_sum[y][x] + y_sum[z][x] + x_sum[z][y] - 2
				if zeros > max_zeros:
					max_zeros = zeros
					max_zeros_index = (z, y, x)
(z, y, x) = max_zeros_index
(P[0], P[x]) = (P[x], P[0])
(Q[0], Q[y]) = (Q[y], Q[0])
(R[0], R[z]) = (R[z], R[0])
oldM = M
M2 = M[R, :, :][:, Q, :][:, :, P]
l = 1
for i in range(2, N):
	if M2[0][0][i] == 0:
		(P[l], P[i]) = (P[i], P[l])
		l += 1
l = 1
for i in range(2, N):
	if M2[0][i][0] == 0:
		(Q[l], Q[i]) = (Q[i], Q[l])
		l += 1
l = 1
for i in range(2, N):
	if M2[i][0][0] == 0:
		(R[l], R[i]) = (R[i], R[l])
		l += 1
M = M[R, :, :][:, Q, :][:, :, P]
if M[0][0][0] == 1:
	M = oldM
	P = np.asarray(list(range(0, N)))
	Q = np.asarray(list(range(0, N)))
	R = np.asarray(list(range(0, N)))
	ind = np.where(M == 0)
	(P[0], Q[0], R[0], P[ind[2][0]], Q[ind[1][0]], R[ind[0][0]]) = (ind[2][0], ind[1][0], ind[0][0], 0, 0, 0)
P = P + 1
Q = Q + 1
R = R + 1
print(' '.join([str(s) for s in P]))
print(' '.join([str(s) for s in Q]))
print(' '.join([str(s) for s in R]))


n = int(input())
X = []
Y = []
Z = []
mas = []
ma = 0
zn = []
xn = [0] * n
yn = [0] * n
for i in range(n):
	l = []
	c = 0
	for j in range(n):
		s = input()
		for k in range(n):
			if s[k] == '0':
				xn[k] += 1
		co = s.count('0')
		yn[j] += co
		c += co
		l.append(s)
	mas.append(l)
	zn.append([i + 1, c])
for i in range(n):
	xn[i] = [i + 1, xn[i]]
	yn[i] = [i + 1, yn[i]]
yn.sort(key=lambda test: test[1], reverse=True)
xn.sort(key=lambda test: test[1], reverse=True)
zn.sort(key=lambda test: test[1], reverse=True)
for i in range(n):
	Z.append(str(zn[i][0]))
	X.append(str(xn[i][0]))
	Y.append(str(yn[i][0]))
print(' '.join(X))
print(' '.join(Y))
print(' '.join(Z))


n = int(input())
X = []
Y = []
Z = []
mas = []
ma = 0
zn = []
xn = [0] * n
yn = [0] * n
for i in range(n):
	l = []
	c = 0
	for j in range(n):
		s = input()
		for k in range(n):
			if s[k] == '0':
				xn[k] += 1
		co = s.count('0')
		yn[j] += co
		c += co
		l.append(s)
	mas.append(l)
	zn.append([i + 1, c])
for i in range(n):
	xn[i] = [i + 1, xn[i]]
	yn[i] = [i + 1, yn[i]]
yn.sort(key=lambda test: test[1], reverse=True)
xn.sort(key=lambda test: test[1], reverse=True)
zn.sort(key=lambda test: test[1], reverse=True)
x1 = []
x2 = []
y1 = []
y2 = []
z1 = []
z2 = []
for i in range(n):
	if i % 2 == 0:
		y1.append(yn[i][0])
		z1.append(zn[i][0])
		x1.append(xn[i][0])
	else:
		z2.append(zn[i][0])
		x2.append(xn[i][0])
		y2.append(yn[i][0])
for i in range(len(z1)):
	Z.append(str(z1[i]))
	X.append(str(x1[i]))
	Y.append(str(y1[i]))
for i in range(len(z2)):
	Z.append(str(z2[len(z2) - 1 - i]))
	X.append(str(x2[len(x2) - 1 - i]))
	Y.append(str(y2[len(y2) - 1 - i]))
print(' '.join(X))
print(' '.join(Y))
print(' '.join(Z))


n = int(input())
layersZ = [None for _ in range(n)]
layersY = [None for _ in range(n)]
layersX = [None for _ in range(n)]
countz = {}
county = {}
countx = {}
for z in range(n):
	layer = [[] for _ in range(n)]
	virus = 0
	infected = n ** 2
	least = n
	for y in range(n):
		row = list(map(int, list(input())))
		for x in range(n):
			if row[x]:
				virus += 1
				least = min(least, x)
			elif x < least:
				infected -= 1
		layer[y] = row
	layersZ[z] = (z, layer)
	countz[z] = (infected, virus)
layersZ.sort(key=lambda layer: countz[layer[0]])
for y in range(n):
	layer = [None for _ in range(n)]
	virus = 0
	infected = n ** 2
	least = n
	for x in range(n):
		row = []
		for z in range(n):
			row.append(layersZ[z][1][y][x])
			if layersZ[z][1][y][x]:
				virus += 1
				least = min(least, z)
			elif z < least:
				infected -= 1
		layer[x] = row
	layersY[y] = (y, layer)
	county[y] = (infected, virus)
layersY.sort(key=lambda layer: county[layer[0]])
for x in range(n):
	layer = [None for _ in range(n)]
	virus = 0
	infected = n ** 2
	least = n
	for z in range(n):
		row = []
		for y in range(n):
			row.append(layersY[y][1][x][z])
			if layersY[y][1][x][z]:
				virus += 1
				least = min(least, y)
			elif y < least:
				infected -= 1
		layer[z] = row
	layersX[x] = (x, layer)
	countx[x] = (infected, virus)
layersX.sort(key=lambda layer: countx[layer[0]])
P = []
Q = []
R = []
for layer in layersX:
	P.append(str(layer[0] + 1))
for layer in layersY:
	Q.append(str(layer[0] + 1))
for layer in layersZ:
	R.append(str(layer[0] + 1))
print(' '.join(P))
print(' '.join(Q))
print(' '.join(R))


n = int(input())
layersZ = [None for _ in range(n)]
layersY = [None for _ in range(n)]
layersX = [None for _ in range(n)]
countz = {}
county = {}
countx = {}
for z in range(n):
	layer = [[] for _ in range(n)]
	counts = []
	for y in range(n):
		row = list(input())
		counts.append(row.count('1'))
		layer[y] = list(map(int, row))
	layersZ[z] = (z, layer)
	counts.sort()
	counts.insert(0, sum(counts))
	countz[z] = counts
layersZ.sort(key=lambda layer: countz[layer[0]])
for y in range(n):
	layer = [None for _ in range(n)]
	counts = []
	for x in range(n):
		row = []
		count = 0
		for z in range(n):
			count += layersZ[z][1][y][x]
			row.append(layersZ[z][1][y][x])
		layer[x] = row
		counts.append(count)
	layersY[y] = (y, layer)
	counts.sort()
	counts.insert(0, sum(counts))
	county[y] = counts
layersY.sort(key=lambda layer: county[layer[0]])
for x in range(n):
	layer = [None for _ in range(n)]
	counts = []
	for z in range(n):
		row = []
		count = 0
		for y in range(n):
			count += layersY[y][1][x][z]
			row.append(layersY[y][1][x][z])
		counts.append(count)
		layer[z] = row
	layersX[x] = (x, layer)
	counts.sort()
	counts.insert(0, sum(counts))
	countx[x] = counts
layersX.sort(key=lambda layer: countx[layer[0]])
P = []
Q = []
R = []
for layer in layersX:
	P.append(str(layer[0] + 1))
for layer in layersY:
	Q.append(str(layer[0] + 1))
for layer in layersZ:
	R.append(str(layer[0] + 1))
print(' '.join(P))
print(' '.join(Q))
print(' '.join(R))


import random
random.seed(143)

def shuff(p, q, r):
	random.shuffle(p)
	random.shuffle(q)
	random.shuffle(r)

def output(s):
	print(s[0], end='')
	for i in range(1, len(s)):
		print(' {}'.format(s[i]), end='')
	print('')
n = int(input())
l = []
count0 = 0
for i in range(n):
	l.append([])
	for j in range(n):
		t = input()
		l[i].append(t)
		count0 += t.count('0')
p = list(range(1, n + 1))
q = list(range(1, n + 1))
r = list(range(1, n + 1))
shuff(p, q, r)
while l[r[0] - 1][q[0] - 1][p[0] - 1] == '1' or (count0 > 1 and l[r[0] - 1][q[0] - 1][p[1] - 1] == '1'):
	shuff(p, q, r)
output(p)
output(q)
output(r)


import random
random.seed(107)

def shuff(p, q, r):
	random.shuffle(p)
	random.shuffle(q)
	random.shuffle(r)

def output(s):
	print(s[0], end='')
	for i in range(1, len(s)):
		print(' {}'.format(s[i]), end='')
	print('')
n = int(input())
l = []
for i in range(n):
	l.append([])
	for j in range(n):
		l[i].append(input())
p = list(range(1, n + 1))
q = list(range(1, n + 1))
r = list(range(1, n + 1))
shuff(p, q, r)
while l[r[0] - 1][q[0] - 1][p[0] - 1] == '1':
	shuff(p, q, r)
output(p)
output(q)
output(r)


n = int(input())
cube = []
p = list(range(1, n + 1))
q = list(range(1, n + 1))
r = list(range(1, n + 1))
for i in range(n):
	temp = []
	for j in range(n):
		l = list(input())
		temp.append(l)
	cube.append(temp)
flag = False
for i in range(n):
	for j in range(n):
		for k in range(n):
			if cube[i][j][k] == '0':
				p[k] = 1
				p[0] = k + 1
				q[j] = 1
				q[0] = j + 1
				r[i] = 1
				r[0] = i + 1
				flag = True
				break
		if flag:
			break
	if flag:
		break
print(*p, sep=' ')
print(*q, sep=' ')
print(*r, sep=' ')


zmap = {}
xmap = {}
ymap = {}
N = int(input())
Z = []
for z in range(N):
	XY = []
	for _ in range(N):
		a = input()
		La = []
		for i in a:
			La.append(int(i))
		XY.append(La)
	Z.append(XY)
R = [i for i in range(1, N + 1)]
d = {}
for j in range(1, N + 1):
	Layer = Z[j - 1]
	no_of_zero = 0
	no_of_healthy = 0
	limit = N
	for row in Layer:
		for c in range(N):
			if row[c] == 1:
				limit = min(limit, c)
			if row[c] == 0:
				if c < limit:
					no_of_zero += 1
					no_of_healthy += 1
				else:
					no_of_zero += 1
	zmap[j] = (-no_of_healthy, -no_of_zero)
R = sorted(R, key=lambda x: zmap[x])
NewZ = []
for x in R:
	NewZ.append(Z[x - 1])
Y = []
i = 0
for g in range(N):
	L = []
	for c in range(N):
		L.append(NewZ[c][i])
	Y.append(L)
	i = i + 1
Q = [i for i in range(1, N + 1)]
for j in range(1, N + 1):
	Layer = Y[j - 1]
	no_of_zero = 0
	no_of_healthy = 0
	limit = N
	for row in Layer:
		for c in range(N):
			if row[c] == 1:
				limit = min(limit, c)
			if row[c] == 0:
				if c < limit:
					no_of_zero += 1
					no_of_healthy += 1
				else:
					no_of_zero += 1
	ymap[j] = (-no_of_healthy, -no_of_zero)
Q = sorted(Q, key=lambda x: ymap[x])
NewY = []
for x in R:
	NewZ.append(Y[x - 1])
X = []
for lay in range(N):
	Layer = []
	for row in range(N):
		J = []
		for hihi in range(N):
			J.append(Y[hihi][row][lay])
		Layer.append(J)
	X.append(Layer)
P = [i for i in range(1, N + 1)]
for j in range(1, N + 1):
	Layer = X[j - 1]
	no_of_zero = 0
	no_of_healthy = 0
	limit = N
	for row in Layer:
		for c in range(N):
			if row[c] == 1:
				limit = min(limit, c)
			if row[c] == 0:
				if c < limit:
					no_of_zero += 1
					no_of_healthy += 1
				else:
					no_of_zero += 1
	xmap[j] = (-no_of_healthy, -no_of_zero)
P = sorted(P, key=lambda x: xmap[x])
for _ in range(N - 1):
	print(P[_], end=' ')
print(P[N - 1])
for _ in range(N - 1):
	print(Q[_], end=' ')
print(Q[N - 1])
for _ in range(N - 1):
	print(R[_], end=' ')
print(R[N - 1])


def swap(l, a, b):
	memo = l[a]
	l[a] = l[b]
	l[b] = memo
	return l
(X, Y, Z, cell, h, uh) = ({}, {}, {}, [], [], [])
N = int(input())
for i in range(N):
	X[i + 1] = Y[i + 1] = Z[i + 1] = 0
for z in range(N):
	cell.append([])
	for x in range(N):
		cell[z].append([])
		layer = input()
		for y in range(N):
			cell[z][x].append(int(layer[y]))
			if layer[y] == '1':
				uh.append([x + 1, y + 1, z + 1])
				continue
			X[x + 1] += 1
			Y[y + 1] += 1
			Z[z + 1] += 1
			h.append([x + 1, y + 1, z + 1])
h.sort(key=lambda y: y[1])
h.sort(key=lambda z: z[2])
h.sort(key=lambda x: x[0])
result = [[], [], []]
(l1, l2, l3) = (sorted(X.items(), key=lambda dx: (dx[1], dx[0])), sorted(Y.items(), key=lambda dy: (dy[1], dy[0])), sorted(Z.items(), key=lambda dz: (dz[1], dz[0])))
for item in l1:
	result[0].append(item[0])
for item in l2:
	result[1].append(item[0])
for item in l3:
	result[2].append(item[0])
for item in range(N):
	if item + 1 not in result[0]:
		result[0].append(item + 1)
	if item + 1 not in result[1]:
		result[1].append(item + 1)
	if item + 1 not in result[2]:
		result[2].append(item + 1)
if cell[result[0][0]][result[1][0]][result[2][0]] == 1:
	for item in h:
		(t1, t2, t3) = (result[0].index(item[0]), result[1].index(item[1]), result[2].index(item[2]))
		result[0] = swap(result[0], 0, t1)
		result[1] = swap(result[1], 0, t2)
		result[2] = swap(result[2], 0, t3)
for lis in result:
	print(*lis)


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


N = int(input())
ls = []
for i in range(N ** 2):
	a = input()
	ls.append(a)
x = [[0, i] for i in range(N)]
for i in range(N ** 2):
	for j in range(N):
		x[j][0] += int(ls[i][j]) * 2 ** (2 * N - 2 - (i % N + i // N))
y = [[0, i] for i in range(N)]
for i in range(N ** 2):
	for j in range(N):
		y[i % N][0] += int(ls[i][j]) * 2 ** (2 * N - 2 - (i // N + j))
z = [[0, i] for i in range(N)]
for i in range(N ** 2):
	for j in range(N):
		z[i // N][0] += int(ls[i][j]) * 2 ** (2 * N - 2 - (i % N + j))
x.sort()
y.sort()
z.sort()
if ls[N * z[0][1] + y[0][1]][x[0][1]] == '0':
	for i in range(N):
		print(x[i][1] + 1, end=' ')
	print()
	for i in range(N):
		print(y[i][1] + 1, end=' ')
	print()
	for i in range(N):
		print(z[i][1] + 1, end=' ')
	print()
else:
	x = [[0, i] for i in range(N)]
	for i in range(N ** 2):
		for j in range(N):
			if i % N == 0 and i // N == 0:
				x[j][0] += int(ls[i][j]) * 10 ** 9
			else:
				x[j][0] += int(ls[i][j])
	y = [[0, i] for i in range(N)]
	for i in range(N ** 2):
		for j in range(N):
			if i // N == 0 and j == 0:
				y[i % N][0] += int(ls[i][j]) * 10 ** 9
			else:
				y[i % N][0] += int(ls[i][j])
	z = [[0, i] for i in range(N)]
	for i in range(N ** 2):
		for j in range(N):
			if i % N == 0 and j == 0:
				z[i // N][0] += int(ls[i][j]) * 10 ** 9
			else:
				z[i // N][0] += int(ls[i][j])
	x.sort()
	y.sort()
	z.sort()
	for i in range(N):
		print(x[i][1] + 1, end=' ')
	print()
	for i in range(N):
		print(y[i][1] + 1, end=' ')
	print()
	for i in range(N):
		print(z[i][1] + 1, end=' ')
	print()


n = int(input())
X = []
Y = []
Z = []
mas = []
ma = 0
zn = []
for i in range(n):
	l = []
	c = 0
	for j in range(n):
		s = input()
		c += s.count('0')
		l.append(s)
	mas.append(l)
	zn.append([i + 1, c])
yn = 0
ma = 0
zn.sort(key=lambda test: test[1], reverse=True)
z1 = []
z2 = []
for i in range(n):
	if i % 2 == 0:
		z1.append(zn[i][0])
	else:
		z2.append(zn[i][0])
for i in range(len(z1)):
	Z.append(str(z1[i]))
for i in range(len(z2)):
	Z.append(str(z2[len(z2) - 1 - i]))
poi = z1[0] - 1
for i in range(n):
	s = mas[poi][i]
	c = s.count('0')
	if c > ma:
		ma = c
		yn = i
Y.append(str(yn + 1))
for i in range(n):
	if mas[poi][yn][i] == '0':
		X.append(str(i + 1))
for i in range(n):
	if str(i + 1) not in X:
		X.append(str(i + 1))
for i in range(n):
	if i != yn:
		Y.append(str(i + 1))
print(' '.join(X))
print(' '.join(Y))
print(' '.join(Z))


import numpy as np
import random
N = int(input())
states = []
for z in range(N):
	states_z = []
	for y in range(N):
		read_states_yz = input()
		states_z.append([int(elem) for elem in read_states_yz])
	states.append(states_z)
infect_x = []
infect_y = []
infect_z = []
states = np.array(states)
states = np.swapaxes(states, 0, 2)
infection = np.where(states == 1)
infect_x = infection[0]
infect_y = infection[1]
infect_z = infection[2]
effect_x = np.zeros(N)
pos = 0
for pos in range(len(infect_x)):
	effect_x[infect_x[pos]] += 1
permute_x = np.argsort(effect_x)
new_x = np.zeros(N)
idx = 0
for item in permute_x:
	new_x[item] = idx
	idx += 1
effect_y = np.zeros(N)
pos = 0
for pos in range(len(infect_y)):
	effect_y[infect_y[pos]] += 1
permute_y = np.argsort(effect_y)
new_y = np.zeros(N)
idx = 0
for item in permute_y:
	new_y[item] = idx
	idx += 1
effect_z = np.zeros(N)
pos = 0
for pos in range(len(infect_z)):
	effect_z[infect_z[pos]] += 1
permute_z = np.argsort(effect_z)
new_z = np.zeros(N)
idx = 0
for item in permute_z:
	new_z[item] = idx
	idx += 1
str1 = ''
for item in permute_x:
	str1 += str(item + 1)
	str1 += ' '
print(str1)
str1 = ''
for item in permute_y:
	str1 += str(item + 1)
	str1 += ' '
print(str1)
str1 = ''
for item in permute_z:
	str1 += str(item + 1)
	str1 += ' '
print(str1)


n = int(input())
cube = []
X = [0] * n
Y = [0] * n
Z = [0] * n
uninf = []
for z in range(1, n + 1):
	layer = []
	for y in range(1, n + 1):
		layer.append(list(input()))
		for x in range(1, n + 1):
			if layer[y - 1][x - 1] == '0':
				uninf.append([x, y, z])
			else:
				X[x - 1] += 1
				Y[y - 1] += 1
				Z[z - 1] += 1
	cube.append(layer)
uninf = sorted(uninf, key=lambda p: X[p[0] - 1] + Y[p[1] - 1] + Z[p[2] - 1])
x = []
y = []
z = []
for point in uninf:
	if point[0] not in x:
		x.append(point[0])
	if point[1] not in y:
		y.append(point[1])
	if point[2] not in z:
		z.append(point[2])
from random import shuffle
a = [i for i in range(1, n + 1)]
shuffle(a)
for i in a:
	if i not in x:
		x.append(i)
shuffle(a)
for i in a:
	if i not in x:
		y.append(i)
shuffle(a)
for i in a:
	if i not in x:
		z.append(i)
for i in x:
	print(i, end=' ')
print()
for i in y:
	print(i, end=' ')
print()
for i in z:
	print(i, end=' ')
print()


import numpy as np

def cmp_to_key(mycmp):

	class K(object):

		def __init__(self, obj, *args):
			self.obj = obj

		def __lt__(self, other):
			return mycmp(self.obj, other.obj) < 0

		def __gt__(self, other):
			return mycmp(self.obj, other.obj) > 0

		def __eq__(self, other):
			return mycmp(self.obj, other.obj) == 0

		def __le__(self, other):
			return mycmp(self.obj, other.obj) <= 0

		def __ge__(self, other):
			return mycmp(self.obj, other.obj) >= 0

		def __ne__(self, other):
			return mycmp(self.obj, other.obj) != 0
	return K

def infectlayer(layer):
	mins = []
	for i in range(N):
		for j in range(N):
			if layer[i, j]:
				if len(mins):
					if j < mins[-1][0]:
						mins.append((j, i))
				else:
					mins.append((j, i))
				break
	mins.append((0, N))
	if len(mins) < 2:
		return 0
	s = 0
	for i in range(len(mins) - 1):
		d = mins[i + 1][1] - mins[i][1]
		print
		s += d * (N - mins[i][0])
	return s

def cmplayer(layer1, layer2):
	if layer1[1] > layer2[1]:
		top = layer1
		bottom = layer2
	else:
		top = layer2
		bottom = layer1
	ti = infectlayer(top[0])
	bi = infectlayer(bottom[0])
	c1 = ti * (N - top[1]) + bi * (N - bottom[1])
	c2 = ti * (N - bottom[1]) + bi * (N - top[1])
	if c1 > c2:
		return -1
	elif c1 < c2:
		return 1
	return 0
N = int(input())
A = np.zeros((N, N, N))
for i in range(N):
	for j in range(N):
		A[i, j, :] = list(map(int, list(input())))
Xlayers = [(A[i, :, :], i) for i in range(N)]
Xsort = sorted(Xlayers, key=cmp_to_key(cmplayer))
A = np.array([x[0] for x in Xsort])
Ylayers = [(A[:, i, :], i) for i in range(N)]
Ysort = sorted(Ylayers, key=cmp_to_key(cmplayer))
A = np.array([x[0] for x in Ysort])
Zlayers = [(A[:, :, i], i) for i in range(N)]
Zsort = sorted(Zlayers, key=cmp_to_key(cmplayer))
A = np.array([x[0] for x in Zsort])
P = [1 + p[1] for p in Xsort]
Q = [1 + q[1] for q in Ysort]
R = [1 + r[1] for r in Zsort]
print(' '.join(map(str, R)))
print(' '.join(map(str, Q)))
print(' '.join(map(str, P)))


n = int(input())
cube = []
X = [0] * n
Y = [0] * n
Z = [0] * n
uninf = []
for z in range(1, n + 1):
	layer = []
	for y in range(1, n + 1):
		layer.append(list(input()))
		for x in range(1, n + 1):
			if layer[y - 1][x - 1] == '0':
				uninf.append([x, y, z])
			else:
				X[x - 1] += 1
				Y[y - 1] += 1
				Z[z - 1] += 1
	cube.append(layer)
from random import shuffle
minpoint = uninf[0]
for point in uninf:
	temp = X[point[0] - 1] + Y[point[1] - 1] + Z[point[2] - 1]
	if temp < X[minpoint[0] - 1] + Y[minpoint[1] - 1] + Z[minpoint[2] - 1]:
		minpoint = point
selected = minpoint
print(selected[0], end=' ')
a = [i for i in range(1, n + 1)]
shuffle(a)
for x in a:
	if x != selected[0]:
		print(x, end=' ')
print('\n' + str(selected[1]), end=' ')
shuffle(a)
for y in a:
	if y != selected[1]:
		print(y, end=' ')
print('\n' + str(selected[2]), end=' ')
shuffle(a)
for z in a:
	if z != selected[2]:
		print(z, end=' ')


n = int(input())
cube = []
uninf = []
for z in range(1, n + 1):
	layer = []
	for y in range(1, n + 1):
		layer.append(list(input()))
		for x in range(1, n + 1):
			if layer[y - 1][x - 1] == '0':
				uninf.append([x, y, z])
	cube.append(layer)
from random import random
from random import shuffle
selected = uninf[int(random() * len(uninf))]
print(selected[0], end=' ')
a = [i for i in range(1, n + 1)]
shuffle(a)
for x in a:
	if x != selected[0]:
		print(x, end=' ')
print('\n' + str(selected[1]), end=' ')
shuffle(a)
for y in a:
	if y != selected[1]:
		print(y, end=' ')
print('\n' + str(selected[2]), end=' ')
shuffle(a)
for z in a:
	if z != selected[2]:
		print(z, end=' ')