A = []
ans = 0

def merge(left, mid, right):
	global A
	global ans
	n1 = mid - left
	n2 = right - mid
	l = []
	r = []
	for i in range(n1):
		l += [A[left + i]]
	for i in range(n2):
		r += [A[mid + i]]
	l += [10**18]
	r += [10**18]
	i = 0
	j = 0
	ans += 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


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

def main():
	global ans
	global A
	n = int(input())
	A = list(map(int,input().split()))
	Msort(0,n)
	print(" ".join(list(map(str,A))))
	print(ans)

main() A = [] A [] ans = 0 ans 0 def merge(left, mid, right):
	global A
	global ans
	n1 = mid - left
	n2 = right - mid
	l = []
	r = []
	for i in range(n1):
		l += [A[left + i]]
	for i in range(n2):
		r += [A[mid + i]]
	l += [10**18]
	r += [10**18]
	i = 0
	j = 0
	ans += 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 merge global A global ans n1 = mid - left n1 mid - left mid left n2 = right - mid n2 right - mid right mid l = [] l [] r = [] r [] for i in range(n1):
		l += [A[left + i]]
	 i range(n1) range n1 l += [A[left + i]] l [A[left + i]] A[left + i] A left + i left i for i in range(n2):
		r += [A[mid + i]]
	 i range(n2) range n2 r += [A[mid + i]] r [A[mid + i]] A[mid + i] A mid + i mid i l += [10**18] l [10**18] 10**18 10 18 r += [10**18] r [10**18] 10**18 10 18 i = 0 i 0 j = 0 j 0 ans += right - left ans 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 left left mid mid right right def Msort(left, right):
	if left + 1 < right:
		mid = int((left + right)/2)
		Msort(left, mid)
		Msort(mid,right)
		merge(left,mid,right) Msort if left + 1 < right:
		mid = int((left + right)/2)
		Msort(left, mid)
		Msort(mid,right)
		merge(left,mid,right) left + 1 < right left + 1 left 1 right mid = int((left + right)/2) mid int((left + right)/2) int (left + right)/2 left + right left right 2 Msort(left, mid) Msort left mid Msort(mid,right) Msort mid right merge(left,mid,right) merge left mid right left left right right def main():
	global ans
	global A
	n = int(input())
	A = list(map(int,input().split()))
	Msort(0,n)
	print(" ".join(list(map(str,A))))
	print(ans) main global ans global A n = int(input()) n int(input()) int input() input A = list(map(int,input().split())) A list(map(int,input().split())) list map(int,input().split()) map int input().split() ().split () input split Msort(0,n) Msort 0 n print(" ".join(list(map(str,A)))) print " ".join(list(map(str,A))) " ".join " " join list(map(str,A)) list map(str,A) map str A print(ans) print ans main() main ans = 0 0 ans A = [] [] A def Msort(left, right):
	if left + 1 < right:
		mid = int((left + right)/2)
		Msort(left, mid)
		Msort(mid,right)
		merge(left,mid,right) def Msort(left, right):
	if left + 1 < right:
		mid = int((left + right)/2)
		Msort(left, mid)
		Msort(mid,right)
		merge(left,mid,right) Msort def merge(left, mid, right):
	global A
	global ans
	n1 = mid - left
	n2 = right - mid
	l = []
	r = []
	for i in range(n1):
		l += [A[left + i]]
	for i in range(n2):
		r += [A[mid + i]]
	l += [10**18]
	r += [10**18]
	i = 0
	j = 0
	ans += 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 def merge(left, mid, right):
	global A
	global ans
	n1 = mid - left
	n2 = right - mid
	l = []
	r = []
	for i in range(n1):
		l += [A[left + i]]
	for i in range(n2):
		r += [A[mid + i]]
	l += [10**18]
	r += [10**18]
	i = 0
	j = 0
	ans += 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 merge def main():
	global ans
	global A
	n = int(input())
	A = list(map(int,input().split()))
	Msort(0,n)
	print(" ".join(list(map(str,A))))
	print(ans) def main():
	global ans
	global A
	n = int(input())
	A = list(map(int,input().split()))
	Msort(0,n)
	print(" ".join(list(map(str,A))))
	print(ans) main
A = []
ans = 0

def merge(left, mid, right):
	global A
	global ans
	n1 = mid - left
	n2 = right - mid
	l = []
	r = []
	for i in range(n1):
		l += [A[left + i]]
	for i in range(n2):
		r += [A[mid + i]]
	l += [10**18]
	r += [10**18]
	i = 0
	j = 0
	ans += 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


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

def main():
	global ans
	global A
	n = int(input())
	A = list(map(int,input().split()))
	Msort(0,n)
	print(" ".join(list(map(str,A))))
	print(ans)

main()
