local 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
  local sum = 0
  local half = n / 2
  for i = 1, half do
    sum = sum - a[i] + a[half + i]
  end
  sum = sum * 2 - a[half + 1] + a[half]
  print(sum)
else
  local sum = 0
  local half = (n - 1) / 2
  for i = 1, half do
    sum = sum - a[i]
  end
  for i = half + 1, n do
    sum = sum + a[i]
  end
  sum = sum * 2 - a[half + 1] - a[half + 2]
  local cand = sum
  sum = 0
  half = (n + 1) / 2
  for i = 1, half do
    sum = sum - a[i]
  end
  for i = half + 1, n do
    sum = sum + a[i]
  end
  sum = sum * 2 + a[half - 1] + a[half]
  print(math.max(cand, sum))
end
