Often, when a list is sorted, the elements being sorted are just keys to other values. For example, if you are sorting files by their size, the sizes need to stay connected to their respective files. You cannot just take the size numbers and output them in order, you need to output all the required file information.

The counting sort is used if you just need to sort a list of integers.  Rather than using a comparison, you create an integer array whose index range covers the entire range of values in your array to sort.  Each time a value occurs in the original array, you increment the counter at that index.  At the end, run through your counting array, printing the value of each non-zero valued index that number of times.

For example, consider an array $arr=[1,1,3,2,1]$.  All of the values are in the range $[0\ldots3]$, so create an array of zeroes, $result=[0,0,0,0]$.  The results of each iteration follow:

i	arr[i]	result
0	1	[0, 1, 0, 0]
1	1	[0, 2, 0, 0]
2	3	[0, 2, 0, 1]
3	2	[0, 2, 1, 1]
4	1	[0, 3, 1, 1]

Now we can print the sorted array: $sorted=[1,1,1,2,3]$.

Challenge 

Given an unsorted list of integers, use the counting sort method to sort the list and then print the sorted list. 

Hint: You can use your previous code that counted the items to print out the actual values in order.  

Function Description  

Complete the countingSort function in the editor below.  It should return the original array, sorted ascending, as an array of integers.  

countingSort has the following parameter(s):  

arr: an array of integers  

Input Format

The first line contains an integer $n$, the length of $\textbf{arr}$.
The next line contains space-separated integers $arr\left[i\right]$ where $0\leq i<n$.

Constraints

$0\leq n\leq1000000$ 

$0\leq arr[i]<100$ 

Output Format

Print the sorted list as a single line of space-separated integers. 

Sample Input
100
63 25 73 1 98 73 56 84 86 57 16 83 8 25 81 56 9 53 98 67 99 12 83 89 80 91 39 86 76 85 74 39 25 90 59 10 94 32 44 3 89 30 27 79 46 96 27 32 18 21 92 69 81 40 40 34 68 78 24 87 42 69 23 41 78 22 6 90 99 89 50 30 20 1 43 3 70 95 33 46 44 9 69 48 33 60 65 16 82 67 61 32 21 79 75 75 13 87 70 33 

Sample Output

 1 1 3 3 6 8 9 9 10 12 13 16 16 18 20 21 21 22 23 24 25 25 25 27 27 30 30 32 32 32 33 33 33 34 39 39 40 40 41 42 43 44 44 46 46 48 50 53 56 56 57 59 60 61 63 65 67 67 68 69 69 69 70 70 73 73 74 75 75 76 78 78 79 79 80 81 81 82 83 83 84 85 86 86 87 87 89 89 89 90 90 91 92 94 95 96 98 98 99 99 

Explanation

Once our counting array has been filled, loop from index $\mbox{o}$ to the end, printing each $\boldsymbol{i}$ value $arr\left[i\right]$ times.

Source: hackerrank | Difficulty: EASY
Tags: Sorting


Solutions:
n = int(input())
ar = [int(x) for x in input().strip().split(' ')]
c = [0] * 100
for a in ar:
	c[a] += 1
s = ''
for x in range(0, 100):
	for i in range(0, c[x]):
		s += ' ' + str(x)
print(s[1:])


import sys
n = int(sys.stdin.readline())
ar = [int(x) for x in sys.stdin.readline().split()]
counter = {}
for a in ar:
	counter[a] = counter.get(a, 0) + 1
values = []
for num in range(0, 100):
	values.extend([str(num)] * counter.get(num, 0))
print(' '.join(values))


def main():
	size = input()
	arr_str = input()
	arr = list(map(int, arr_str.split()))
	count = [0] * 100
	for item in arr:
		count[item] += 1
	for i in range(0, len(count)):
		for j in range(0, count[i]):
			print(i, end=' ')
main()


n = int(input())
counts = {i: 0 for i in range(100)}
vals = [int(i) for i in input().split()]
for i in range(n):
	counts[vals[i]] += 1
