Consider an array of numeric strings where each string is a positive number with anywhere from $\mbox{I}$ to $10^{6}$ digits. Sort the array's elements in non-decreasing, or ascending order of their integer values and return the sorted array.

Example 

$unsorted=[\text{'1'},\text{'200'},\text{'150'},\text{'3'}]$  

Return the array ['1', '3', '150', '200']. 

Function Description  

Complete the bigSorting function in the editor below.  

bigSorting has the following parameter(s):  

string unsorted[n]: an unsorted array of integers as strings  

Returns  

string[n]:  the array sorted in numerical order  

Input Format

The first line contains an integer, $n$, the number of strings in $un sorted$. 

Each of the $n$ subsequent lines contains an integer string, ${un sorted}[i]$.

Constraints

$1\leq n\leq2\times10^5$
Each string is guaranteed to represent a positive integer.
There will be no leading zeros.
The total number of digits across all strings in $un sorted$ is between $\mbox{I}$ and $10^{6}$ (inclusive).

Sample Input 0
6
31415926535897932384626433832795
1
3
10
3
5

Sample Output 0
1
3
3
5
10
31415926535897932384626433832795

Explanation 0

The initial array of strings is $unsorted=[31415926535879338846464383795,1,3,10,3,5]$. When we order each string by the real-world integer value it represents, we get: $1\leq3\leq3\leq5\leq10\leq31415926535897932384626433832795$

We then print each value on a new line, from smallest to largest.

Sample Input 1
8
1
2
100
12303479849857341718340192371
3084193741082937
3084193741082938
111
200

Sample Output 1
1
2
100
111
200
3084193741082937
3084193741082938
12303479849857341718340192371

Difficulty: EASY
Tags: Sorting
Skill types: Sorting

Starter code:

Solutions:
import sys
n = int(input().strip())
unsorted = []
unsorted_i = 0
for unsorted_i in range(n):
	unsorted_t = str(input().strip())
	unsorted.append(unsorted_t)
unsorted.sort(key=lambda x: int(x))
for u in unsorted:
	print(u)


print(*sorted((input() for _ in range(int(input()))), key=int), sep='\n')


n = int(input().strip())
data = [input().strip() for i in range(n)]
data.sort(key=lambda x: (len(x), x))
for v in data:
	print(v)


import sys
n = int(input().strip())
unsorted = []
unsorted_i = 0
for unsorted_i in range(n):
	unsorted_t = str(input().strip())
	unsorted.append(unsorted_t)
print(*sorted(unsorted, key=lambda x: (len(x), x)), sep='\n')


import sys
n = int(input().strip())
unsorted = []
unsorted_i = 0
for unsorted_i in range(n):
	unsorted_t = str(input().strip())
	unsorted.append(unsorted_t)
ans = sorted(unsorted, key=lambda x: (len(x), x))
for s in ans:
	print(s)


import sys
n = int(input().strip())
unsorted = []
unsorted_i = 0
for unsorted_i in range(n):
	unsorted_t = str(input().strip())
	unsorted.append(unsorted_t)
bylen = sorted(unsorted, key=len)
srted = []
(l, r) = (0, 0)
while r < n:
	while r < n and len(bylen[r]) == len(bylen[l]):
		r += 1
	srted.extend(sorted(bylen[l:r]))
	l = r
for a in srted:
	print(a)


import sys
n = int(input().strip())
unsorted = []
unsorted_i = 0
for unsorted_i in range(n):
	unsorted_t = str(input().strip())
	unsorted.append(unsorted_t)
unsorted.sort(key=lambda x: (len(x), x))
for i in unsorted:
	print(i)


import sys
n = int(input().strip())
unsorted = []
unsorted_i = 0
for unsorted_i in range(n):
	unsorted.append(str(input().strip()))
for x in sorted(unsorted, key=lambda s: (len(s), s)):
	print(x)


n = int(input())
N = list((input() for _ in range(n)))
N.sort(key=int)
for n in N:
	print(n)


import sys
n = int(input().strip())
unsorted = []
unsorted_i = 0
for unsorted_i in range(n):
	unsorted_t = str(input().strip())
	unsorted.append(unsorted_t)
for i in sorted(unsorted, key=int):
	print(i)


