N = gets.to_i
A = N.times.map { gets.to_i }.sort
B = [A.shift]
(N - 1).times do |i|
  x = i.even? ? A.pop : A.shift
  if (B.last - x).abs < (B.first - x).abs
    B.unshift x
  else
    B.push x
  end
end
ans1 = 0
(N - 1).times  do |i|
  ans1 += (B[i] - B[i + 1]).abs
end
C = B.sort
D = [C.pop]
(N - 1).times do |i|
  x = i.even? ? C.shift : C.pop
  if (D.last - x).abs < (D.first - x).abs
    D.unshift x
  else
    D.push x
  end
end
ans2 = 0
(N - 1).times do |i|
  ans2 += (D[i] - D[i + 1]).abs
end
puts [ans1, ans2].max
