gets
a=gets.split(' ').map(&:to_i)
def merge(a, left, mid, right,count)
  n1 = mid-left
  n2 = right-mid
  l = (0..n1).to_a
  r = (0..n2).to_a
  for i in 0..n1-1
    l[i] = a[i+left]
  end
  for i in 0..n2-1
    r[i] = a[mid+i]
  end
  i = j = 0
  l[n1] = r[n2] = Float::INFINITY
  for k in left..right-1
    count += 1
    if l[i] <= r[j]
      a[k] = l[i]
      i += 1
    else
      a[k] = r[j]
      j += 1
    end
  end
  count
end

def merge_sort(a, left, right, count)
  if left+1 < right
    mid = (left+right) / 2
    count = merge_sort(a,left,mid,count)
    count = merge_sort(a,mid,right,count)
    count = merge(a,left,mid,right,count)
  end
  count
end

# p a
count = 0
count = merge_sort(a,0,a.size,count)
ans=""
for i in 0..a.size-1
  ans += "#{a[i]}"
  ans += " " if i != a.size-1
end
puts ans
puts count