n = gets.to_i

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

m = n / 2
if n % 2 == 0
  sum = -2 * arr[0...(m - 1)].sum
  sum += 2 * arr[(m + 1)..-1].sum
  sum += arr[m] - arr[m - 1]
else
  sum = -2 * arr[0...(m - 1)].sum 
  sum += 2 * arr[(m + 2)..-1].sum 
  sum1 = sum + 2 * arr[m + 1] - arr[m] - arr[m - 1]
  sum2 = sum + arr[m + 1] + arr[m] - 2 * arr[m - 1]
  sum = [sum1, sum2].max
end
puts sum