def merge(S, left, mid, right):
	global cnt
	L = S[left:mid] + [float('inf')]
	R = S[mid:right] + [float('inf')]
	i,j = 0,0
	for k in range(left,right):
		if L[i] <= R[j]:
			S[k] = L[i]
			i += 1
		else:
			S[k] = R[j]
			j += 1
	cnt += right - left


def merge_sort(S, left = 0, right = 500000):
	right = min(len(S),right)
	if left+1 < right:
		mid = (left+right) // 2
		merge_sort(S, left, mid)
		merge_sort(S, mid, right)
		merge(S, left, mid, right)


if __name__ == '__main__':
	n = int(input())
	S = [int(s) for s in input().split()]
	cnt = 0
	merge_sort(S)
	print(*S)
	print(cnt) def merge(S, left, mid, right):
	global cnt
	L = S[left:mid] + [float('inf')]
	R = S[mid:right] + [float('inf')]
	i,j = 0,0
	for k in range(left,right):
		if L[i] <= R[j]:
			S[k] = L[i]
			i += 1
		else:
			S[k] = R[j]
			j += 1
	cnt += right - left merge global cnt L = S[left:mid] + [float('inf')] L S[left:mid] + [float('inf')] S[left:mid] S left:mid left mid [float('inf')] float('inf') float 'inf' R = S[mid:right] + [float('inf')] R S[mid:right] + [float('inf')] S[mid:right] S mid:right mid right [float('inf')] float('inf') float 'inf' i,j = 0,0 i 0 j 0 for k in range(left,right):
		if L[i] <= R[j]:
			S[k] = L[i]
			i += 1
		else:
			S[k] = R[j]
			j += 1
	 k range(left,right) range left right if L[i] <= R[j]:
			S[k] = L[i]
			i += 1
		else:
			S[k] = R[j]
			j += 1
	 L[i] <= R[j] L[i] L i R[j] R j S[k] = L[i] S[k] S k L[i] L i i += 1 i 1 S[k] = R[j] S[k] S k R[j] R j j += 1 j 1 cnt += right - left cnt right - left right left S S left left mid mid right right def merge_sort(S, left = 0, right = 500000):
	right = min(len(S),right)
	if left+1 < right:
		mid = (left+right) // 2
		merge_sort(S, left, mid)
		merge_sort(S, mid, right)
		merge(S, left, mid, right) merge_sort right = min(len(S),right) right min(len(S),right) min len(S) len S right if left+1 < right:
		mid = (left+right) // 2
		merge_sort(S, left, mid)
		merge_sort(S, mid, right)
		merge(S, left, mid, right) left+1 < right left+1 left 1 right mid = (left+right) // 2 mid (left+right) // 2 left+right left right 2 merge_sort(S, left, mid) merge_sort S left mid merge_sort(S, mid, right) merge_sort S mid right merge(S, left, mid, right) merge S left mid right S S left = 0 left 0 right = 500000 right 500000 if __name__ == '__main__':
	n = int(input())
	S = [int(s) for s in input().split()]
	cnt = 0
	merge_sort(S)
	print(*S)
	print(cnt) __name__ == '__main__' __name__ '__main__' n = int(input()) n int(input()) int input() input int(s) for s in input().split() for s in input().split() s input().split() ().split () input split for s in input().split() int(s) int s S = [int(s) for s in input().split()] S [int(s) for s in input().split()] cnt = 0 cnt 0 merge_sort(S) merge_sort S print(*S) print *S S print(cnt) print cnt n = int(input()) int(input()) n S = [int(s) for s in input().split()] [int(s) for s in input().split()] S def merge(S, left, mid, right):
	global cnt
	L = S[left:mid] + [float('inf')]
	R = S[mid:right] + [float('inf')]
	i,j = 0,0
	for k in range(left,right):
		if L[i] <= R[j]:
			S[k] = L[i]
			i += 1
		else:
			S[k] = R[j]
			j += 1
	cnt += right - left def merge(S, left, mid, right):
	global cnt
	L = S[left:mid] + [float('inf')]
	R = S[mid:right] + [float('inf')]
	i,j = 0,0
	for k in range(left,right):
		if L[i] <= R[j]:
			S[k] = L[i]
			i += 1
		else:
			S[k] = R[j]
			j += 1
	cnt += right - left merge cnt = 0 0 cnt def merge_sort(S, left = 0, right = 500000):
	right = min(len(S),right)
	if left+1 < right:
		mid = (left+right) // 2
		merge_sort(S, left, mid)
		merge_sort(S, mid, right)
		merge(S, left, mid, right) def merge_sort(S, left = 0, right = 500000):
	right = min(len(S),right)
	if left+1 < right:
		mid = (left+right) // 2
		merge_sort(S, left, mid)
		merge_sort(S, mid, right)
		merge(S, left, mid, right) merge_sort
def merge(S, left, mid, right):
	global cnt
	L = S[left:mid] + [float('inf')]
	R = S[mid:right] + [float('inf')]
	i,j = 0,0
	for k in range(left,right):
		if L[i] <= R[j]:
			S[k] = L[i]
			i += 1
		else:
			S[k] = R[j]
			j += 1
	cnt += right - left


def merge_sort(S, left = 0, right = 500000):
	right = min(len(S),right)
	if left+1 < right:
		mid = (left+right) // 2
		merge_sort(S, left, mid)
		merge_sort(S, mid, right)
		merge(S, left, mid, right)


if __name__ == '__main__':
	n = int(input())
	S = [int(s) for s in input().split()]
	cnt = 0
	merge_sort(S)
	print(*S)
	print(cnt)