def mergesort array_A,left,right
  if left+1 < right
  mid = (left+right)/2
  mergesort(array_A,left,mid)
  mergesort(array_A,mid,right)  
  merge(array_A,left,mid,right) 
  end
end

def merge array_A,left,mid,right
n1 = mid - left
n2 = right - mid
array_L,array_R = Array.new(),Array.new()
n1.times {|i|
array_L[i] = array_A[left+i]
}
n2.times {|i|
  array_R[i] = array_A[mid+i]
}
array_L[n1],array_R[n2]=(10**9).next,(10**9).next
j,i=0,0
p = right - left
p.times {|k|
  if array_L[i] <= array_R[j]
  array_A[left+k]=array_L[i]
  i+=1
  else
  array_A[left+k]=array_R[j]
  j+=1
  end
}
$count +=  p
end
n = gets.chomp.to_i
$count = 0
array_A = gets.split(" ").map{|x|x.to_i}
mergesort(array_A,0,n)
q = array_A.count {|item| !item.nil? }
(q-1).times {|i|
  printf("%d ",array_A[i])
}
printf("%d\n%d\n",array_A[q-1],$count)