def mergeSort(num_list, left, right):
	if left + 1 < right:
		mid = (left + right) / 2
		mergeSort(num_list, left, mid)
		mergeSort(num_list, mid, right)
		merge(num_list, left, mid, right)

def merge(num_list, left, mid, right):
	global count 
	L = list(num_list[left:mid])
	L.append(float("inf"))
	R = list(num_list[mid:right])
	R.append(float("inf"))
	i, j = 0, 0
	for k in range(left, right):
		if L[i] <= R[j]:
			num_list[k] = L[i]
			i += 1
			count += 1
		else:
			num_list[k] = R[j]
			j += 1
			count += 1

count = 0
n = int(raw_input())
a = raw_input()
l = []
l = a.split(" ")
for i in range(len(l)):
	l[i] = int(l[i])
mergeSort(l, 0, n)

print " ".join(map(str, l)) 
print count def mergeSort(num_list, left, right):
	if left + 1 < right:
		mid = (left + right) / 2
		mergeSort(num_list, left, mid)
		mergeSort(num_list, mid, right)
		merge(num_list, left, mid, right) mergeSort if left + 1 < right:
		mid = (left + right) / 2
		mergeSort(num_list, left, mid)
		mergeSort(num_list, mid, right)
		merge(num_list, left, mid, right) left + 1 < right left + 1 left 1 right mid = (left + right) / 2 mid (left + right) / 2 left + right left right 2 mergeSort(num_list, left, mid) mergeSort num_list left mid mergeSort(num_list, mid, right) mergeSort num_list mid right merge(num_list, left, mid, right) merge num_list left mid right num_list num_list left left right right def merge(num_list, left, mid, right):
	global count 
	L = list(num_list[left:mid])
	L.append(float("inf"))
	R = list(num_list[mid:right])
	R.append(float("inf"))
	i, j = 0, 0
	for k in range(left, right):
		if L[i] <= R[j]:
			num_list[k] = L[i]
			i += 1
			count += 1
		else:
			num_list[k] = R[j]
			j += 1
			count += 1 merge global count L = list(num_list[left:mid]) L list(num_list[left:mid]) list num_list[left:mid] num_list left:mid left mid L.append(float("inf")) L.append L append float("inf") float "inf" R = list(num_list[mid:right]) R list(num_list[mid:right]) list num_list[mid:right] num_list mid:right mid right R.append(float("inf")) R.append R append float("inf") float "inf" i, j = 0, 0 i 0 j 0 for k in range(left, right):
		if L[i] <= R[j]:
			num_list[k] = L[i]
			i += 1
			count += 1
		else:
			num_list[k] = R[j]
			j += 1
			count += 1 k range(left, right) range left right if L[i] <= R[j]:
			num_list[k] = L[i]
			i += 1
			count += 1
		else:
			num_list[k] = R[j]
			j += 1
			count += 1 L[i] <= R[j] L[i] L i R[j] R j num_list[k] = L[i] num_list[k] num_list k L[i] L i i += 1 i 1 count += 1 count 1 num_list[k] = R[j] num_list[k] num_list k R[j] R j j += 1 j 1 count += 1 count 1 num_list num_list left left mid mid right right count = 0 count 0 n = int(raw_input()) n int(raw_input()) int raw_input() raw_input a = raw_input() a raw_input() raw_input l = [] l [] l = a.split(" ") l a.split(" ") a.split a split " " for i in range(len(l)):
	l[i] = int(l[i]) i range(len(l)) range len(l) len l l[i] = int(l[i]) l[i] l i int(l[i]) int l[i] l i mergeSort(l, 0, n) mergeSort l 0 n print " ".join(map(str, l)) " ".join " " join map(str, l) map str l print def merge(num_list, left, mid, right):
	global count 
	L = list(num_list[left:mid])
	L.append(float("inf"))
	R = list(num_list[mid:right])
	R.append(float("inf"))
	i, j = 0, 0
	for k in range(left, right):
		if L[i] <= R[j]:
			num_list[k] = L[i]
			i += 1
			count += 1
		else:
			num_list[k] = R[j]
			j += 1
			count += 1 def merge(num_list, left, mid, right):
	global count 
	L = list(num_list[left:mid])
	L.append(float("inf"))
	R = list(num_list[mid:right])
	R.append(float("inf"))
	i, j = 0, 0
	for k in range(left, right):
		if L[i] <= R[j]:
			num_list[k] = L[i]
			i += 1
			count += 1
		else:
			num_list[k] = R[j]
			j += 1
			count += 1 merge l = a.split(" ") a.split(" ") l l = [] [] l count = 0 0 count a = raw_input() raw_input() a n = int(raw_input()) int(raw_input()) n def mergeSort(num_list, left, right):
	if left + 1 < right:
		mid = (left + right) / 2
		mergeSort(num_list, left, mid)
		mergeSort(num_list, mid, right)
		merge(num_list, left, mid, right) def mergeSort(num_list, left, right):
	if left + 1 < right:
		mid = (left + right) / 2
		mergeSort(num_list, left, mid)
		mergeSort(num_list, mid, right)
		merge(num_list, left, mid, right) mergeSort
def mergeSort(num_list, left, right):
	if left + 1 < right:
		mid = (left + right) / 2
		mergeSort(num_list, left, mid)
		mergeSort(num_list, mid, right)
		merge(num_list, left, mid, right)

def merge(num_list, left, mid, right):
	global count 
	L = list(num_list[left:mid])
	L.append(float("inf"))
	R = list(num_list[mid:right])
	R.append(float("inf"))
	i, j = 0, 0
	for k in range(left, right):
		if L[i] <= R[j]:
			num_list[k] = L[i]
			i += 1
			count += 1
		else:
			num_list[k] = R[j]
			j += 1
			count += 1

count = 0
n = int(raw_input())
a = raw_input()
l = []
l = a.split(" ")
for i in range(len(l)):
	l[i] = int(l[i])
mergeSort(l, 0, n)

print " ".join(map(str, l)) 
print count