n = gets.chomp.to_i
a = []
n.times do
  a << gets.chomp.to_i
end

if n == 2
  puts (a[1] - a[0]).abs
  exit
end

b = a.clone.sort

a.sort!
center = a.shift
left = a.pop
right = a.pop

ans = 0
ans += (center - left).abs
ans += (center - right).abs

flag = true
loop do
  break if a.empty?
  if a.length == 1
    sum1 = (left - a[0]).abs
    sum2 = (right - a[0]).abs
    if sum1 >= sum2
      ans += sum1
    else
      ans += sum2
    end
    break
  end
  if flag
    nl = a.shift
    nr = a.shift
    sum1 = (left - nl).abs + (right - nr).abs
    sum2 = (left - nr).abs + (right - nl).abs
    if sum1 >= sum2
      ans += sum1
    else
      ans += sum2
    end
    left = nl
    right = nr
    flag = false
  else
    nl = a.pop
    nr = a.pop
    sum1 = (left - nl).abs + (right - nr).abs
    sum2 = (left - nr).abs + (right - nl).abs
    if sum1 >= sum2
      ans += sum1
    else
      ans += sum2
    end
    left = nl
    right = nr
    flag = true
  end
end

temp = [ans]

a = b

center = a.pop
left = a.shift
right = a.shift
ans = 0
ans += (center - left).abs
ans += (center - right).abs

flag = true
loop do
  break if a.empty?
  if a.length == 1
    sum1 = (left - a[0]).abs
    sum2 = (right - a[0]).abs
    if sum1 >= sum2
      ans += sum1
    else
      ans += sum2
    end
    break
  end
  if flag
    nl = a.shift
    nr = a.shift
    sum1 = (left - nl).abs + (right - nr).abs
    sum2 = (left - nr).abs + (right - nl).abs
    if sum1 >= sum2
      ans += sum1
    else
      ans += sum2
    end
    left = nl
    right = nr
    flag = false
  else
    nl = a.pop
    nr = a.pop
    sum1 = (left - nl).abs + (right - nr).abs
    sum2 = (left - nr).abs + (right - nl).abs
    if sum1 >= sum2
      ans += sum1
    else
      ans += sum2
    end
    left = nl
    right = nr
    flag = true
  end
end

temp << ans

puts temp.max