INFTY = 9999999999
$cnt = 0

def merge(a, left, mid, right)
	n1 = mid - left
	n2 = right - mid
	l = []
	r = []
	0.upto(n1-1) do |i|
		l[i] = a[left + i]
	end
	0.upto(n2-1) do |i|
		r[i] = a[mid + i]
	end
	l[n1] = INFTY
	r[n2] = INFTY
	i = 0
	j = 0
	left.upto(right-1) do |k|
		$cnt += 1
		if l[i] <= r[j]
			a[k] = l[i]
			i += 1
		else
			a[k] = r[j]
			j += 1
		end
	end
end

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

n = gets.to_i
s = gets.split.map &:to_i
mergeSort(s, 0, s.size)
puts s.join(" ")
puts $cnt