Chef has $N$ decimal strings $S_{1}, S_{2}, \ldots, S_{N}$ with him (that is, each of these strings contains only characters '0' through '9'). The characters in all strings are indexed starting from $1$. Chef wants to form a single long string $W$ by *interleaving* all these strings.

A string $W$ is said to be formed by interleaving $S_{1}, S_{2}, \ldots, S_{N}$ if the characters of $W$ can be partitioned into $N$ subsequences $T_{1}, T_{2}, \ldots, T_{N}$ such that for each valid $i$, $T_{i}$ is identical to the string $S_{i}$. Formally, for each valid $i$, the subsequence $T_{i}$ must have length $|S_{i}|$; let's denote $T_{i} = (T_{i, 1}, T_{i, 2}, \ldots, T_{i, |S_{i}|})$, where $1 ≤ T_{i, j} ≤ N$ and $T_{i, j} < T_{i, j+1}$ for each valid $j$. Each integer between $1$ and $|W| = |S_{1}| + |S_{2}| + \ldots + |S_{N}|$ inclusive must occur in exactly one of these subsequences, and for each valid $i$ and $j$, the $T_{i, j}$-th character of $W$ must be identical to the $j$-th character of $S_{i}$. For example, if $S_{1}$ is "123", $S_{2}$ is "456" and $S_{3}$ is "789", then the strings "124758963" and "123456789" are formed by interleaving these strings, but "123456798" is not.

The *cost* of the interleaved string $W$ is defined as $\sum_{i=2}^{|W|} |W_{i} - W_{i-1}|^2$, where $W_{i}$ denotes the integer represented by the $i$-th character of $W$. For example, if $W$ is "124", then its cost is $|2 - 1|^2 + |4 - 2|^2 = 1 + 4 = 5$.

Chef wants you to find an interleaved string $W$. The cost of this string should be as low as possible.

------  Input ------
The first line of the input contains a single integer $N$.
$N$ lines follow. For each $i$ ($1 ≤ i ≤ N$), the $i$-th of these lines contains a single string $S_{i}$.

