N = gets.to_i
A = Array.new(N)
N.times do |n|
  A[n] = gets.to_i
end

A.sort!

a = A.clone

size = A.size

is_even = (size % 2 == 0)

if is_even
  c = size / 2
  r = c
  l = c-1
  c.times do |i|
    if i % 2 == 0
      a[r] = A.pop
      a[l] = A.shift
      r += 1
      l -= 1
    else
      a[r] = A.shift
      a[l] = A.pop
      r += 1
      l -= 1
    end
  end
else
  c = size / 2
  r = c+1
  l = c-1
  a[c] = A.shift
  c.times do |i|
    a[r] = A.pop
    a[l] = A.pop
    r += 1
    l -= 1
  end
end

sum = 0
(1...size).each do |i|
  sum += (a[i] - a[i-1]).abs
end

puts sum
