@cnt = 0
def merge(a, left, right)
  left.upto(right-1) do |k|
    @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, right)
  end
end

n = gets.to_i
nums = gets.split.map(&:to_i)
merge_sort(nums, 0, n)
puts nums.sort * ' '
puts @cnt