for i in range(100):
	if counts[i] == 0:
		continue
	for j in range(counts[i]):
		print(i, end=' ')
print()


def countSort(ar):
	ar.sort()
	(dico, lst) = ({k: ar.count(k) for k in range(100)}, [])
	for i in dico.keys():
		count = dico[i]
		while count != 0:
			lst.append(i)
			count -= 1
	return lst
n = input()
ar = [int(i) for i in input().strip().split()]
for i in countSort(ar):
	print(i, end=' ')


output = dict()
n = int(input())
args = [int(elt) for elt in input().split()]
for elt in args:
	try:
		output[elt] += 1
	except KeyError:
		output[elt] = 1
for i in range(100):
	try:
		reps = output[i]
		for j in range(reps):
			print(i, end=' ')
	except KeyError:
		pass


size = input()
data = [int(x) for x in input().strip().split(' ')]
a = [0 for i in range(100)]
for i in data:
	a[i] += 1
result = []
for i in range(len(a)):
	for j in range(a[i]):
		result.append(i)
print(' '.join([str(x) for x in result]))


n = int(input())
ar = [int(i) for i in input().strip().split()]
x = [0 for i in range(100)]
for e in ar:
	x[e] += 1
for (i, e) in enumerate(x):
	for _ in range(e):
		print(i, end=' ')


n = int(input())
l = list(map(int, input().split()))
l.sort()
for i in l:
	print(i, end=' ')


n = int(input())
ar = [int(x) for x in input().split()]
counts = [0] * 100
for x in ar:
	counts[x] += 1
res = []
for (i, count) in enumerate(counts):
	if count:
		res += [i] * count
print(' '.join(map(str, res)))


input()
count = [0] * 100
for n in map(int, input().split()):
	count[n] += 1
print(''.join([''.join([str(i) + ' '] * count[i]) for i in range(100)]).rstrip())


d = {}
for i in range(100):
	d[i] = 0
n = input('')
s = input('')
s = s.split(' ')
for i in s:
	if i == '':
		break
	x = int(i)
	d[x] += 1
for i in d:
	while d[i] > 0:
		print(i, end=' ')
		d[i] -= 1
print()


count = [0] * 100
valid = [str(n) for n in range(100)]
n = int(input())
for k in input().split(' '):
	if k in valid:
		m = int(k)
		count[m] = count[m] + 1
res = ''
n = 0
while n != 100:
	if count[n] == 0:
		n += 1
	else:
		count[n] = count[n] - 1
		res = res + str(n) + ' '
print(res[:-1])


SIZE = 100

def count_sort(L, size):
	count = [0] * size
	out = []
	for i in L:
		count[i] += 1
	for i in range(size):
		out.extend([i] * count[i])
	return out
n = int(input())
L = [int(s) for s in input().split()]
print(' '.join([str(i) for i in count_sort(L, SIZE)]))


def h():
	x = str(input())
	y = x.split()
	l = len(y)
	z = []
	for i in y:
		z.append(int(i))
	return z

def listtostr(l):
	x = str(l[0])
	for i in range(1, len(l)):
		x = x + ' ' + str(l[i])
	return x
n = int(input())
z = h()
z.sort()
print(listtostr(z))


n = int(input())
ar = list(map(int, input().split()))
tot = [0] * 100
prnt = []
for j in range(0, n):
	temp = ar[j]
	tot[temp] += 1
for i in range(0, 100):
	while tot[i] > 0:
		prnt.append(i)
		tot[i] -= 1
print(*prnt, sep=' ')


import sys

def print_list(data):
	for element in data:
		print(element, end=' ')
	print()
sizeOfList = int(sys.stdin.readline())
data = []
raw = sys.stdin.readline().split()
for index in range(sizeOfList):
	data.append(int(raw[index]))
counter = [0] * 100
for element in data:
	counter[element] += 1
for index in range(1, len(counter)):
	counter[index] = counter[index] + counter[index - 1]
