n = gets.to_i
s = gets.split.map(&:to_i)
co = 0

merge = ->(left, mid, right) {
  n1, n2 = mid - left, right - mid
  l = s[left, n1] + [Float::INFINITY]
  r = s[mid , n2] + [Float::INFINITY]
  i = j = 0
  co += right - left
  left.upto(right - 1) do |k|
    if l[i] <= r[j]
      s[k] = l[i]
      i += 1
    else
      s[k] = r[j]
      j += 1
    end
  end
}

merge_sort = ->(left, right) {
  if left < right - 1
    mid = (left + right) / 2
    merge_sort.(left, mid)
    merge_sort.(mid, right)
    merge.(left, mid, right)
  end
}

merge_sort.(0, n)
puts s.join(" ")
puts co
