n = gets.to_i

arr = Array.new(n)
n.times do |i|
  arr[i] = gets.to_i
end

arr = arr.sort
sum = 0
((n-1)/2).times do |i|
  sum += 2 * (arr[-i - 1] - arr[i])
end

i = n / 2
if n % 2 == 0
  sum += arr[i + 1] - arr[i]
else
  sum += arr[i] - arr[i - 1]
end
puts sum