result = [0] * len(data)
for element in data:
	result[counter[element] - 1] = element
	counter[element] -= 1
print_list(result)


n = int(input())
ar = map(int, input().split())
counts = 100 * [0]
for x in ar:
	counts[x] += 1
for i in range(100):
	for j in range(counts[i]):
		print(i, end=' ')
print()


n = int(input())
ar = [int(v) for v in input().split()]
count = [0] * 100
for item in ar:
	count[item] += 1
for i in range(100):
	if count[i] > 0:
		print(' '.join([str(i)] * count[i]), end=' ')


size = int(input())
print(str(sorted(list(map(int, input().split())))).replace('[', '').replace(',', '').replace(']', ''))


import sys

def mToString(mArray):
	startStr = ''
	for el in mArray:
		startStr = startStr + str(el) + ' '
	if len(startStr) == 0:
		startStr = ' '
	return startStr[:-1]
lines = []
for line in sys.stdin:
	lines.append(line)
n = int(lines[0])
inputArray = list(map(int, lines[1].split()))
countArray = [0] * 100
for el in inputArray:
	countArray[el] = countArray[el] + 1
outputArray = []
for i in range(100):
	outputArray = outputArray + [i] * countArray[i]
print(mToString(outputArray))


x = input()
y = input().split()
y = [int(i) for i in y]
y.sort()
y = [str(i) for i in y]
print(' '.join(y))


import fileinput

def main():
	lines = []
	for line in fileinput.input():
		lines.append(line)
	numbers = list(map(int, str(lines[1]).split()))
	numbers.sort()
	printout = ''
	for number in numbers:
		printout += str(number) + ' '
	print(printout)
main()


n = int(input())
ar = list(map(int, str(input()).split()))
counts = [0 for i in range(100)]
for i in range(n):
	counts[ar[i]] += 1
ar = []
for (i, c) in enumerate(counts):
	ar += [i] * c
print(' '.join(map(str, ar)))


num = int(input())
A = [0] * 100
ar = [int(c) for c in input().split()]
for i in ar:
	A[i] += 1
for j in range(0, 100):
	if A[j] > 0:
		for k in range(0, A[j]):
			print(j, end=' ')


size = int(input())
assert 100 <= size <= 1000000
numbers = [int(x) for x in input().split()]
counters = {}
counts = ''
for x in range(0, 100):
	counters[x] = 0
for e in numbers:
	counters[e] += 1
for y in counters:
	counts += (str(y) + ' ') * counters[y]
print(counts.strip())


import random
n = int(input())
ar = [int(x) for x in input().split()]

def countsort(ar):
	counts = [0] * 100
	for x in ar:
		counts[x] += 1
	return counts
res = countsort(ar)

def inorder(array):
	lst = []
	for i in range(len(array)):
		for x in range(array[i]):
			lst.append(i)
	return lst
finals = inorder(res)
print(' '.join(map(str, finals)))


from collections import Counter
input()
cc = Counter([int(x) for x in input().split()])
sk = list(dict(cc).keys())
sk.sort()
for k in sk:
	for i in range(cc[k]):
		print(k, end=' ')


import sys

def counting(arr, s):
	appearences = {}
	for x in range(100):
		appearences[x] = 0
	for value in arr:
		appearences[value] += 1
	result = []
	for x in range(100):
		if appearences[x] != 0:
			for a in range(appearences[x]):
				result.append(x)
	return result
size = int(sys.stdin.readline().strip())
array = sys.stdin.readline().strip().split()
array = [int(i) for i in array]
print(' '.join([str(i) for i in counting(array, len(array))]))


import sys
N = int(sys.stdin.readline())
occ = [0] * 100
for line in sys.stdin:
	for i in line.split():
		occ[int(i)] += 1
for i in range(len(occ)):
	for z in range(occ[i]):
		print(i, end=' ')


from collections import defaultdict
input()
ar = [int(i) for i in input().split()]

def csort(ar):
	hist = defaultdict(int)
	for i in ar:
		hist[i] += 1
	sar = []
	for k in hist:
		sar.extend([k] * hist[k])
	return sar
