def merge(a,l,m,r)
  nl = m - l
  nr = r - m
  al = Array.new(nl+1)
  ar = Array.new(nr+1)
  for i in 0...nl
    al[i] = a[l+i]
  end
  for i in 0...nr
    ar[i] = a[m+i]
  end
  al[nl] = 1000000
  ar[nr] = 1000000
  i = 0
  j = 0
  cnt = 0
  for k in l...r
    if al[i] <= ar[j]
      a[k] = al[i]
      i += 1
    else
      a[k] = ar[j]
      j += 1
    end
    cnt += 1
  end
  cnt
end

def mergesort(a,l,r)
  cnt = 0
  if l+1 < r
    m = (l+r)/2
    cnt += mergesort(a,l,m)
    cnt += mergesort(a,m,r)
    cnt += merge(a,l,m,r)
  end
  cnt
end

n = gets.to_i
a = gets.split.map(&:to_i)
c = mergesort(a,0,n)
for i in 0...n
  print " " unless i == 0
  print a[i]
end
print "\n"
puts c