n = gets.to_i
a = []
n.times do
  a << gets.to_i
end
a.sort!
ans = 0
if n.odd?
  m = a.slice!(n/2-1,3)
  n -= 3
  ans += [-2*m[0]+m[1]+m[2],-m[0]-m[1]+2*m[2]].max
else
  ans += - a.delete_at(n/2-1)
  ans +=  a.delete_at(n/2-1)
  n -= 2
end
ans += -2 * a[0,n/2].inject(:+) + 2*a[n/2,n/2].inject(:+) if !a.empty?
p ans