import sys
n = int(input().strip())
unsorted = []
length_d = dict()
unsorted_i = 0
for unsorted_i in range(n):
	t = str(input().strip())
	t_len = len(t)
	try:
		length_d[t_len].append(t)
	except:
		length_d[t_len] = [t]
lk = list(length_d.keys())
lk.sort()
for l in lk:
	length_d[l].sort()
	for x in length_d[l]:
		print(x)


arr = []
n = int(input())
for i in range(n):
	arr.append(input().strip())
arr.sort(key=lambda x: (len(x), x))
for s in arr:
	print(s)


import sys
n = int(input().strip())
unsorted = []
unsorted_i = 0
for unsorted_i in range(n):
	unsorted_t = str(input().strip())
	unsorted.append(unsorted_t)
sort_arr = sorted(unsorted, key=lambda x: int(x))
for i in sort_arr:
	print(i)


import sys
n = int(input().strip())
unsorted = []
unsorted_i = 0
for unsorted_i in range(n):
	unsorted_t = str(input().strip())
	unsorted.append(unsorted_t)
result = sorted(unsorted, key=lambda x: int(x))
for r in result:
	print(r)


print('\n'.join(sorted((input().strip() for _ in range(int(input().strip()))), key=int)))


import sys
n = int(input().strip())
unsorted = []
unsorted_i = 0
for unsorted_i in range(n):
	unsorted_t = str(input().strip())
	unsorted.append(unsorted_t)
unsorted.sort(key=int)
for n in unsorted:
	print(n)


import sys
n = int(input().strip())
unsorted = []
unsorted_i = 0
for unsorted_i in range(n):
	unsorted_t = str(input().strip())
	unsorted.append(unsorted_t)
for v in sorted(unsorted, key=lambda v: int(v)):
	print(v)


n = int(input().strip())
unsorted = []
unsorted_i = 0
for unsorted_i in range(n):
	unsorted_t = str(input().strip())
	unsorted.append(unsorted_t)
unsorted.sort(key=int)
for ele in unsorted:
	print(ele)


import sys
n = int(input().strip())
unsorted = []
unsorted_i = 0
for unsorted_i in range(n):
	unsorted_t = str(input().strip())
	unsorted.append(unsorted_t)
unsorted.sort(key=int)
for items in unsorted:
	print(items)


n = int(input().strip())
unsorted = [input().strip() for _ in range(n)]
unsorted = sorted(unsorted, key=lambda s: (len(s), s))
for s in unsorted:
	print(s)


import sys
n = int(input().strip())
unsorted = []
unsorted_i = 0
for unsorted_i in range(n):
	unsorted_t = str(input().strip())
	unsorted.append(unsorted_t)
unsorted.sort(key=int)
for x in unsorted:
	print(x)


import sys
n = int(input().strip())
unsorted = []
unsorted_i = 0
for unsorted_i in range(n):
	unsorted_t = str(input().strip())
	unsorted.append(unsorted_t)
sort_ = sorted(unsorted, key=int)
for i in sort_:
	print(i)


import sys

def sort_without_cast_to_int(unsorted):
	sorted_smb_values = []
	length_ind = [(len(unsorted[i]), i) for i in range(len(unsorted))]
	unique_lengths = list(set([ll for (ll, i) in length_ind]))
	for ll in sorted(unique_lengths):
		tmp_unsorted = [unsorted[i] for (ll_i, i) in length_ind if ll_i == ll]
		for el in sorted(tmp_unsorted):
			sorted_smb_values.append(el)
	return sorted_smb_values
n = int(input().strip())
unsorted = []
unsorted_i = 0
for unsorted_i in range(n):
	unsorted_t = str(input().strip())
	unsorted.append(unsorted_t)
res = sort_without_cast_to_int(unsorted)
for el in res:
	print(el)


import sys
n = int(input().strip())
unsorted = []
unsorted_i = 0
for unsorted_i in range(n):
	unsorted_t = str(input().strip())
	unsorted.append(unsorted_t)
unsorted.sort(key=int)
for i in unsorted:
	print(i)


import sys
from collections import defaultdict as dd
n = int(input().strip())
unsorted = []
ip = dd(list)
for unsorted_i in range(n):
	t = str(input().strip())
	ip[len(t)].append(t)
