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

$cnt = 0
$INF = 10**9

def marge(l, r)
  l.push($INF)
  r.push($INF)
  length = l.length-1 + r.length-1
  return Array.new(length){$cnt+=1; (l.first <= r.first ? l : r).shift}
end

def marge_sort(s)
  if s.length >= 2
    mid = s.length/2
    l = marge_sort(s[0..mid-1])
    r = marge_sort(s[mid..-1])
    s = marge(l, r)
  end
  return s
end

puts marge_sort(s).join(" ")
puts $cnt