print(' '.join((str(i) for i in csort(ar))))


T = int(input())
array = input().split()
output = []
for i in range(T):
	output.append(int(array[i]))
output.sort()
print(' '.join((str(x) for x in output)))


n = int(input())
ar = [int(i) for i in str(input()).split()]
freq = [0] * 100
for i in ar:
	freq[i] += 1
ans = []
for (i, f) in enumerate(freq):
	ans += [str(i)] * f
print(' '.join(ans))


N = int(input())
arr = input().split()
count = dict()
for i in arr:
	if i in count:
		count[i] += 1
	else:
		count[i] = 1
out = ''
for i in range(N):
	if str(i) in count:
		for j in range(int(count[str(i)])):
			out += str(i) + ' '
print(out)


import sys, math, copy
data = sys.stdin.readlines()
a = [int(n) for n in data[1].split()]
o = []
for n in range(max(a) + 1):
	c = a.count(n)
	for i in range(c):
		o.append(n)
print(' '.join([str(k) for k in o]))


N = int(input())
array = list(map(int, input().split()))
counts = [0] * 100
for elem in array:
	counts[elem] += 1
total = 0
for i in range(100):
	(total, counts[i]) = (total + counts[i], total)
sorted_array = [0] * N
for elem in array:
	index = counts[elem]
	sorted_array[index] = elem
	counts[elem] += 1
print(*sorted_array)


counts = dict()
n = int(input())
ar = [int(x) for x in input().split()]
for num in ar:
	counts[num] = counts.get(num, 0) + 1
out = []
for i in range(100):
	for j in range(counts.get(i, 0)):
		out.append(str(i))
print(' '.join(out))


N = int(input())
print(' '.join([str(x) for x in sorted([int(x) for x in input().split()])]))


N = int(input())
int_list = [int(x) for x in input().split()]
freq_list = [0 for x in range(100)]
for i in range(N):
	freq_list[int_list[i]] += 1
printstr = ''
for i in range(100):
	printstr += (str(i) + ' ') * freq_list[i]
print(printstr)


def count_sort(ar):
	a = [0] * 100
	for x in ar:
		a[x] += 1
	s = ''
	for y in range(0, len(a)):
		for z in range(0, a[y]):
			s += str(y) + ' '
	print(s)
m = int(input().strip())
ar = [int(i) for i in input().strip().split()]
count_sort(ar)


int(input())
allInput = input()
allInput = [int(n) for n in allInput.split()]
allInput.sort()
s = ''
for i in allInput:
	s += str(i) + ' '
print(s)


N = int(input())
input_map = list(map(int, input().split()))
counter = [0] * 100
for element in input_map:
	counter[element] += 1
output = ''
i = 0
while i < 100:
	key = counter[i]
	for j in range(key):
		output = output + str(i) + ' '
	i = i + 1
print(output)


counter = [int(0) for i in range(100)]
N = int(input())
ar = [int(x) for x in input().split()]
for v in ar:
	counter[v] += 1
print(''.join(' '.join((str(x) for x in range(len(counter)) for _ in range(counter[x])))))


from sys import stdin

def main():
	stdin.readline()
	numbers = list(map(int, stdin.readline().split()))
	frequencies = {}
	for i in numbers:
		if i in frequencies:
			frequencies[i] += 1
		else:
			frequencies[i] = 1
	for i in range(100):
		if i not in frequencies:
			frequencies[i] = 0
		for j in range(frequencies[i]):
			print(i, end=' ')
main()


count = input()
nums = list(map(int, input().split()))

def sort(arr):
	less = []
	equal = []
	greater = []
	if len(arr) > 1:
		pivot = arr[0]
		for i in range(len(arr)):
			if arr[i] > pivot:
				greater.append(arr[i])
			elif arr[i] < pivot:
				less.append(arr[i])
			else:
				equal.append(arr[i])
		return sort(less) + equal + sort(greater)
	else:
		return arr
