$count = 0

def merge(a, left, mid, right)
  la = a[left..mid]
  ra = a[mid+1..right]
  sorted = []
  i = 0
  j = 0
  while i < la.size || j < ra.size
    if la[i] <= ra[j]
      sorted <<  la[i]
      i += 1
    else
      sorted << ra[j]
      j += 1
    end
    $count += 1
    if la.size <= i
      until ra.size <= j
        sorted << ra[j]  
        j += 1
        $count += 1
      end
    elsif ra.size <= j
      until la.size <= i
        sorted << la[i] 
        i += 1
        $count += 1
      end
    end
  end
  sorted
end

def merge_sort(a, left, right)
  if right - left > 0
    mid = (left + right) / 2
    sorted = merge_sort(a[0..mid], 0, mid) + merge_sort(a[mid+1..right], 0, right - (mid + 1))
    merge(sorted, left, mid, right)
  else
    a
  end
end

n = gets.to_i
a = gets.split.map(&:to_i)
puts merge_sort(a, 0, n-1).join(' '), $count