def merge(a,n)
  x=0
  left=Array.new
  right=Array.new 
  l=(n/2).to_i
  r=n-l
  l.times do |i|
    left<<a[i]
  end
  r.times do |i|
    right<<a[i+l]
  end
  left<<10**9+1
  right<<10**9+1
  if l>1 then
    x+=merge(left,l)
  end
  if r>1 then
    x+=merge(right,r)
  end
  i=0
  j=0
  n.times do |k|
    if left[i]<right[j] then
      a[k]=left[i]
      i+=1
    else
      a[k]=right[j]
      j+=1
    end
  end
  return i+j+x
end

n=gets.to_i
a=gets.split.map!{|i|i.to_i}
a.slice!(n..-1)
x=merge(a,n)
n.times do |i|
  print a[i]
  if i!=n-1
    print " "
  end
end
print "\n",x