keys = list(ip.keys())
keys.sort()
for key in keys:
	v = ip[key]
	v.sort()
	for vi in v:
		print(vi)


import sys
N = int(input())
sort = []
for n in range(N):
	s = input()
	sort.append([len(s), s])
sort = sorted(sort)
for s in sort:
	print(s[1])


import sys
n = int(input().strip())
unsorted = []
unsorted_i = 0
for unsorted_i in range(n):
	unsorted_t = str(input().strip())
	unsorted.append(unsorted_t)
unsorted.sort(key=int)
for i in range(n):
	print(unsorted[i])


import sys
n = int(input().strip())
unsorted = []
unsorted_i = 0
for unsorted_i in range(n):
	unsorted_t = str(input().strip())
	unsorted.append(unsorted_t)
unsorted.sort(key=len, reverse=False)
unsorted.sort(key=int)
for i in unsorted:
	print(i)


import sys
n = int(input().strip())
unsorted = []
unsorted_i = 0
for unsorted_i in range(n):
	unsorted.append(str(input().strip()))
unsorted.sort(key=lambda s: '{:>7}{:}'.format(len(s), s))
for t in unsorted:
	print(t.strip())


import sys
n = int(input().strip())
unsorted = []
unsorted_i = 0
for unsorted_i in range(n):
	unsorted_t = str(input().strip())
	unsorted.append(unsorted_t)
for i in sorted(unsorted, key=lambda val: int(val)):
	print(i)


import sys
n = int(input().strip())
unsorted = []
unsorted_i = 0
for unsorted_i in range(n):
	unsorted_t = str(input().strip())
	unsorted.append(unsorted_t)
unsorted.sort(key=int)
for i in unsorted:
	print(i)


import sys
n = int(input().strip())
unsorted = []
unsorted_i = 0
for unsorted_i in range(n):
	unsorted_t = str(input().strip())
	unsorted.append(unsorted_t)
unsorted.sort()
unsorted.sort(key=lambda s: len(s))
for unsorted_i in unsorted:
	print(unsorted_i)


import sys
n = int(input().strip())
unsorted = []
unsorted_i = 0
for unsorted_i in range(n):
	unsorted_t = str(input().strip())
	unsorted_t.lstrip('0')
	unsorted.append((len(unsorted_t), unsorted_t))
unsorted.sort()
for x in unsorted:
	print(x[1])


import sys
n = int(input().strip())
unsorted = []
unsorted_i = 0
for unsorted_i in range(n):
	unsorted_t = str(input().strip())
	unsorted.append(unsorted_t)
unsorted.sort(key=int)
for word in unsorted:
	print(word)


import sys
n = int(input().strip())
unsorted = []
unsorted_i = 0
for unsorted_i in range(n):
	unsorted_t = str(input().strip())
	unsorted.append(unsorted_t)
sorted = unsorted.sort(key=int)
for item in unsorted:
	print(item)


import sys
n = int(input().strip())
unsorted = []
for i in range(n):
	unsorted.append(str(input().strip()))
unsorted.sort(key=lambda x: (len(x), x))
for e in unsorted:
	print(e)


import sys
n = int(input().strip())
unsorted = []
unsorted_i = 0
for unsorted_i in range(n):
	unsorted_t = str(input().strip())
	unsorted.append(unsorted_t)
unsorted.sort(key=int)
for unsorted_i in unsorted:
	print(unsorted_i)


import sys
n = int(input().strip())
unsorted = []
unsorted_i = 0
for unsorted_i in range(n):
	unsorted_t = str(input().strip())
	unsorted.append(unsorted_t)
unsorted.sort(key=int)
for i in unsorted:
	print(i)


n = int(input())
li = []
for i in range(0, n):
	x = input()
	li.append(x)
li.sort(key=int)
for i in range(0, n):
	print(li[i])


import sys
n = int(input().strip())
unsorted = []
unsorted_i = 0
for unsorted_i in range(n):
	unsorted_t = str(input().strip())
	unsorted.append(unsorted_t)
unsorted.sort(key=int)
for i in unsorted:
	print(i)


