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

class Array
  def merge_sort
    merge = ->(a, b) {
      result = []
      while a.size > 0 and b.size > 0
        result.push((a[0] < b[0]) ? a.shift : b.shift)
      end
      result + a + b
    }
    
    l = length
    return self if l <= 1
    q = l / 2
    $co += l
    merge.call(self[0...q].merge_sort, self[q..-1].merge_sort)
  end
end

puts s.merge_sort.join(" ")
puts $co
