import sys

def merge(A, left, mid, right, num_compare):
	n1 = mid - left
	n2 = right - mid

	L = A[left:mid] + [SENTINEL]
	R = A[mid:right] + [SENTINEL]
	
	i = 0
	j = 0

	num_compare += right - left
	for k in range(left, right):
		if L[i] <= R[j]:
			A[k] = L[i]
			i += 1
		else:
			A[k] = R[j]
			j += 1
	return num_compare

def merge_sort(A, left, right, num_compare):
	if left + 1 < right:
		mid = (left + right) // 2
		num_compare = merge_sort(A, left, mid, num_compare)
		num_compare = merge_sort(A, mid, right, num_compare)
		num_compare = merge(A, left, mid, right, num_compare)

	return num_compare


#fin = open("test.txt", "r")
fin = sys.stdin

SENTINEL = float("inf")

n = int(fin.readline())
S = list(map(int, fin.readline().split()))

num_compare = 0
num_compare = merge_sort(S, 0, n, num_compare)

print(S[0], end = "")
for s in S[1:]:
	print(" " + str(s), end = "")
print("") 
print(num_compare) import sys sys def merge(A, left, mid, right, num_compare):
	n1 = mid - left
	n2 = right - mid

	L = A[left:mid] + [SENTINEL]
	R = A[mid:right] + [SENTINEL]
	
	i = 0
	j = 0

	num_compare += right - left
	for k in range(left, right):
		if L[i] <= R[j]:
			A[k] = L[i]
			i += 1
		else:
			A[k] = R[j]
			j += 1
	return num_compare merge n1 = mid - left n1 mid - left mid left n2 = right - mid n2 right - mid right mid L = A[left:mid] + [SENTINEL] L A[left:mid] + [SENTINEL] A[left:mid] A left:mid left mid [SENTINEL] SENTINEL R = A[mid:right] + [SENTINEL] R A[mid:right] + [SENTINEL] A[mid:right] A mid:right mid right [SENTINEL] SENTINEL i = 0 i 0 j = 0 j 0 num_compare += right - left num_compare right - left right left for k in range(left, right):
		if L[i] <= R[j]:
			A[k] = L[i]
			i += 1
		else:
			A[k] = R[j]
			j += 1
	 k range(left, right) range left right if L[i] <= R[j]:
			A[k] = L[i]
			i += 1
		else:
			A[k] = R[j]
			j += 1
	 L[i] <= R[j] L[i] L i R[j] R j A[k] = L[i] A[k] A k L[i] L i i += 1 i 1 A[k] = R[j] A[k] A k R[j] R j j += 1 j 1 return num_compare num_compare A A left left mid mid right right num_compare num_compare def merge_sort(A, left, right, num_compare):
	if left + 1 < right:
		mid = (left + right) // 2
		num_compare = merge_sort(A, left, mid, num_compare)
		num_compare = merge_sort(A, mid, right, num_compare)
		num_compare = merge(A, left, mid, right, num_compare)

	return num_compare