from itertools import groupby
keyfunc = lambda s: len(s)
data = sorted((input() for _ in range(int(input()))), key=keyfunc)
for (k, g) in groupby(data, key=keyfunc):
	print(*sorted(g), sep='\n')


import sys
n = int(input().strip())
unsorted = []
unsorted_i = 0
for unsorted_i in range(n):
	unsorted_t = str(input().strip())
	unsorted.append(unsorted_t)
unsorted.sort(key=lambda x: int(x), reverse=False)
for i in unsorted:
	print(i)


import sys
n = int(input().strip())
unsorted = []
unsorted_i = 0
for unsorted_i in range(n):
	unsorted_t = str(input().strip())
	unsorted.append(unsorted_t)
unsorted = sorted(unsorted, key=lambda s: int(s))
for i in range(n):
	print(unsorted[i])


import sys
n = int(input().strip())
unsorted = []
unsorted_i = 0
for unsorted_i in range(n):
	unsorted_t = str(input().strip())
	unsorted.append(unsorted_t)
unsorted.sort(key=int)
for i in unsorted:
	print(i)


import sys
n = int(input().strip())
unsorted = []
unsorted_i = 0
for unsorted_i in range(n):
	unsorted_t = str(input().strip())
	unsorted.append(unsorted_t)
unsorted.sort(key=int)
for i in unsorted:
	print(i)


import sys
import functools

def compare(x, y):
	if len(x) > len(y):
		return 1
	elif len(x) < len(y):
		return -1
	else:
		for (dx, dy) in zip(x, y):
			if dx > dy:
				return 1
			elif dx < dy:
				return -1
		return 0
n = int(input().strip())
unsorted = []
unsorted_i = 0
for unsorted_i in range(n):
	unsorted_t = str(input().strip())
	unsorted.append(unsorted_t)
for x in sorted(unsorted, key=functools.cmp_to_key(compare)):
	print(x)


import sys
import re

def atoi(text):
	return int(text) if text.isdigit() else text

def natural_keys(text):
	return [atoi(c) for c in re.split('(\\d+)', text)]
n = int(input().strip())
unsorted = []
unsorted_i = 0
for unsorted_i in range(n):
	unsorted_t = str(input().strip())
	unsorted.append(unsorted_t)
unsorted.sort(key=natural_keys)
for item in unsorted:
	print(item)


N = int(input().strip())
vals = []
for n in range(N):
	s = input().strip()
	vals.append(s)
vals = sorted(vals, key=lambda x: (len(x), x))
for s in vals:
	print(s)


import sys
n = int(input().strip())
unsorted = []
for unsorted_i in range(n):
	unsorted_t = str(input().strip())
	unsorted.append(unsorted_t)
unsorted.sort(key=lambda _: int(_))
for s in unsorted:
	print(s)


import sys
n = int(input().strip())
unsorted = []
unsorted_i = 0
for unsorted_i in range(n):
	unsorted_t = str(input().strip())
	unsorted.append(unsorted_t)
unsorted.sort(key=len)
i = 0
while i < n:
	j = i
	count = 0
	while j < n - 1 and len(unsorted[j]) == len(unsorted[j + 1]):
		if j == n - 1:
			j += 1
		j += 1
	j += 1
	temp = unsorted[i:j]
	del unsorted[i:j]
	temp.sort()
	unsorted[i:i] = temp
	i = max(j, i + 1)
print('\n'.join(map(str, unsorted)))


import sys

def solve(n, inp):
	numbers = [inp.readline().strip() for x in range(n)]
	numbers.sort(key=lambda x: (len(x), x))
	[print(x) for x in numbers]

def main(inp=sys.stdin):
	n = int(inp.readline().strip())
	solve(n, inp)
main()


import sys
n = int(input().strip())
unsorted = []
unsorted_i = 0
for unsorted_i in range(n):
	unsorted_t = str(input().strip())
	unsorted.append(unsorted_t)
for val in sorted(unsorted, key=lambda val: (len(val.lstrip('0')), val.lstrip('0'))):
	print(val)


n = int(input())
arr = [input() for i in range(n)]
arr.sort()
arr.sort(key=lambda x: len(x))
print(*arr, sep='\n')


