n = gets.chomp.to_i
s = gets.chomp.split(" ").map{ |x| x.to_i }

$count = 0

def merge(a, left, mid, right)
  n1 = mid - left
  n2 = right - mid
  l = (0..n1).to_a
  r = (0..n2).to_a
  (0...n1).each { |i| l[i] = a[left + i] }
  (0...n2).each { |i| r[i] = a[mid + i] }

  l[n1] = r[n2] = 10**9
  i = j = 0

  (left...right).each do |k|
    $count += 1
    if l[i] <= r[j]
      a[k] = l[i]
      i = i + 1
    else
      a[k] = r[j]
      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
  return $count, a
end

result = mergeSort(s, 0, n)
puts result[1].join(" ")
puts result[0]

