#!/usr/bin/ruby
$cnt = 0

def merge(a, left, mid, right)
  # mergeを指示された範囲を配列として取得
  # a[基準, 基準から何個とるか]
  l = a[left, (mid - left)]
  r = a[mid, (right - mid)]
  # loopが綺麗に回るように範囲超えの値を挿入
  l << 10**10
  r << 10**10
  # l, rの配列の先頭から小さい数字を詰めていく
  li, ri = 0, 0 # l, rの配列用のindex
  left.upto(right - 1) do | i | # aに挿入するためのindex
    $cnt += 1
    if l[li] <= r[ri]
      a[i] = l[li]
      li += 1
    else
      a[i] = r[ri]
      ri += 1
    end
  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, mid, right)
  end
end

#
n = gets.to_i
a = gets.split.map(&:to_i)
merge_sort(a, 0, n)
puts a.join(' ')
puts $cnt