def ms(l1, l2):
	(ln1, ln2) = (len(l1), len(l2))
	(i, j) = (0, 0)
	c = []
	while i + j < ln1 + ln2:
		if i == ln1:
			c.append(l2[j])
			j += 1
		elif j == ln2:
			c.append(l1[i])
			i += 1
		elif len(l1[i]) < len(l2[j]):
			c.append(l1[i])
			i += 1
		elif len(l1[i]) > len(l2[j]):
			c.append(l2[j])
			j += 1
		elif l1[i] < l2[j]:
			c.append(l1[i])
			i += 1
		else:
			c.append(l2[j])
			j += 1
	return c

def mers(a, l, r):
	if r - l <= 1:
		return a[l:r]
	mid = (l + r) // 2
	le = mers(a, l, mid)
	ri = mers(a, mid, r)
	return ms(le, ri)
n = int(input().strip())
unsorted = list()
for unsorted_i in range(n):
	unsorted_t = str(input().strip())
	unsorted.append(unsorted_t)
k = mers(unsorted, 0, n)
for i in range(n):
	print(k[i])


n = int(input().strip())
len_arr = [0] * 1000000
unsorted = []
unsorted_i = 0
for unsorted_i in range(n):
	unsorted_t = str(input().strip())
	dig_len = len(unsorted_t) - 1
	if len_arr[dig_len] == 0:
		len_arr[dig_len] = [unsorted_t]
	else:
		len_arr[dig_len].append(unsorted_t)
	unsorted.append(unsorted_t)
sort_arr = []
for elements in len_arr:
	if elements != 0:
		sort_arr += sorted(elements)
print('\n'.join(sort_arr))


import sys
n = int(input().strip())
unsorted = []
unsorted_i = 0
for unsorted_i in range(n):
	unsorted_t = str(input().strip())
	unsorted.append(unsorted_t)
unsorted.sort(key=int)
unsorted_i = 0
for unsorted_i in range(n):
	print(unsorted[unsorted_i])


import sys
n = int(input().strip())
unsorted = []
unsorted_i = 0
for unsorted_i in range(n):
	unsorted_t = str(input().strip())
	unsorted.append(unsorted_t)
sorted_ = []
numbers = {}
for number in unsorted:
	numbers.setdefault(len(number), []).append(number)
lengths = sorted(numbers.keys())
for l in lengths:
	sorted_.extend(sorted(numbers[l]))
print('\n'.join(sorted_))


import sys
n = int(input().strip())
unsorted = []
unsorted_i = 0
for unsorted_i in range(n):
	unsorted_t = str(input().strip())
	unsorted.append(unsorted_t)
ans = []
ans = sorted(unsorted, key=int)
i = 0
for i in range(n):
	print(ans[i])


import sys
import re

def atoi(text):
	return int(text) if text.isdigit() else text

def natural_keys(text):
	return [atoi(c) for c in re.split('(\\d+)', text)]

def main():
	n = int(input().strip())
	unsorted = []
	unsorted_i = 0
	for unsorted_i in range(n):
		unsorted_t = str(input().strip())
		unsorted.append(unsorted_t)
	unsorted.sort(key=natural_keys)
	print(*unsorted, sep='\n')
main()


import sys
n = int(input().strip())
unsorted = []
unsorted_i = 0
for unsorted_i in range(n):
	unsorted_t = str(input().strip())
	unsorted.append(unsorted_t)
unsorted.sort(key=lambda s: (len(s), s))
for s in unsorted:
	print(s)


n = int(input().strip())
numbers = dict()
for i in range(n):
	t = str(input().strip())
	l = len(t)
	if l not in numbers.keys():
		numbers[l] = []
	numbers[l].append(t)
for (l, t) in sorted(numbers.items()):
	for num in sorted(t):
		print(num)


import sys
n = int(input().strip())
unsorted = []
unsorted_i = 0
for unsorted_i in range(n):
	unsorted_t = str(input().strip())
	unsorted.append(unsorted_t)
unsorted.sort(key=int)
for i in unsorted:
	print(i)


def foo(x, y):
	if len(x) != len(y):
		return len(x) - len(y)
	elif x > y:
		return 1
	elif x < y:
		return -1
	else:
		return 0
n = int(input())
l = []
for i in range(n):
	l.append(input())
import functools
l = sorted(l, key=functools.cmp_to_key(foo))
print('\n'.join(l))


