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.

Difficulty: VERY_HARD

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


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)


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


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