n = io.read("*n")
local a = {}
for i = 1, n do
  a[i] = io.read("*n")
end
table.sort(a)
if n % 2 == 0 then
  hn = n // 2
  ret = 0
  for i = 1, hn - 1 do
    ret = ret + a[n + 1 - i] - a[i]
  end
  ret = ret * 2 + a[hn + 1] - a[hn]
  print(ret)
else
  hn = n // 2
  ret1 = 0
  for i = 1, hn - 1 do
    ret1 = ret1 + a[n + 1 - i]
  end
  for i = 1, hn do
    ret1 = ret1 - a[i]
  end
  ret1 = 2 * ret1 + a[hn + 1] + a[hn + 2]
  ret2 = 0
  for i = 1, hn do
    ret2 = ret2 + a[n + 1 - i]
  end
  for i = 1, hn - 1 do
    ret2 = ret2 - a[i]
  end
  ret2 = 2 * ret2 - a[hn] - a[hn + 1]
  print(math.max(ret1, ret2))
end
