
INF = 10000000000

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

	n1 = mid - left
	n2 = right - mid

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

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

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

	return cnt

def mergeSort(A,left,right):

	if left+1 < right:
		mid = ( left + right ) // 2
		cnt_l = mergeSort(A,left,mid)
		cnt_r = mergeSort(A,mid,right)

		return merge(A,left,mid,right)+cnt_l+cnt_r

	return 0

if __name__ == '__main__':

	num = int(input())
	A = [int(i) for i in input().split()]

	left = 0
	right = len(A)

	count = mergeSort(A,left,right)

	print(" ".join(map(str,A)))
	print(count)
 INF = 10000000000 INF 10000000000 def merge(A,left,mid,right):

	n1 = mid - left
	n2 = right - mid

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

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

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

	return cnt merge n1 = mid - left n1 mid - left mid left n2 = right - mid n2 right - mid right mid L = A[left:mid] + [INF] L A[left:mid] + [INF] A[left:mid] A left:mid left mid [INF] INF R = A[mid:right] + [INF] R A[mid:right] + [INF] A[mid:right] A mid:right mid right [INF] INF 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 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 += 1
		else:
			A[k] = R[j]
			j += 1

	 k range(left,right) range left right cnt += 1 cnt 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 cnt cnt A A left left mid mid right right def mergeSort(A,left,right):

	if left+1 < right:
		mid = ( left + right ) // 2
		cnt_l = mergeSort(A,left,mid)
		cnt_r = mergeSort(A,mid,right)

		return merge(A,left,mid,right)+cnt_l+cnt_r

	return 0 mergeSort if left+1 < right:
		mid = ( left + right ) // 2
		cnt_l = mergeSort(A,left,mid)
		cnt_r = mergeSort(A,mid,right)

		return merge(A,left,mid,right)+cnt_l+cnt_r

	 left+1 < right left+1 left 1 right mid = ( left + right ) // 2 mid ( left + right ) // 2 left + right left right 2 cnt_l = mergeSort(A,left,mid) cnt_l mergeSort(A,left,mid) mergeSort A left mid cnt_r = mergeSort(A,mid,right) cnt_r mergeSort(A,mid,right) mergeSort A mid right return merge(A,left,mid,right)+cnt_l+cnt_r merge(A,left,mid,right)+cnt_l+cnt_r merge(A,left,mid,right)+cnt_l merge(A,left,mid,right) merge A left mid right cnt_l cnt_r return 0 0 A A left left right right if __name__ == '__main__':

	num = int(input())
	A = [int(i) for i in input().split()]

	left = 0
	right = len(A)

	count = mergeSort(A,left,right)

	print(" ".join(map(str,A)))
	print(count) __name__ == '__main__' __name__ '__main__' num = int(input()) num 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()] left = 0 left 0 right = len(A) right len(A) len A count = mergeSort(A,left,right) count mergeSort(A,left,right) mergeSort A left right print(" ".join(map(str,A))) print " ".join(map(str,A)) " ".join " " join map(str,A) map str A print(count) print count def mergeSort(A,left,right):

	if left+1 < right:
		mid = ( left + right ) // 2
		cnt_l = mergeSort(A,left,mid)
		cnt_r = mergeSort(A,mid,right)

		return merge(A,left,mid,right)+cnt_l+cnt_r

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

	if left+1 < right:
		mid = ( left + right ) // 2
		cnt_l = mergeSort(A,left,mid)
		cnt_r = mergeSort(A,mid,right)

		return merge(A,left,mid,right)+cnt_l+cnt_r

	return 0 mergeSort A = [int(i) for i in input().split()] [int(i) for i in input().split()] A count = mergeSort(A,left,right) mergeSort(A,left,right) count left = 0 0 left right = len(A) len(A) right INF = 10000000000 10000000000 INF def merge(A,left,mid,right):

	n1 = mid - left
	n2 = right - mid

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

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

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

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

	n1 = mid - left
	n2 = right - mid

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

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

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

	return cnt merge num = int(input()) int(input()) num

INF = 10000000000

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

	n1 = mid - left
	n2 = right - mid

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

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

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

	return cnt

def mergeSort(A,left,right):

	if left+1 < right:
		mid = ( left + right ) // 2
		cnt_l = mergeSort(A,left,mid)
		cnt_r = mergeSort(A,mid,right)

		return merge(A,left,mid,right)+cnt_l+cnt_r

	return 0

if __name__ == '__main__':

	num = int(input())
	A = [int(i) for i in input().split()]

	left = 0
	right = len(A)

	count = mergeSort(A,left,right)

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

