def merge(array, left, mid, right)
  n1 = mid - left
  n2 = right - mid
  l = []
  r = []
  (0..(n1-1)).each do |i|
    l << array[left+i]
  end
  (0..(n2-1)).each do |i|
    r << array[mid+i]
  end
  l[n1] = Float::INFINITY
  r[n2] = Float::INFINITY

  count = 0
  i = 0
  j = 0
  (left..(right-1)).each do |k|
    count += 1
    if l[i] <= r[j] then
      array[k] = l[i]
      i += 1
    else
      array[k] = r[j]
      j += 1
    end
  end
  return count
end

def merge_sort(array, left, right)
  count = 0
  if left+1 < right then
    mid = (left + right) / 2
    count += merge_sort(array, left, mid)
    count += merge_sort(array, mid, right)
    count += merge(array, left, mid, right)
  end
  return count
end

n = gets.chomp.to_i
array = gets.chomp.split.map(&:to_i)
count = merge_sort(array, 0, n)
puts array.join(' ')
puts count