$count = 0
def merge(array, left, mid, right)
  n1 = mid - left
  n2 = right - mid
  l = Array.new(n1) { nil }
  r = Array.new(n2) { nil }
  l.size.times do |i|
    l[i] = array[left + i]
  end
  r.size.times do |i|
    r[i] = array[mid + i]
  end
  l << 9999999999
  r << 9999999999
  i, j = 0, 0
  left.upto(right - 1) do |k|
    $count += 1
    if l[i] <= r[j]
      array[k] = l[i]
      i += 1
    else
      array[k] = r[j]
      j += 1
    end
  end
end

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

len = gets.to_i
array = gets.split(' ').map(&:to_i)
mergeSort(array, 0, len)
puts array.join(' ')
p $count

