n = gets.chomp.to_i
a = []
n.times do
  a.push(gets.chomp.to_i)
end
a.sort!

def sum(array)
  if array.empty?
    0
  else
    array.inject(:+)
  end
end

if a.size.even?
  a_zen = a[0..a.size/2 - 1]
  a_kou = a[a.size/2..a.size-1]
  a_zen_last = a_zen.pop
  a_kou_last = a_kou.shift
  p sum(a_kou) * 2 + a_kou_last - sum(a_zen) * 2 - a_zen_last
else
  a_zen = a[0..a.size/2 - 1]
  a_kou = a[a.size/2..a.size-1]
  a_harf = a_kou.shift
  a_zen_last = a_zen.pop
  a_kou_last = a_kou.shift
  total = sum(a_kou) * 2 + a_kou_last - sum(a_zen) * 2 - a_zen_last
  p total + [a_harf - a_zen_last, a_kou_last - a_harf].max
end
