def merge(A,left,mid,right):
	L=A[left:mid]+[10**9]
	R=A[mid:right]+[10**9]
	i = 0
	j = 0
	c = 0
	for k in range(left,right):
		c += 1
		if L[i] <= R[j]:
			A[k] = L[i]
			i+=1
		else:
			A[k] = R[j]
			j+=1
	return c

def merge_sort(A,left,right):
	if left+1 < right:
		mid = (left+right) // 2
		cL=merge_sort(A,left,mid)
		cR=merge_sort(A,mid,right)
		return(merge(A,left,mid,right) + cL + cR)
	return 0

c=0
n = int(input())
A = [int(i) for i in input().split()]
c=merge_sort(A,0,n)
print(*A)
print(c) def merge(A,left,mid,right):
	L=A[left:mid]+[10**9]
	R=A[mid:right]+[10**9]
	i = 0
	j = 0
	c = 0
	for k in range(left,right):
		c += 1
		if L[i] <= R[j]:
			A[k] = L[i]
			i+=1
		else:
			A[k] = R[j]
			j+=1
	return c merge L=A[left:mid]+[10**9] L A[left:mid]+[10**9] A[left:mid] A left:mid left mid [10**9] 10**9 10 9 R=A[mid:right]+[10**9] R A[mid:right]+[10**9] A[mid:right] A mid:right mid right [10**9] 10**9 10 9 i = 0 i 0 j = 0 j 0 c = 0 c 0 for k in range(left,right):
		c += 1
		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 c += 1 c 1 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 c c A A left left mid mid right right def merge_sort(A,left,right):
	if left+1 < right:
		mid = (left+right) // 2
		cL=merge_sort(A,left,mid)
		cR=merge_sort(A,mid,right)
		return(merge(A,left,mid,right) + cL + cR)
	return 0 merge_sort if left+1 < right:
		mid = (left+right) // 2
		cL=merge_sort(A,left,mid)
		cR=merge_sort(A,mid,right)
		return(merge(A,left,mid,right) + cL + cR)
	 left+1 < right left+1 left 1 right mid = (left+right) // 2 mid (left+right) // 2 left+right left right 2 cL=merge_sort(A,left,mid) cL merge_sort(A,left,mid) merge_sort A left mid cR=merge_sort(A,mid,right) cR merge_sort(A,mid,right) merge_sort A mid right return(merge(A,left,mid,right) + cL + cR) merge(A,left,mid,right) + cL + cR merge(A,left,mid,right) + cL merge(A,left,mid,right) merge A left mid right cL cR return 0 0 A A left left right right c=0 c 0 n = int(input()) n int(input()) int input() input int(i) for i in input().split() for i in input().split() i input().split() ().split () input split for i in input().split() int(i) int i A = [int(i) for i in input().split()] A [int(i) for i in input().split()] c=merge_sort(A,0,n) c merge_sort(A,0,n) merge_sort A 0 n print(*A) print *A A print(c) print c n = int(input()) int(input()) n A = [int(i) for i in input().split()] [int(i) for i in input().split()] A c=merge_sort(A,0,n) merge_sort(A,0,n) c def merge(A,left,mid,right):
	L=A[left:mid]+[10**9]
	R=A[mid:right]+[10**9]
	i = 0
	j = 0
	c = 0
	for k in range(left,right):
		c += 1
		if L[i] <= R[j]:
			A[k] = L[i]
			i+=1
		else:
			A[k] = R[j]
			j+=1
	return c def merge(A,left,mid,right):
	L=A[left:mid]+[10**9]
	R=A[mid:right]+[10**9]
	i = 0
	j = 0
	c = 0
	for k in range(left,right):
		c += 1
		if L[i] <= R[j]:
			A[k] = L[i]
			i+=1
		else:
			A[k] = R[j]
			j+=1
	return c merge def merge_sort(A,left,right):
	if left+1 < right:
		mid = (left+right) // 2
		cL=merge_sort(A,left,mid)
		cR=merge_sort(A,mid,right)
		return(merge(A,left,mid,right) + cL + cR)
	return 0 def merge_sort(A,left,right):
	if left+1 < right:
		mid = (left+right) // 2
		cL=merge_sort(A,left,mid)
		cR=merge_sort(A,mid,right)
		return(merge(A,left,mid,right) + cL + cR)
	return 0 merge_sort c=0 0 c
def merge(A,left,mid,right):
	L=A[left:mid]+[10**9]
	R=A[mid:right]+[10**9]
	i = 0
	j = 0
	c = 0
	for k in range(left,right):
		c += 1
		if L[i] <= R[j]:
			A[k] = L[i]
			i+=1
		else:
			A[k] = R[j]
			j+=1
	return c

def merge_sort(A,left,right):
	if left+1 < right:
		mid = (left+right) // 2
		cL=merge_sort(A,left,mid)
		cR=merge_sort(A,mid,right)
		return(merge(A,left,mid,right) + cL + cR)
	return 0

c=0
n = int(input())
A = [int(i) for i in input().split()]
c=merge_sort(A,0,n)
print(*A)
print(c)
