import sys

infty = 10**10

def merge(A,left,mid,right):

	n1 = mid -left
	n2 = right - mid

	L = [0] * n1
	R = [0] * n2

	for i in range(n1):
		L[i] = A[left+i]
	for i in range(n2):
		R[i] = A[mid+i]

	L.append(infty)
	R.append(infty)

	i = 0
	j = 0
	cnt = 0

#	print(f"{left} {mid} {right} {n1} {n2}")
#	print(f"{L} {R}")
	for k in range(left,right):

		cnt += 1

		if L[i] <= R[j]:
			A[k] = L[i]
			i = i + 1
		else:
			A[k] = R[j]
			j = j + 1
		

	return cnt

#	print(A)

def mergeSort(A,left,right):

	cnt = 0

	if left+1 < right:

		mid = (left + right) // 2
		cnt += mergeSort(A,left,mid)
		cnt += mergeSort(A,mid,right)
		cnt += merge(A,left,mid,right)

	return cnt

def test():

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

	result = mergeSort(S,0,n)
	
	for i in range(n-1):
		print(f"{S[i]} ",end='')
	print(S[n-1])
	print(result)


if __name__ == "__main__":
	test()

 import sys sys infty = 10**10 infty 10**10 10 10 def merge(A,left,mid,right):

	n1 = mid -left
	n2 = right - mid

	L = [0] * n1
	R = [0] * n2

	for i in range(n1):
		L[i] = A[left+i]
	for i in range(n2):
		R[i] = A[mid+i]

	L.append(infty)
	R.append(infty)

	i = 0
	j = 0
	cnt = 0

#	print(f"{left} {mid} {right} {n1} {n2}")
#	print(f"{L} {R}")
	for k in range(left,right):

		cnt += 1

		if L[i] <= R[j]:
			A[k] = L[i]
			i = i + 1
		else:
			A[k] = R[j]
			j = j + 1
		

	return cnt

#	print(A) merge n1 = mid -left n1 mid -left mid left n2 = right - mid n2 right - mid right mid L = [0] * n1 L [0] * n1 [0] 0 n1 R = [0] * n2 R [0] * n2 [0] 0 n2 for i in range(n1):
		L[i] = A[left+i]
	 i range(n1) range n1 L[i] = A[left+i] L[i] L i A[left+i] A left+i left i for i in range(n2):
		R[i] = A[mid+i]

	 i range(n2) range n2 R[i] = A[mid+i] R[i] R i A[mid+i] A mid+i mid i L.append(infty) L.append L append infty R.append(infty) R.append R append infty i = 0 i 0 j = 0 j 0 cnt = 0 cnt 0 for k in range(left,right):

		cnt += 1

		if L[i] <= R[j]:
			A[k] = L[i]
			i = i + 1
		else:
			A[k] = R[j]
			j = j + 1
		

	 k range(left,right) range left right cnt += 1 cnt 1 if L[i] <= R[j]:
			A[k] = L[i]
			i = i + 1
		else:
			A[k] = R[j]
			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 = i + 1 i i + 1 i 1 A[k] = R[j] A[k] A k R[j] R j j = j + 1 j j + 1 j 1 return cnt cnt A A left left mid mid right right def mergeSort(A,left,right):

	cnt = 0

	if left+1 < right:

		mid = (left + right) // 2
		cnt += mergeSort(A,left,mid)
		cnt += mergeSort(A,mid,right)
		cnt += merge(A,left,mid,right)

	return cnt mergeSort cnt = 0 cnt 0 if left+1 < right:

		mid = (left + right) // 2
		cnt += mergeSort(A,left,mid)
		cnt += mergeSort(A,mid,right)
		cnt += merge(A,left,mid,right)

	 left+1 < right left+1 left 1 right mid = (left + right) // 2 mid (left + right) // 2 left + right left right 2 cnt += mergeSort(A,left,mid) cnt mergeSort(A,left,mid) mergeSort A left mid cnt += mergeSort(A,mid,right) cnt mergeSort(A,mid,right) mergeSort A mid right cnt += merge(A,left,mid,right) cnt merge(A,left,mid,right) merge A left mid right return cnt cnt A A left left right right def test():

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

	result = mergeSort(S,0,n)
	
	for i in range(n-1):
		print(f"{S[i]} ",end='')
	print(S[n-1])
	print(result) test n = int(sys.stdin.readline()) n int(sys.stdin.readline()) int sys.stdin.readline() sys.stdin.readline sys.stdin sys stdin readline S = list(map(int,sys.stdin.readline().split())) S list(map(int,sys.stdin.readline().split())) list map(int,sys.stdin.readline().split()) map int sys.stdin.readline().split() sys.stdin.readline().split sys.stdin.readline() sys.stdin.readline sys.stdin sys stdin readline split result = mergeSort(S,0,n) result mergeSort(S,0,n) mergeSort S 0 n for i in range(n-1):
		print(f"{S[i]} ",end='')
	 i range(n-1) range n-1 n 1 print(f"{S[i]} ",end='') print f"{S[i]} " end='' end '' print(S[n-1]) print S[n-1] S n-1 n 1 print(result) print result if __name__ == "__main__":
	test() __name__ == "__main__" __name__ "__main__" test() test def test():

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

	result = mergeSort(S,0,n)
	
	for i in range(n-1):
		print(f"{S[i]} ",end='')
	print(S[n-1])
	print(result) def test():

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

	result = mergeSort(S,0,n)
	
	for i in range(n-1):
		print(f"{S[i]} ",end='')
	print(S[n-1])
	print(result) test def merge(A,left,mid,right):

	n1 = mid -left
	n2 = right - mid

	L = [0] * n1
	R = [0] * n2

	for i in range(n1):
		L[i] = A[left+i]
	for i in range(n2):
		R[i] = A[mid+i]

	L.append(infty)
	R.append(infty)

	i = 0
	j = 0
	cnt = 0