------  Output ------
Print a single line containing $|W| = |S_{1}| + |S_{2}| + \ldots + |S_{N}|$ space-separated integers. For each valid $i$, the $i$-th of these integers (let's denote it by $x$) should denote that the $i$-th character of your interleaved string comes from the string $S_{x}$.
Your output will be considered valid if for each $i$ ($1 ≤ i ≤ N$), your output contains the integer $i$ exactly $|S_{i}|$ times.

------  Constraints ------
$N = 10,000$
$|S_{i}| = 100$ for each valid $i$
$S_{1}, S_{2}, \ldots, S_{N}$ contain only decimal digits, i.e. characters '0' through '9'

------  Scoring ------
The score of each test case (and therefore each test file) is the cost of the string $W$ described by your output, i.e. $\sum_{i=2}^{|W|} |W_{i} - W_{i-1}|^2$. The score of a submission is the sum of scores of all test files. Your goal is to minimise the score of your submission.

If your output is invalid, the verdict of your submission will be Wrong Answer.

There are twenty test files - ten of each type described below. During the contest, the displayed score will account for exactly four test files, i.e. your score reflects your submission's performance on 20% (4/20) of the test files, two for each of the types described below. 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 sixteen test files.

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

3
123
456
789

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

1 1 2 3 2 3 3 2 1

------  Explanation ------
The output corresponds to the string "124758963". The score for this test file would be the cost of this string, which is $46$.

Test Generation Process
There are two types of test files.

Type 1: Each character of each string is chosen uniformly randomly from the set {'0', '1', ..., '9'}.

Type 2: Each character of each string is chosen randomly from the set {'0', '1', ..., '9'}. The probability of '0' being chosen is $0.4$, the probability of '1' being chosen is also $0.4$ and the probability of each of the remaining 8 characters being chosen is $0.025$.

Difficulty: VERY_HARD

Starter code:

Solutions:
import numpy as np
try:
	N = int(input())
	k = 100
	a = np.zeros([N, k])
	a = [[int(x) for x in input()] for i in range(N)]
	for ctr in range(k):
		b = [[i, a[i][ctr]] for i in range(N)]
		for x in range(10):
			t = x if ctr % 2 == 0 else 9 - x
			for m in range(len(b)):
				if b[m][1] == t:
					print(b[m][0] + 1, end=' ')
					b[m][0] = -1
			filter(lambda y: y[0] > -1, b)
except:
	pass


import numpy as np
try:
	import numpy as np
	N = int(input())
	k = 100
	a = np.zeros([N, k])
	a = [[int(x) for x in input()] for i in range(N)]
	for ctr in range(k):
		b = [[i, a[i][ctr]] for i in range(N)]
		b.sort(key=lambda x: x[1], reverse=ctr % 2)
		for t in range(N):
			print(b[t][0] + 1, end=' ')
except:
	pass


data = []
n = int(input())
for _ in range(n):
	s = input()
	data.append(s)
for i in range(n):
	for j in range(len(data[i])):
		print(i + 1, end=' ')


l = 1
for _ in range(int(input())):
	s = input()
	for i in range(len(s)):
		print(str(l) + ' ', end=' ')
	l += 1


n = int(input())
S = []
l = []
ml = 0
ans = ''
for i in range(n):
	S.append([])
	a = input()
	ml = max(ml, len(a))
	l.append(len(a))
	for k in a:
		S[i].append(int(k))
for i in range(ml):
	W = [[], [], [], [], [], [], [], [], [], []]
	s = ''
	for j in range(n):
		if l[j] > i:
			W[S[j][i]].append(j)
	if i % 2:
		for j in range(10):
			for k in W[-j - 1]:
				s = s + str(k + 1) + ' '
	else:
		for j in range(10):
			for k in W[j]:
				s = s + str(k + 1) + ' '
	ans += s
print(ans)


try:
	n = int(input())
	n += 1
	for i in range(n):
		if i == 0:
			n -= 2
		else:
			n -= 1
		x = input()
		for i in x:
			print(n + 1, end=' ')
		if i == 0:
			n += 1
	print()
except:
	pass


n = int(input())
s = []
for i in range(n):
	s = input()
	for j in range(len(s)):
		print(i + 1, end=' ')
print()


try:
	n = int(input())
	for i in range(n):
		n -= 1
		x = input()
		for i in x:
			print(n + 1, end=' ')
	print()
except:
	pass


n = int(input())
s = ''
for i in range(n):
	inn = str(input())
	for j in range(len(inn)):
		d = str(i + 1)
		s += d
		s += ' '
print(s)


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


arr = [[] for i in range(100)]
for nitish in range(int(input())):
	s = input()
	for i in range(len(s)):
		arr[i].append([int(s[i]), nitish + 1])
ans = []
for i in range(100):
	arr[i].sort()
	if i % 2 == 1:
		for j in arr[i]:
			ans.append(j[1])
	else:
		for j in range(len(arr[i]) - 1, -1, -1):
			ans.append(arr[i][j][1])
for i in ans:
	print(i, end=' ')


import random
n = int(input())
stri = []
p = []
for i in range(n):
	for j in range(len(input())):
		p.append(i + 1)
random.shuffle(p)
ans = ' '.join([str(x) for x in p])
print(ans.strip())


import itertools
n = int(input())
cnt = 1
li = []
for i in range(n):
	s = input()
	for i in range(len(s)):
		li.append(cnt)
	cnt += 1
mid = (0 + len(li)) // 2
las = len(li) - 1
for i in range(len(li) // 3):
	(li[mid], li[las - 1]) = (li[las - 1], li[mid])
	mid -= 1
	las -= 1
for i in li:
	print(i, end=' ')


n = int(input())
stri = []
p = []
for i in range(n):
	stri.append([int(x) for x in input()])
	p.append(' '.join([str(i + 1) for x in stri[i]]))
ans = ' '.join(p)
print(ans.strip())


n = int(input())
strings = []
for i in range(n):
	strings.append(len(input()))
w = []
while True:
	flag = 0
	for i in range(n):
		if strings[i] > 0:
			w.append(str(i + 1))
			strings[i] -= 1
			flag = 1
	if flag == 0:
		break
print(' '.join(w))


n = int(input())
strings = []
for i in range(n):
	strings.append(input())
w = []
for x in range(0, n, 2):
	w += [str(x + 1)] * len(strings[x])
for x in range(1, n, 2):
	w += [str(x + 1)] * len(strings[x])
print(' '.join(w))


test = int(input())
strings = []
for i in range(test):
	string = list(input())
	strings.append(len(string))
ans = 0
for i in range(test):
	for j in range(strings[i]):
		print(ans + 1, end=' ')
	ans += 1


n = int(input())
a = []
for i in range(n):
	s = input().rstrip()
	a.append(s)
for i in range(1, n + 1):
	for j in range(1, len(s) + 1):
		print(i, end=' ')


import random
n = int(input())
useme = []
usemetoo = []
for _ in range(n):
	nouse = input()
	use = len(nouse)
	useme.append(use)
usemetoo = []
doubleuse = 1
for i in useme:
	for j in range(i):
		usemetoo.append(doubleuse)
	doubleuse += 1
random.shuffle(usemetoo)
for pp in usemetoo:
	print(pp, end=' ')


n = int(input())
for i in range(1, n + 1):
	st = input()
	for j in range(0, len(st)):
		print(i, end=' ')


n = int(input())
c = 1
while n > 0:
	s = input()
	l = len(s)
	for i in range(l):
		print(c, end=' ')
	c = c + 1
	n = n - 1


N = int(input())
nums = []
for i in range(N):
	s = input()
	nums.append((s, i + 1))
snums = sorted(nums)
S = len(nums[0][0])
ii = 0
maxi = S * N
res = []
while ii < maxi:
	iim = ii % N
	if ii // N % 2 == 1:
		iim = N - 1 - iim
	(_, ind) = snums[iim]
	ii += 1
	res.append(str(ind))
print(' '.join(res))


n = int(input())
dic = dict()

def DaC(lys, val):
	first = 0
	last = len(lys) - 1
	index = -1
	if last == -1:
		return -1
	if lys[-1] <= val:
		return -1
	while first <= last and index == -1:
		try:
			mid = (first + last) // 2
		except Exception as e:
			pass
		if lys[mid] >= val and lys[mid - 1] < val:
			index = mid
			return index
		elif val < lys[mid]:
			last = mid - 1
		else:
			first = mid + 1
	return 0

def add(s, e):
	i = DaC(s, e)
	if i == -1:
		s.append(e)
	else:
		s.insert(i, e)
	return s
for i in range(n):
	st = input()
	if st not in dic.keys():
		dic[st] = [i + 1]
	else:
		m = dic[st] + [i + 1]
		dic[st] = m
li = sorted(dic.keys())
a = 0
s = 0
while 1:
	for i in dic[li[-1]]:
		print(i, end=' ')
	if len(li[-1][:]) != 1:
		d = dic[li[-1]]
		st = li[-1][1:]
		del dic[li[-1]]
		li.remove(li[-1])
		while len(li) > 0 and len(st) > 0 and (st[0] >= li[-1][0:1]):
			for i in d:
				print(i, end=' ')
			st = st[1:]
		if st != '':
			if st not in dic.keys():
				dic[st] = d
				add(li, st)
			elif dic[st] != '':
				m = dic[st] + d
				dic.update({st: m})
		s += 1
	else:
		del dic[li[-1]]
		li.remove(li[-1])
	if dic == {}:
		break
	a += 1


import collections
n = int(input())
l = []
b = []
a = []
j = 1
while j <= n:
	l.append(input())
	j += 1
for i in range(0, 100):
	b = []
	for j in range(0, len(l)):
		if l[j] != '*':
			if len(l[j]) == 1:
				b.append(int(l[j]))
				l[j] = '*'
			else:
				b.append(int(l[j][0]))
				l[j] = l[j][1:]
		else:
			b.append(10)
	a.append(b)
for i in range(0, len(a)):
	c = sorted(a[i])
	for j in range(0, len(a[i])):
		if a[i][j] < 10:
			print(j + 1, end=' ')


n = int(input())
dic = dict()
li = []
lis = []
dic1 = dict()
for i in range(n):
	a = input()
	lis.append(a)
	if a in dic:
		dic[a] = dic[a] + [i + 1]
	else:
		dic[a] = [i + 1]
	co = a.count('0')
	if co in dic1:
		dic1[co] = dic1[co] + [i + 1]
	else:
		dic1[co] = [i + 1]
li = list(dic1.keys())
li.sort()
for i in range(len(li) - 1, -1, -1):
	for j in dic1[li[i]]:
		for k in range(len(lis[j - 1])):
			print(j, end=' ')


d = {}
sorting_list = []
total_length = 0
n = int(input())
if n < 100:
	for i in range(n):
		t = list(input())
		t = [int(x) for x in t]
		total_length += len(t)
		d[i] = t
	for i in range(n):
		sorting_list.append(d[i][0])
	for _ in range(total_length):
		i = sorting_list.index(min(sorting_list))
		print(i + 1, end=' ')
		d[i].remove(d[i][0])
		try:
			sorting_list[i] = d[i][0]
		except:
			sorting_list[i] = 10
else:
	l = []
	for i in range(n):
		t = list(input())
		t1 = []
		for j in range(len(t)):
			if t[j] == '0':
				print(i + 1, end=' ')
			else:
				t1.append(int(t[j]))
		l.append(t1)
	final_l = []
	for i in range(n):
		l1 = []
		for j in range(len(l[i])):
			if l[i][j] == 1:
				print(i + 1, end=' ')
			else:
				l1.append(l[i][j])
		final_l.append(l1)
	for i in range(n):
		for j in range(len(final_l[i])):
			print(i + 1, end=' ')


n = int(input())
l = []
p = []
count = 0
count2 = 0
for i in range(100):
	l.append([])
for i in range(n):
	s = input()
	p.append(s)
	for j in range(len(s)):
		if j == 0:
			count = count + int(s[j]) - 0
		else:
			count = count + int(s[j]) - int(s[j - 1])
		l[j].append((s[j], i + 1))
for i in range(100):
	if l[i] == []:
		break
	l[i].sort()
	for j in range(len(l[i])):
		if j == 0:
			count2 = count2 + int(l[i][j][0]) - 0
		else:
			count2 = count2 + int(l[i][j][0]) - int(l[i][j - 1][0])
last = 0
if count2 <= count:
	for i in range(100):
		if l[i] == []:
			break
		elif i == 0:
			for j in range(len(l[i])):
				print(l[i][j][1], end=' ')
				last = int(l[i][j][0])
		elif abs(int(l[i][0][0]) - last) <= abs(int(l[i][len(l[i]) - 1][0]) - last):
			for j in range(len(l[i])):
				print(l[i][j][1], end=' ')
				last = int(l[i][j][0])
		else:
			for j in range(len(l[i]) - 1, -1, -1):
				print(l[i][j][1], end=' ')
				last = int(l[i][j][0])
else:
	for i in range(len(p)):
		for j in range(len(p[i])):
			print(i + 1, end=' ')


n = int(input())
sz = 0
for i in range(n):
	st = input()
	sz = len(st)
res = ''
for i in range(sz):
	for j in range(n):
		print(str(j + 1), end=' ')


for i in range(int(input())):
	word = list(input())
	ans = [i + 1 for x in word]
	for x in ans:
		print(int(x), end=' ')


a = []
ass = []
anslen = 0
for _ in range(int(input())):
	xxx = input()
	n = int(xxx)
	a.append(n)
	nstr = str(n)
	anslen += len(xxx)
	ass.append(xxx)
l = len(a)
ans = [0 for x in range(anslen)]
count = 0
for sexx in range(100):
	fromx = 0
	tox = 10
	stepx = 1
	if sexx % 2 != 0:
		fromx = 9
		tox = -1
		stepx = -1
	for j in range(fromx, tox, stepx):
		for i in range(len(ass)):
			s = ass[i]
			if s == '':
				continue
			while int(s[0]) == j:
				ans[count] = i + 1
				count += 1
				if len(s) == 1:
					s = ''
					break
				elif len(s) == 2:
					s = s[1]
				else:
					s = s[1:]
			ass[i] = s
for i in ans:
	print(i, end=' ')


n = int(input())
leng = []
for i in range(n):
	s = input()
	leng.append(len(s))
l = '1'
ans = ''
for k in leng:
	ans += (l + ' ') * k
	l = str(int(l) + 1)
print(ans[:-1])


n = int(input())
list = [[], [], [], [], [], [], [], [], [], []]
for i in range(0, n):
	s = str(input())
	for j in range(0, len(s)):
		list[int(s[j])].append(i + 1)
for i in range(0, 10):
	for j in range(0, len(list[i])):
		print(list[i][j], end=' ')


def multify(seqs):
	ret = []
	for seq in seqs:
		mul_seq = []
		prev = seq[0]
		count = 1
		for val in seq[1:]:
			if val == prev:
				count += 1
			else:
				mul_seq.append((prev, count))
				prev = val
				count = 1
		mul_seq.append((prev, count))
		ret.append(mul_seq)
	return ret

def digify(seqs):
	ret = [[] for _ in range(10)]
	for (index, seq) in enumerate(seqs):
		ret[seq.pop()].append(index)
	return ret

def eat_all(digit, seqs, digit_to_seqs):
	indices = digit_to_seqs[digit]
	ret = []
	digit_to_seqs[digit] = []
	for index in indices:
		ret.append(index + 1)
		seq = seqs[index]
		if len(seq) > 0:
			val = seq.pop()
			digit_to_seqs[val].append(index)
	return ret

def naive(seqs, digit_to_seqs):
	ret = []
	limit = len(seqs) * (len(seqs[0]) + 1)
	cur = 0
	dif = 1
	while len(ret) < limit:
		ret.extend(eat_all(cur, seqs, digit_to_seqs))
		cur += dif
		if cur == 0 or cur == 9:
			dif *= -1
	return ret
N = int(input())
seqs = [list(map(int, reversed(input().strip()))) for _ in range(N)]
digit_to_seqs = digify(seqs)
print(' '.join((str(val) for val in naive(seqs, digit_to_seqs))))


from random import choice
n = int(input())
la = []
for i in range(n):
	s = input()
	la.append(len(s))
la = [0] + la
suma = sum(la)
cl = [int(x) for x in range(1, n + 1)]
while cl:
	ni = choice(cl)
	print(ni, end=' ')
	la[ni] = la[ni] - 1
	if la[ni] == 0:
		cl.remove(ni)
print()


import random
n = int(input())
sz = 0
for i in range(n):
	st = input()
	sz = len(st)
lst = []
for i in range(n):
	for j in range(sz):
		lst.append(i + 1)
random.shuffle(lst)
random.shuffle(lst)
random.shuffle(lst)
for each in lst:
	print(str(each), end=' ')


def value(s):
	n = len(s)
	Sum = 0
	for i in range(1, n):
		Sum += (int(s[i]) - int(s[i - 1])) ** 2
	return Sum
T = int(input())
ls = []
for i in range(T):
	ls.append((input(), i + 1))
ls.sort(key=lambda x: x[0])
n = len(ls[0][0])
s1 = ''
for i in ls:
	s1 += i[0]
v1 = value(s1)
s2 = ''
for j in range(n):
	for i in range(T):
		s2 += ls[i][0][j]
v2 = value(s2)
if v1 < v2:
	for i in ls:
		print((str(i[1]) + ' ') * n, end='')
else:
	for i in range(n):
		for i in ls:
			print(i[1], end=' ')


ans = []
count = 1
for _ in range(int(input())):
	nstr = input()
	val = [count for x in range(len(nstr))]
	count += 1
	ans.extend(val)
for i in ans:
	print(i, end=' ')


from collections import *
import heapq
n = int(input())
Ps = []
c = 0
front = []
heapq.heapify(front)
for i in range(n):
	Ps.append(deque([int(i) for i in input()]))
	heapq.heappush(front, (Ps[-1][0], i))
	c += len(Ps[-1])
W = []
while c:
	(ch, ind) = heapq.heappop(front)
	W.append(ind + 1)
	u = Ps[ind][0]
	Ps[ind].popleft()
	if Ps[ind]:
		Ps[ind][0] = abs(u - Ps[ind][0]) + u
		heapq.heappush(front, (Ps[ind][0], ind))
	c -= 1
for i in W:
	print(i, end=' ')
print()


a = []
e = {}
t = int(input())
for j in range(t):
	s = input()
	z = 0
	for i in s:
		z = z + int(i)
	e[j + 1] = z
so = sorted(e.items(), key=lambda kv: kv[1])
j = 1
f = len(s)
for i in range(1, f * t + 1):
	print(so[j - 1][0], end=' ')
	if i % f == 0:
		j = j + 1


import sys

def score(w):
	p = [0] * n
	vis = [0] * n
	rez = 0
	for i in range(1, len(w)):
		i1 = int(w[i]) - 1
		b1 = int(a[i1][p[i1]])
		if vis[i1] == 0:
			vis[i1] = 1
			p[i1] += 1
		i2 = int(w[i - 1]) - 1
		b2 = int(a[i2][p[i2]])
		if vis[i2] == 0:
			vis[i2] = 1
			p[i2] += 1
		rez += (b1 - b2) * (b1 - b2)
	return rez
f = sys.stdin
n = int(f.readline())
a = []
for i in range(n):
	s = f.readline().rstrip()
	a.append(s)
w = []
rez1 = 0
for i in range(n):
	for j in range(len(a[i])):
		w.append(str(1 + i))
rez1 = score(w)
ans = w
w = []
for i in range(n):
	w.append(str(1 + i))
w *= len(a[0])
rez2 = score(w)
if rez2 < rez1:
	ans = w
print(' '.join(ans))


try:
	n = int(input())
	w = ''
	arr = []
	for i in range(n):
		s = input()
		arr.append(len(s))
		w = w + s
	k = 1
	for i in arr:
		for j in range(i):
			print(k, end=' ')
		k += 1
except:
	pass


n = int(input())
dic = dict()
for i in range(n):
	a = input()
	if a in dic:
		dic[a] = dic[a] + [i + 1]
	else:
		dic[a] = [i + 1]
ans = []
li = sorted(dic.keys())
for i in range(len(li)):
	for j in dic[li[i]]:
		for k in range(len(li[i])):
			print(j, end=' ')


a = []
t = int(input())
for j in range(t):
	n = input()
	s = str(n)
	for i in s:
		a.append(j + 1)
for i in range(len(a)):
	if a[i] == t:
		print(1, end=' ')
	elif a[i] == 1:
		print(t, end=' ')
	else:
		print(a[i], end=' ')


n = int(input())
dic = dict()
for i in range(n):
	a = input()
	dic[a] = [i + 1]
ans = []
li = sorted(dic.keys())
for i in range(len(li)):
	ans += dic[li[i]] * len(li[i])
for i in ans:
	print(i, end=' ')


n = int(input())
import bisect
it = []
oo = []
for _ in range(n):
	it.append([int(i) for i in input()])
for io in range(20):
	s = [(j + io * 500, i[0]) for (j, i) in enumerate(it[io * 500:io * 500 + 500])]
	s.sort(key=lambda x: x[1])
	ss = [i[1] for i in s]
	co = 0
	while s:
		co += 1
		k = s[0]
		oo.append(k[0] + 1)
		try:
			aa = it[k[0]]
			try:
				aa = aa[1:]
				it[k[0]] = aa
			except:
				del it[k[0]]
			try:
				s = s[1:]
				ss = ss[1:]
			except:
				pass
			ind = bisect.bisect_left(ss, aa[0])
			s.insert(ind, (k[0], aa[0]))
			ss.insert(ind, aa[0])
		except:
			pass
for (k, i) in enumerate(it):
	for j in i:
		oo.append(k + 1)
print(' '.join([str(i) for i in oo]))


n = int(input())
import random
import bisect, time
it = []
oo = []
for _ in range(n):
	it.append([int(i) for i in input()])
a = time.time()
for io in range(1000):
	b = time.time()
	if b - a > 80:
		break
	s = [(j + io * 10, i[0]) for (j, i) in enumerate(it[io * 10:io * 10 + 10])]
	s.sort(key=lambda x: x[1])
	ss = [i[1] for i in s]
	co = 0
	while s:
		co += 1
		k = s[0]
		oo.append(k[0] + 1)
		try:
			aa = it[k[0]]
			try:
				aa = aa[1:]
				it[k[0]] = aa
			except:
				del it[k[0]]
			try:
				s = s[1:]
				ss = ss[1:]
			except:
				pass
			ind = bisect.bisect_left(ss, aa[0])
			s.insert(ind, (k[0], aa[0]))
			ss.insert(ind, aa[0])
		except:
			pass
for (k, i) in enumerate(it):
	for j in i:
		oo.append(k + 1)
print(' '.join([str(i) for i in oo]))


n = int(input())
import bisect
it = []
oo = []
for _ in range(n):
	it.append([int(i) for i in input()])
s = [(j, i[0]) for (j, i) in enumerate(it)]
s.sort(key=lambda x: x[1])
ss = [i[1] for i in s]
for (k, i) in enumerate(it):
	for j in i:
		oo.append(k + 1)
print(' '.join([str(i) for i in oo]))


n = int(input())
s = []
for i in range(n):
	s.append([input(), i])
s.sort()
for i in range(n):
	(j, k) = s[i]
	j = list(j)
	j.sort()
	s[i] = [j, k]
ans = []
for i in range(len(s)):
	for j in range(len(s[i][0])):
		ans.append(s[i][1] + 1)
print(*ans)


d = {}
sorting_list = []
total_length = 0
n = int(input())
if n < 7500:
	for i in range(n):
		t = list(input())
		t = [int(x) for x in t]
		total_length += len(t)
		d[i] = t
	for i in range(n):
		sorting_list.append(d[i][0])
	for _ in range(total_length):
		i = sorting_list.index(min(sorting_list))
		print(i + 1, end=' ')
		d[i].remove(d[i][0])
		try:
			sorting_list[i] = d[i][0]
		except:
			sorting_list[i] = 10
else:
	l = []
	for i in range(n):
		t = list(input())
		length = len(t)
		l.append(length)
	for i in range(n):
		for j in range(1, l[i] + 1):
			print(i + 1, end=' ')