def merge(a, left, mid, right)
	n1 = mid - left
	n2 = right - mid
	
	l = Array.new(n1+1)
	r = Array.new(n2+1)
	
	for i in 0..n1-1 do
		l[i] = a[left + i]
	end
	for i in 0..n2-1 do
		r[i] = a[mid + i]
	end
	
	l[n1] = 10 ** 9
	r[n2] = 10 ** 9
	
	i = 0
	j = 0
	for k in left..right-1 do
		if l[i] <= r[j]
			a[k] = l[i]
			i = i + 1
		else 
			a[k] = r[j]
			j = j + 1
		end
		$cnt += 1
	end
end

def merge_sort(a, left, right)
	if left + 1 < right
		mid = (left + right) / 2
		merge_sort(a, left, mid)
		merge_sort(a, mid, right)
		merge(a, left, mid, right)
	end
end

n = gets.chomp.to_i
s = gets.chomp.split(" ").map(&:to_i)

$cnt = 0
merge_sort(s, 0, n)

puts s.join(" "),$cnt