#	print(f"{left} {mid} {right} {n1} {n2}")
#	print(f"{L} {R}")
	for k in range(left,right):

		cnt += 1

		if L[i] <= R[j]:
			A[k] = L[i]
			i = i + 1
		else:
			A[k] = R[j]
			j = j + 1
		

	return cnt

#	print(A) def merge(A,left,mid,right):

	n1 = mid -left
	n2 = right - mid

	L = [0] * n1
	R = [0] * n2

	for i in range(n1):
		L[i] = A[left+i]
	for i in range(n2):
		R[i] = A[mid+i]

	L.append(infty)
	R.append(infty)

	i = 0
	j = 0
	cnt = 0

#	print(f"{left} {mid} {right} {n1} {n2}")
#	print(f"{L} {R}")
	for k in range(left,right):

		cnt += 1

		if L[i] <= R[j]:
			A[k] = L[i]
			i = i + 1
		else:
			A[k] = R[j]
			j = j + 1
		

	return cnt

#	print(A) merge infty = 10**10 10**10 infty def mergeSort(A,left,right):

	cnt = 0

	if left+1 < right:

		mid = (left + right) // 2
		cnt += mergeSort(A,left,mid)
		cnt += mergeSort(A,mid,right)
		cnt += merge(A,left,mid,right)

	return cnt def mergeSort(A,left,right):

	cnt = 0

	if left+1 < right:

		mid = (left + right) // 2
		cnt += mergeSort(A,left,mid)
		cnt += mergeSort(A,mid,right)
		cnt += merge(A,left,mid,right)

	return cnt mergeSort
import sys

infty = 10**10

def merge(A,left,mid,right):

	n1 = mid -left
	n2 = right - mid

	L = [0] * n1
	R = [0] * n2

	for i in range(n1):
		L[i] = A[left+i]
	for i in range(n2):
		R[i] = A[mid+i]

	L.append(infty)
	R.append(infty)

	i = 0
	j = 0
	cnt = 0

#	print(f"{left} {mid} {right} {n1} {n2}")
#	print(f"{L} {R}")
	for k in range(left,right):

		cnt += 1

		if L[i] <= R[j]:
			A[k] = L[i]
			i = i + 1
		else:
			A[k] = R[j]
			j = j + 1
		

	return cnt

#	print(A)

def mergeSort(A,left,right):

	cnt = 0

	if left+1 < right:

		mid = (left + right) // 2
		cnt += mergeSort(A,left,mid)
		cnt += mergeSort(A,mid,right)
		cnt += merge(A,left,mid,right)

	return cnt

def test():

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

	result = mergeSort(S,0,n)
	
	for i in range(n-1):
		print(f"{S[i]} ",end='')
	print(S[n-1])
	print(result)


if __name__ == "__main__":
	test()