s = sort(nums)
for i in range(len(s)):
	print(s[i], end=' ')


counters = [0 for x in range(100)]
n = int(input())
inp = input().split(' ')
for i in range(n):
	index = int(inp[i])
	counters[index] = counters[index] + 1
sorted = []
for i in range(100):
	count = counters[i]
	for j in range(count):
		sorted.append(i)
print(' '.join((str(x) for x in sorted)))


n = int(input())
c = [0 for i in range(100)]
l = 0
a = []
while l < n:
	a += input().split()
	l = len(a)
for i in a:
	c[int(i)] += 1
ans = ''
for j in range(len(c)):
	ans += c[j] * (str(j) + ' ')
print(ans)


def counting_sort(a):
	count = [0] * 100
	for x in a:
		count[x] += 1
	a.clear()
	for i in range(len(count)):
		a += [i] * count[i]
	return a
n = int(input())
a = [int(x) for x in str(input()).split()]
counting_sort(a)
print(' '.join([str(x) for x in a]))


input()
nums = [int(x) for x in input().split()]
count = [0] * 100
for i in nums:
	count[i] += 1
for i in range(len(count)):
	for j in range(count[i]):
		print(i, end=' ')


n = int(input())
seq = input().split()
seq = sorted([int(num) for num in seq])
for num in seq:
	print(num, end=' ')


k = 100
n = int(input())
data = list(map(int, input().split()))
count = [0 for _ in range(k)]
output = [0 for _ in range(n)]
for x in data:
	count[x] += 1
total = 0
for i in range(k):
	old_count = count[i]
	count[i] = total
	total += old_count
for x in data:
	output[count[x]] = x
	count[x] += 1
print(' '.join(map(str, output)))


l = int(input())
a = list(input())
b = []
for x in range(0, l):
	b.append('')
index = 0
for x in range(0, len(a)):
	if a[x] != ' ':
		b[index] += a[x]
	if a[x] == ' ':
		index += 1
for x in range(0, len(b)):
	b[x] = int(b[x])
ans = [0] * 100
for x in range(l):
	ans[b[x]] += 1
ansx = []
for x in range(100):
	for y in range(ans[x]):
		ansx.append(x)
print(' '.join(map(str, ansx)))


n = int(input())
ar = list(map(int, input().split()))
c = [0] * 100
for e in ar:
	c[e] += 1
for i in range(len(c)):
	if c[i] > 0:
		print(' '.join([str(i)] * c[i]), end=' ')


from collections import defaultdict
n = int(input())
nbs = [int(i) for i in input().split()]
freq = defaultdict(lambda : 0)
for nb in nbs:
	freq[nb] += 1
ret = []
for i in range(max(nbs) + 1):
	for _ in range(freq[i]):
		ret.append(str(i))
print(' '.join(ret))


n = int(input())
arr = [int(x) for x in input().split()]
arr.sort()
print(' '.join([str(x) for x in arr]))


def makelistsameline(strnos):
	return list(map(lambda x: int(x), strnos.split()))

def pp(L):
	print(' '.join(map(str, L)))
N = int(input())
ar = makelistsameline(input())
count = dict.fromkeys(range(100), 0)
for x in ar:
	count[x] += 1
ordered = []
for (no, times) in tuple(count.items()):
	ordered.extend([no] * times)
pp(ordered)


n = int(input())
numberList = [int(x) for x in input().split()]
counts = [0 for _ in range(100)]
for num in numberList:
	counts[num] += 1
for (i, count) in enumerate(counts):
	if count != 0:
		for _ in range(count):
			print(i, end=' ')
print()


from sys import stdin

def count(arr):
	counts = [0] * 100
	for x in arr:
		counts[x] += 1
	return counts

def counting_sort(arr):
	result = []
	for (i, c) in enumerate(count(arr)):
		for j in range(c):
			result.append(i)
	return result
n = int(stdin.readline())
arr = [int(x) for x in stdin.readline().split()]
print(' '.join([str(x) for x in counting_sort(arr)]))


