def merge_sort(arr, &block)
  return arr if arr.size <= 1

  mid = arr.size / 2

  arr1 = arr[0...mid]
  arr2 = arr[mid..-1]

  merge(merge_sort(arr1, &block), merge_sort(arr2, &block), &block)
end

def merge(arr1, arr2, &block)
  ret = []

  until arr1.empty? || arr2.empty?
    if arr1.first <= arr2.first
      ret << arr1.shift
    else
      ret << arr2.shift
    end

    block.call
  end

  unless arr1.empty?
    ret.push(*arr1)
    arr1.size.times { block.call }
  end

  unless arr2.empty?
    ret.push(*arr2)
    arr2.size.times { block.call }
  end

  ret
end

n = gets.to_i
arr = gets.split.map(&:to_i)

count = 0

puts merge_sort(arr) { count += 1 }.join(' ')

puts count