N = gets.to_i
A = N.times.map { gets.to_i }.sort

list = Array.new(N)
n = N / 2
list[n] = A[0]

a = -1
d = 1

fi = 1
bi = N - 1

(N - 1).times do |i|
  if d.even?
    list[n + a * d] = A[fi]
    fi += 1
  else
    list[n + a * d] = A[bi]
    bi -= 1
  end

  if i.odd?
    d += 1
  end

  a *= -1
end

ans = 0

list.each_cons(2) do |a, b|
  ans += (a - b).abs
end

puts ans
