# https://onlinejudge.u-aizu.ac.jp/courses/lesson/1/ALDS1/5/ALDS1_5_B

n = int(input())
A = list(map(int, input().split()))
	
# マージソート
def merge_sort(arr, left, right):
	# merge_sort(lst, 0, len(lst))
	global cnt
	if right - left == 1:
		return 
	mid = left + (right - left) // 2
	merge_sort(arr, left, mid)
	merge_sort(arr, mid, right)
	a = [arr[i] for i in range(left, mid)] \
		+ [arr[i] for i in range(right - 1, mid - 1, -1)]
	iterator_left = 0
	iterator_right = len(a) - 1
	for i in range(left, right):
		cnt += 1
		if a[iterator_left] <= a[iterator_right]:
			arr[i] = a[iterator_left]
			iterator_left += 1
		else:
			arr[i] = a[iterator_right]
			iterator_right -= 1

cnt = 0
merge_sort(A, 0, n)
print(*A)
print(cnt) 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 def merge_sort(arr, left, right):
	# merge_sort(lst, 0, len(lst))
	global cnt
	if right - left == 1:
		return 
	mid = left + (right - left) // 2
	merge_sort(arr, left, mid)
	merge_sort(arr, mid, right)
	a = [arr[i] for i in range(left, mid)] \
		+ [arr[i] for i in range(right - 1, mid - 1, -1)]
	iterator_left = 0
	iterator_right = len(a) - 1
	for i in range(left, right):
		cnt += 1
		if a[iterator_left] <= a[iterator_right]:
			arr[i] = a[iterator_left]
			iterator_left += 1
		else:
			arr[i] = a[iterator_right]
			iterator_right -= 1 merge_sort global cnt if right - left == 1:
		return 
	 right - left == 1 right - left right left 1 return mid = left + (right - left) // 2 mid left + (right - left) // 2 left (right - left) // 2 right - left right left 2 merge_sort(arr, left, mid) merge_sort arr left mid merge_sort(arr, mid, right) merge_sort arr mid right arr[i] for i in range(left, mid) for i in range(left, mid) i range(left, mid) range left mid for i in range(left, mid) arr[i] arr i a = [arr[i] for i in range(left, mid)] \
		+ [arr[i] for i in range(right - 1, mid - 1, -1)] a [arr[i] for i in range(left, mid)] \
		+ [arr[i] for i in range(right - 1, mid - 1, -1)] [arr[i] for i in range(left, mid)] [arr[i] for i in range(right - 1, mid - 1, -1)] iterator_left = 0 iterator_left 0 iterator_right = len(a) - 1 iterator_right len(a) - 1 len(a) len a 1 for i in range(left, right):
		cnt += 1
		if a[iterator_left] <= a[iterator_right]:
			arr[i] = a[iterator_left]
			iterator_left += 1
		else:
			arr[i] = a[iterator_right]
			iterator_right -= 1 i range(left, right) range left right cnt += 1 cnt 1 if a[iterator_left] <= a[iterator_right]:
			arr[i] = a[iterator_left]
			iterator_left += 1
		else:
			arr[i] = a[iterator_right]
			iterator_right -= 1 a[iterator_left] <= a[iterator_right] a[iterator_left] a iterator_left a[iterator_right] a iterator_right arr[i] = a[iterator_left] arr[i] arr i a[iterator_left] a iterator_left iterator_left += 1 iterator_left 1 arr[i] = a[iterator_right] arr[i] arr i a[iterator_right] a iterator_right iterator_right -= 1 iterator_right 1 arr arr left left right right cnt = 0 cnt 0 merge_sort(A, 0, n) merge_sort A 0 n print(*A) print *A A print(cnt) print cnt n = int(input()) int(input()) n def merge_sort(arr, left, right):
	# merge_sort(lst, 0, len(lst))
	global cnt
	if right - left == 1:
		return 
	mid = left + (right - left) // 2
	merge_sort(arr, left, mid)
	merge_sort(arr, mid, right)
	a = [arr[i] for i in range(left, mid)] \
		+ [arr[i] for i in range(right - 1, mid - 1, -1)]
	iterator_left = 0
	iterator_right = len(a) - 1
	for i in range(left, right):
		cnt += 1
		if a[iterator_left] <= a[iterator_right]:
			arr[i] = a[iterator_left]
			iterator_left += 1
		else:
			arr[i] = a[iterator_right]
			iterator_right -= 1 def merge_sort(arr, left, right):
	# merge_sort(lst, 0, len(lst))
	global cnt
	if right - left == 1:
		return 
	mid = left + (right - left) // 2
	merge_sort(arr, left, mid)
	merge_sort(arr, mid, right)
	a = [arr[i] for i in range(left, mid)] \
		+ [arr[i] for i in range(right - 1, mid - 1, -1)]
	iterator_left = 0
	iterator_right = len(a) - 1
	for i in range(left, right):
		cnt += 1
		if a[iterator_left] <= a[iterator_right]:
			arr[i] = a[iterator_left]
			iterator_left += 1
		else:
			arr[i] = a[iterator_right]
			iterator_right -= 1 merge_sort cnt = 0 0 cnt A = list(map(int, input().split())) list(map(int, input().split())) A
# https://onlinejudge.u-aizu.ac.jp/courses/lesson/1/ALDS1/5/ALDS1_5_B

n = int(input())
A = list(map(int, input().split()))
	
# マージソート
def merge_sort(arr, left, right):
	# merge_sort(lst, 0, len(lst))
	global cnt
	if right - left == 1:
		return 
	mid = left + (right - left) // 2
	merge_sort(arr, left, mid)
	merge_sort(arr, mid, right)
	a = [arr[i] for i in range(left, mid)] \
		+ [arr[i] for i in range(right - 1, mid - 1, -1)]
	iterator_left = 0
	iterator_right = len(a) - 1
	for i in range(left, right):
		cnt += 1
		if a[iterator_left] <= a[iterator_right]:
			arr[i] = a[iterator_left]
			iterator_left += 1
		else:
			arr[i] = a[iterator_right]
			iterator_right -= 1

cnt = 0
merge_sort(A, 0, n)
print(*A)
print(cnt)