intlist = [0 for i in range(100)]
n = eval(input())
l = list(map(int, input().split()))
for i in l:
	intlist[i] += 1
printlist = []
for i in range(100):
	for j in range(intlist[i]):
		printlist.append(i)
print(' '.join(map(str, printlist)))


def sort(l):
	h = {}
	mx = float('-inf')
	for i in l:
		h[i] = h.get(i, 0) + 1
		if i > mx:
			mx = i
	for i in range(mx + 1):
		if i in h:
			print(' '.join([str(i)] * h[i]), end=' ')
	print('')
n = int(input())
l = [int(x) for x in input().strip().split()]
assert n == len(l)
sort(l)


amount = int(input())
nums = str(input()).split(' ')
count = []
for x in range(0, 100):
	count.append(str(nums.count(str(x))))
index = 0
s = []
for num in count:
	for i in range(int(num)):
		s.append(str(index))
	index += 1
print(' '.join(s))


n = int(input())
ar = [int(x) for x in input().split()]
freq = [0] * n
for x in ar:
	freq[x] += 1
answer = ''
for i in range(n):
	count = freq[i]
	while count > 0:
		answer += '%d ' % i
		count -= 1
print(answer[:-1])


n = int(input())
lst = [int(t) for t in input().strip().split(' ')]
maxVal = max(lst)
cnt = [0] * (maxVal + 1)
for i in lst:
	cnt[i] += 1
for a in range(len(cnt)):
	for c in range(cnt[a]):
		print(a, end=' ')
print()


nombreEntrees = int(input())
ar = [int(i) for i in input().strip().split()]
tableauCompte = [0] * 100
for el in ar:
	tableauCompte[el] += 1
reponse = ''
for i in range(len(tableauCompte)):
	if tableauCompte[i] != 0:
		reponse += (str(i) + ' ') * tableauCompte[i]
print(reponse.rstrip())


size = int(input().strip())
counts = {}
for i in range(100):
	counts[i] = 0
for number in input().strip().split():
	num = int(number)
	counts[num] = counts[num] + 1
countsArr = []
for i in range(100):
	for j in range(counts[i]):
		countsArr.append(str(i))
print(' '.join(countsArr))


n = int(input())
arr = [int(i) for i in str(input()).split()]
output_arr = [0] * 100
ordered_arr = []
for value in arr:
	output_arr[value] += 1
for i in range(100):
	for j in range(output_arr[i]):
		ordered_arr.append(i)
print(' '.join(map(str, ordered_arr)))


N = int(input())
ar = [int(i) for i in input().split()]
res = [0] * 100
for val in ar:
	res[val] += 1
print(' '.join([' '.join([str(i)] * val) for (i, val) in enumerate(res) if val > 0]))


(n, ar) = (int(input()), map(int, input().split()))
counts = [''] * 100
for x in ar:
	counts[x] += str(x) + ' '
print(''.join(counts))


def counting_sort(array):
	res_array = [0 for i in range(100)]
	for a in array:
		res_array[a] += 1
	for i in range(len(res_array)):
		for j in range(res_array[i]):
			print(i, '', end='')
N = int(input())
array = [int(i) for i in input().strip().split()]
counting_sort(array)


N = int(input())
ar = list(map(int, input().split()))
ar.sort()
for num in ar:
	print(num, end=' ')


def count(lst):
	out = [0 for _ in range(100)]
	for el in lst:
		out[el] += 1
	return out

def out(lst):
	sorted_lst = []
	for (i, c) in enumerate(lst):
		if c != 0:
			sorted_lst.extend((i for _ in range(c)))
	return sorted_lst
n = int(input())
strlst = input()
cc = count([int(el) for el in strlst.split()])
result = out(cc)
print(' '.join((str(c) for c in result)))


n = int(input().strip())
ar = [int(i) for i in input().strip().split(' ')]
freq = [0 for i in range(100)]
for i in ar:
	freq[i] += 1
