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

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

a = -1
d = 1

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

  if i.even?
    d += 1
  end

  a *= -1
end

ans = 0

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

puts ans