#fin = open("test.txt", "r") merge_sort if left + 1 < right:
		mid = (left + right) // 2
		num_compare = merge_sort(A, left, mid, num_compare)
		num_compare = merge_sort(A, mid, right, num_compare)
		num_compare = merge(A, left, mid, right, num_compare)

	 left + 1 < right left + 1 left 1 right mid = (left + right) // 2 mid (left + right) // 2 left + right left right 2 num_compare = merge_sort(A, left, mid, num_compare) num_compare merge_sort(A, left, mid, num_compare) merge_sort A left mid num_compare num_compare = merge_sort(A, mid, right, num_compare) num_compare merge_sort(A, mid, right, num_compare) merge_sort A mid right num_compare num_compare = merge(A, left, mid, right, num_compare) num_compare merge(A, left, mid, right, num_compare) merge A left mid right num_compare return num_compare num_compare A A left left right right num_compare num_compare fin = sys.stdin fin sys.stdin sys stdin SENTINEL = float("inf") SENTINEL float("inf") float "inf" n = int(fin.readline()) n int(fin.readline()) int fin.readline() fin.readline fin readline S = list(map(int, fin.readline().split())) S list(map(int, fin.readline().split())) list map(int, fin.readline().split()) map int fin.readline().split() fin.readline().split fin.readline() fin.readline fin readline split num_compare = 0 num_compare 0 num_compare = merge_sort(S, 0, n, num_compare) num_compare merge_sort(S, 0, n, num_compare) merge_sort S 0 n num_compare print(S[0], end = "") print S[0] S 0 end = "" end "" for s in S[1:]:
	print(" " + str(s), end = "") s S[1:] S 1: 1 print(" " + str(s), end = "") print " " + str(s) " " str(s) str s end = "" end "" print("") print "" print(num_compare) print num_compare SENTINEL = float("inf") float("inf") SENTINEL def merge(A, left, mid, right, num_compare):
	n1 = mid - left
	n2 = right - mid

	L = A[left:mid] + [SENTINEL]
	R = A[mid:right] + [SENTINEL]
	
	i = 0
	j = 0

	num_compare += right - left
	for k in range(left, right):
		if L[i] <= R[j]:
			A[k] = L[i]
			i += 1
		else:
			A[k] = R[j]
			j += 1
	return num_compare def merge(A, left, mid, right, num_compare):
	n1 = mid - left
	n2 = right - mid

	L = A[left:mid] + [SENTINEL]
	R = A[mid:right] + [SENTINEL]
	
	i = 0
	j = 0

	num_compare += right - left
	for k in range(left, right):
		if L[i] <= R[j]:
			A[k] = L[i]
			i += 1
		else:
			A[k] = R[j]
			j += 1
	return num_compare merge fin = sys.stdin sys.stdin fin num_compare = 0 0 num_compare def merge_sort(A, left, right, num_compare):
	if left + 1 < right:
		mid = (left + right) // 2
		num_compare = merge_sort(A, left, mid, num_compare)
		num_compare = merge_sort(A, mid, right, num_compare)
		num_compare = merge(A, left, mid, right, num_compare)

	return num_compare


#fin = open("test.txt", "r") def merge_sort(A, left, right, num_compare):
	if left + 1 < right:
		mid = (left + right) // 2
		num_compare = merge_sort(A, left, mid, num_compare)
		num_compare = merge_sort(A, mid, right, num_compare)
		num_compare = merge(A, left, mid, right, num_compare)

	return num_compare


#fin = open("test.txt", "r") merge_sort num_compare = merge_sort(S, 0, n, num_compare) merge_sort(S, 0, n, num_compare) num_compare n = int(fin.readline()) int(fin.readline()) n S = list(map(int, fin.readline().split())) list(map(int, fin.readline().split())) S
import sys

def merge(A, left, mid, right, num_compare):
	n1 = mid - left
	n2 = right - mid

	L = A[left:mid] + [SENTINEL]
	R = A[mid:right] + [SENTINEL]
	
	i = 0
	j = 0

	num_compare += right - left
	for k in range(left, right):
		if L[i] <= R[j]:
			A[k] = L[i]
			i += 1
		else:
			A[k] = R[j]
			j += 1
	return num_compare

def merge_sort(A, left, right, num_compare):
	if left + 1 < right:
		mid = (left + right) // 2
		num_compare = merge_sort(A, left, mid, num_compare)
		num_compare = merge_sort(A, mid, right, num_compare)
		num_compare = merge(A, left, mid, right, num_compare)

	return num_compare


#fin = open("test.txt", "r")
fin = sys.stdin

SENTINEL = float("inf")

n = int(fin.readline())
S = list(map(int, fin.readline().split()))

num_compare = 0
num_compare = merge_sort(S, 0, n, num_compare)

print(S[0], end = "")
for s in S[1:]:
	print(" " + str(s), end = "")
print("") 
print(num_compare)