import sys
n = int(input().strip())
unsorted = []
unsorted_i = 0
for unsorted_i in range(n):
	unsorted_t = str(input().strip())
	unsorted.append(unsorted_t)
unsorted.sort(key=int)
for e in unsorted:
	print(e)


import sys
n = int(input().strip())
i = 0
dic = {}
for i in range(n):
	t = str(input().strip())
	if len(t) in dic.keys():
		dic[len(t)].append(t)
	else:
		dic[len(t)] = [t]
keys = sorted(dic)
for key in keys:
	temp = sorted(dic[key])
	for item in temp:
		print(item)


import sys
from collections import defaultdict
n = int(input().strip())
dictionary = defaultdict(list)
unsorted = []
unsorted_i = 0
for unsorted_i in range(n):
	raw = str(input().strip())
	num = int(raw)
	dictionary[num].append(raw)
	unsorted.append(num)
unsorted.sort()
seen = set()
for number in unsorted:
	if number in seen:
		continue
	seen.add(number)
	strings = dictionary[number]
	strings.sort()
	for string in strings:
		print(string)


import sys
n = int(input().strip())
X = []
for i in range(n):
	s = str(input().strip())
	X.append((len(s), s))
X = sorted(X)
for t in X:
	print(t[1])


import sys
n = int(input().strip())
unsorted = []
unsorted_i = 0
for unsorted_i in range(n):
	unsorted_t = str(input().strip())
	unsorted.append(unsorted_t)
unsorted.sort()
unsorted.sort(key=len, reverse=False)
for i in unsorted:
	print(i)


import functools

def comparator(x, y):
	if len(x) < len(y):
		return -1
	elif len(x) > len(y):
		return 1
	else:
		for i in range(len(x)):
			if x[i] < y[i]:
				return -1
			elif x[i] > y[i]:
				return 1
		return 0
n = int(input().strip())
unsorted = []
unsorted_i = 0
for unsorted_i in range(n):
	unsorted_t = str(input().strip())
	unsorted.append(unsorted_t)
sorted_list = sorted(unsorted, key=functools.cmp_to_key(comparator))
for n in sorted_list:
	print(n)


import sys
len_dict = {}
n = int(input().strip())
unsorted = []
unsorted_i = 0
for unsorted_i in range(n):
	unsorted_t = str(input().strip())
	l = len(unsorted_t)
	if l in len_dict:
		len_dict[l].append(unsorted_t)
	else:
		len_dict[l] = [unsorted_t]
l_keys = list(len_dict.keys())
l_keys.sort()
for i in l_keys:
	temp = len_dict[i][:]
	temp.sort()
	for j in temp:
		print(j)


import sys
n = int(input().strip())
unsorted_i = 0
numbers_by_length = {}
for unsorted_i in range(n):
	unsorted_t = str(input().strip())
	if len(unsorted_t) not in numbers_by_length:
		numbers_by_length[len(unsorted_t)] = []
	numbers_by_length[len(unsorted_t)].append(unsorted_t)
lengths = sorted(numbers_by_length.keys())
for length in lengths:
	sorted_numbers = sorted(numbers_by_length[length])
	for sorted_number in sorted_numbers:
		print(sorted_number)


import sys
n = int(input().strip())
unsorted = []
unsorted_i = 0
for unsorted_i in range(n):
	unsorted_t = str(input().strip())
	unsorted.append(unsorted_t)
unsorted.sort(key=len)
lg = len(unsorted[0]) - 1
my_list = list()
for i in unsorted:
	if lg != len(i):
		new_list = list()
		lg = len(i)
		new_list.append(i)
		my_list.append(new_list)
	else:
		my_list[-1].append(i)
final_list = list()
for i in my_list:
	i.sort()
	for j in i:
		final_list.append(j)
for i in final_list:
	print(i)


import sys
n = int(input().strip())
unsorted = []
unsorted_i = 0
for unsorted_i in range(n):
	unsorted_t = str(input().strip())
	unsorted.append(unsorted_t)
for i in sorted(unsorted, key=int):
	print(i)


import sys
n = int(input().strip())
unsorted = []
unsorted_i = 0
for unsorted_i in range(n):
	unsorted_t = str(input().strip())
	unsorted.append(unsorted_t)
