n = gets.to_i
a = n.times.map{gets.to_i}.sort
ans = 0
l,r = a[-1],a[0]
for i in 1..n/2-1
  if (l-a[i]).abs > (r-a[i]).abs
    ans += (l-a[i]).abs
    l = a[i]
  else
    ans += (r-a[i]).abs
    r = a[i]
  end
  if (l-a[-1-i]).abs > (r-a[-1-i]).abs
    ans += (l-a[-1-i]).abs
    l = a[-1-i]
  else
    ans += (r-a[-1-i]).abs
    r = a[-1-i]
  end
end
if n%2 == 1
  ans += [(l-a[n/2]).abs,(r-a[n/2]).abs].max
end
puts ans+a[-1]-a[0]