INF = 10**9 + 1

def merge(a,left,mid,right)
  count = 0
  lSize = mid-left;
  rSize = right-mid;
  l = []
  r = []
  (0...lSize).each do |i|
    l[i] = a[left+i]
  end
  (0...rSize).each do |i|
    r[i] = a[mid+i]
  end
  l[lSize] = INF
  r[rSize] = INF
  i,j=0,0
  (left...right).each do |k|
    count += 1
    if l[i] <= r[j]
      a[k] = l[i]
      i += 1
    else 
      a[k] = r[j]
      j += 1
    end
  end
  return count
end

def mergeSort(a,left,right)
  count = 0
  if left+1 < right
    mid = (left+right)/2;
    count += mergeSort(a,left,mid)
    count += mergeSort(a,mid,right)
    count += merge(a,left,mid,right)
  end
  return count
end

n = gets.to_i
a = gets.split.map(&:to_i)
count = mergeSort(a,0,n)
p a
p count