for i in sorted(unsorted, key=int):
	print(i)


import sys
n = int(input().strip())
unsorted = []
unsorted_i = 0
for unsorted_i in range(n):
	unsorted_t = str(input().strip())
	unsorted.append(unsorted_t)
unsorted = sorted(unsorted, key=int)
for i in unsorted:
	print(i)


import sys
n = int(input().strip())
ordem = {}
unsorted_i = 0
for unsorted_i in range(n):
	unsorted_t = str(input().strip())
	size = len(unsorted_t)
	if size in ordem:
		ordem[size].append(unsorted_t)
	else:
		ordem[size] = [unsorted_t]
tamanhos = sorted(ordem)
for t in tamanhos:
	l = sorted(ordem[t])
	for n in l:
		print(n)


import sys
n = int(input().strip())
unsorted = []
unsorted_i = 0
for unsorted_i in range(n):
	unsorted_t = str(input().strip())
	unsorted.append(unsorted_t)
unsorted.sort(key=int)
print('\n'.join(unsorted))


import sys
n = int(input().strip())
unsorted = []
unsorted_i = 0
for unsorted_i in range(n):
	unsorted_t = str(input().strip())
	unsorted.append(unsorted_t)
ans = sorted(unsorted, key=int)
for i in ans:
	print(i)


import sys
n = int(input().strip())
unsorted = []
unsorted_i = 0
for unsorted_i in range(n):
	unsorted_t = str(input().strip())
	unsorted.append(unsorted_t)
unsorted = sorted(unsorted, key=lambda x: int(x))
for i in range(n):
	print(unsorted[i])


n = int(input())
nums = [input().strip() for _ in range(n)]
nums.sort()
nums.sort(key=lambda x: len(x))
for x in nums:
	print(x)


import sys
n = int(input().strip())
unsorted = []
unsorted_i = 0
for unsorted_i in range(n):
	unsorted_t = str(input().strip())
	unsorted.append(unsorted_t)
for i in sorted(unsorted, key=int):
	print(i)


import sys
n = int(input().strip())
unsorted = []
unsorted_i = 0
for unsorted_i in range(n):
	unsorted_t = str(input().strip())
	unsorted.append(unsorted_t)
x = [[i, len(unsorted[i])] for i in range(len(unsorted))]
x.sort(key=lambda x: x[1])
current_len = 0
to_sort = []
for (i, l) in x:
	if l == current_len:
		to_sort.append(unsorted[i])
	else:
		to_sort.sort()
		[print(x) for x in to_sort]
		current_len = l
		to_sort = [unsorted[i]]
to_sort.sort()
[print(x) for x in to_sort]


n = int(input().strip())
unsorted = []
unsorted_i = 0
for unsorted_i in range(n):
	unsorted_t = str(input().strip())
	unsorted.append(unsorted_t)
unsorted.sort(key=int)
for i in unsorted:
	print(i)


import sys
n = int(input().strip())
unsorted = []
unsorted_i = 0
for unsorted_i in range(n):
	unsorted_t = str(input().strip())
	unsorted.append(unsorted_t)
for i in sorted(unsorted, key=lambda s: int(s)):
	print(i)


import sys
n = int(input().strip())
unsorted = []
unsorted_i = 0
for unsorted_i in range(n):
	unsorted_t = str(input().strip())
	unsorted.append(unsorted_t)
sorte_d = []
sorte_d = sorted(unsorted, key=int)
print(*sorte_d, sep='\n')


import sys
n = int(input().strip())
unsorted = []
unsorted_i = 0
for unsorted_i in range(n):
	unsorted_t = str(input().strip())
	unsorted.append(unsorted_t)
print(*sorted(unsorted, key=lambda x: int(x)), sep='\n')


import sys
n = int(input().strip())
un = []
i = 0
for i in range(n):
	t = str(input().strip())
	un.append(t)
un.sort(key=int)
print('\n'.join(un))


import sys
import functools
n = int(input().strip())
unsorted = []
unsorted_i = 0
for unsorted_i in range(n):
	unsorted_t = str(input().strip())
	unsorted.append(unsorted_t)

