@count = 0
def merge(l, r)
  result = []
  l_n = l.shift
  r_n = r.shift
  loop do
    break if [l_n, r_n].all?(&:nil?)
    @count += 1
    if l_n.nil?
      result << r_n
      r_n = r.shift
      next
    end
    if r_n.nil?
      result << l_n
      l_n = l.shift
      next
    end
    if l_n <= r_n
      result << l_n
      l_n = l.shift
    else
      result << r_n
      r_n = r.shift
    end
  end
  result
end

def merge_sort(arr)
  return arr if arr.length == 1

  mid = arr.length / 2 - 1
  merge(merge_sort(arr[0..mid]), merge_sort(arr[mid+1..-1]))
end

n = gets.to_i
arr = gets.split.map(&:to_i)
result = merge_sort(arr)
puts result.map(&:to_s).join(' ')
puts @count