s = ''
for i in range(100):
	for j in range(freq[i]):
		s = s + str(i) + ' '
print(s)


input()
print(' '.join([str(i) for i in sorted([int(j) for j in input().split()])]))


t = int(input())
l = []
l.append(input())
res = []
res = l[0].split()
for x in range(t):
	res[x] = int(res[x])
res.sort()
for x in range(t):
	print(res[x], end=' ')


n = int(input())
m = 100
A = [int(s) for s in input().split()]
B = [0] * m
for i in range(n):
	B[A[i]] += 1
C = []
for i in range(m):
	C += [i] * B[i]
print(' '.join(map(str, C)))


input()
a = map(int, input().split())
print(*sorted(a))


DEV = False
if DEV:
	f = open('test_data.txt', 'r')
	ra_len = int(f.readline().strip())
	ra = [int(i) for i in f.readline().strip().split()]
else:
	ra_len = int(input().strip())
	ra = [int(i) for i in input().strip().split()]
counts = []
for num in range(0, 100, 1):
	counts.append(0)
for num in ra:
	counts[num] += 1
result = ''
for num in range(0, 100, 1):
	for repeats in range(0, counts[num]):
		result += '{0} '.format(num)
print(result)
if DEV:
	f.close()


input()
X = [0] * 100
for i in map(int, input().split()):
	X[i] += 1
for i in range(100):
	for j in range(X[i]):
		print(i, end=' ')


n = int(input())
ar = [int(number) for number in input().split()]
count = [0] * 100
for number in ar:
	count[number] += 1
for (i, j) in enumerate(count):
	for _ in range(j):
		print(i, end=' ')


cnt = [0 for i in range(101)]
n = int(input())
l = map(int, input().split())
for i in l:
	cnt[i] += 1
for i in range(100):
	for j in range(cnt[i]):
		print(i, end=' ')


size = int(input())
tmp = input()
li = tmp.split()
for i in range(0, size):
	li[i] = int(li[i])
li.sort()
for i in range(0, size):
	li[i] = str(li[i])
print(' '.join(li))


n = int(input())
arr = [int(x) for x in input().split()]

def countingSort(A, k):
	B = [-1 for x in range(len(A))]
	C = [0 for x in range(k)]
	for i in range(len(A)):
		C[A[i]] += 1
	for i in range(1, k):
		C[i] += C[i - 1]
	for i in range(len(A) - 1, -1, -1):
		B[C[A[i]] - 1] = A[i]
		C[A[i]] -= 1
	return B
sortedArr = countingSort(arr, 100)
print(' '.join(map(str, sortedArr)))


n = int(input())
ar = [int(i) for i in str(input()).split()]
count = [0] * 100
for i in ar:
	count[i] += 1
result = []
for (j, k) in enumerate(count):
	result += [str(j)] * k
print(' '.join(result))


from collections import defaultdict
arraySize = input()
array = [int(x) for x in input().split()]
occurrences = defaultdict(lambda : 0)
for element in array:
	occurrences[element] += 1
for x in range(100):
	if occurrences[x] != 0:
		print((str(x) + ' ') * occurrences[x], end='')


N = int(input().strip())
ar = [int(x) for x in input().strip().split()]
count = [0] * 100
for element in ar:
	count[element] += 1
sort = []
for i in range(len(count)):
	for j in range(count[i]):
		sort.append(i)
print(' '.join([str(x) for x in sort]))


n = input()
numbers = list(map(int, input().split()))
n_sorted = sorted(numbers)
print(' '.join(map(str, n_sorted)))


n = int(input())
numbers = [int(i) for i in input().split()]
arr = [0 for i in range(100)]
output = [0 for i in range(len(numbers))]
for i in range(n):
	arr[numbers[i]] += 1
for j in range(1, 100):
	arr[j] += arr[j - 1]
for k in range(n - 1, -1, -1):
	output[arr[numbers[k]] - 1] = numbers[k]
	arr[numbers[k]] -= 1
print(' '.join([str(i) for i in output]))