def compareStr(str1, str2):
	if len(str1) > len(str2):
		return 1
	elif len(str1) < len(str2):
		return -1
	else:
		for i in range(0, len(str1)):
			if str1[i] > str2[i]:
				return 1
			elif str1[i] < str2[i]:
				return -1
		return 1
unsorted.sort(key=functools.cmp_to_key(compareStr))
for i in range(0, n):
	print(unsorted[i])


import sys
n = int(input().strip())
unsorted = []
unsorted_i = 0
for unsorted_i in range(n):
	unsorted_t = str(input().strip())
	unsorted.append(unsorted_t)
unsorted = sorted(unsorted)
unsorted = sorted(unsorted, key=len)
for i in unsorted:
	print(i)


import sys
n = int(input().strip())
unsorted = []
for i in range(1000001):
	unsorted.append([])
for unsorted_i in range(n):
	t = str(input().strip())
	unsorted[len(t)].append(t)
for i in unsorted:
	if len(i) != 0:
		i.sort()
		print('\n'.join((j for j in i)))


import sys
n = int(input().strip())
unsorted = []
unsorted_i = 0
d = {}
for unsorted_i in range(n):
	unsorted_t = str(input().strip())
	unsorted.append(unsorted_t)
	if d.get(len(unsorted_t), 0) != 0:
		d[len(unsorted_t)].append(unsorted_t)
	else:
		d[len(unsorted_t)] = [unsorted_t]
for i in sorted(d.keys()):
	for j in sorted(d[i]):
		print(j)


import sys
n = int(input().strip())
unsorted = []
unsorted_i = 0
for unsorted_i in range(n):
	unsorted_t = str(input().strip())
	unsorted.append(unsorted_t)

def sort_almost_custom(listToSort):
	sortedList = sorted(listToSort, key=int)
	for i in range(0, len(sortedList)):
		print(sortedList[i])
sort_almost_custom(unsorted)


import sys
n = int(input().strip())
unsorted = []
unsorted_i = 0
for unsorted_i in range(n):
	unsorted_t = str(input().strip())
	unsorted.append(unsorted_t)
unsorted.sort(key=int)
for i in unsorted:
	print(i)


import sys
n = int(input().strip())
numbers = []
for _i in range(n):
	item = str(input().strip())
	numbers.append((len(item), item))
numbers.sort()
for item in numbers:
	print(item[1])


import sys
n = int(input().strip())
unsorted = []
unsorted_i = 0
for unsorted_i in range(n):
	unsorted_t = str(input().strip())
	unsorted.append(unsorted_t)
unsorted.sort(key=int)
for val in unsorted:
	print(val)


n = input()
n = int(n)
string = []
for i in range(0, n):
	k = input()
	string.append(k)
string.sort(key=int)
for i in range(0, n):
	print(string[i])


import sys
n = int(input().strip())
unsorted = []
unsorted_i = 0
for unsorted_i in range(n):
	unsorted_t = str(input().strip())
	unsorted.append(unsorted_t)
unsorted.sort(key=int)
sort_i = 0
for sort_i in range(n):
	print(unsorted[sort_i])


import sys
import bisect
n = int(input().strip())
nums = {}
for _ in range(n):
	t = input().strip()
	size = len(t)
	if size in nums:
		bisect.insort(nums[size], t)
	else:
		nums[size] = [t]
nums = sorted(nums.items())
for (_, lst) in nums:
	print('\n'.join(lst))


import sys
n = int(input().strip())
unsorted = []
unsorted_i = 0
for unsorted_i in range(n):
	unsorted_t = str(input().strip())
	unsorted.append(unsorted_t)
sorted_arr = sorted(unsorted, key=int)
for x in sorted_arr:
	print(x)


from functools import cmp_to_key
import sys

def compare(s1, s2):
	if len(s1) < len(s2):
		return -1
	if len(s1) > len(s2):
		return 1
	for i in range(len(s1)):
		if s1[i] < s2[i]:
			return -1
		if s1[i] > s2[i]:
			return 1
	return 0
n = int(input().strip())
unsorted = []
unsorted_i = 0
for unsorted_i in range(n):
	unsorted_t = str(input().strip())
	unsorted.append(unsorted_t)
unsorted.sort(key=cmp_to_key(compare))
for val in unsorted:
	print(val)