N = STDIN.gets.chomp.to_i
A = STDIN.readlines.map(&:to_i)


arr = A.sort
# puts arr.join(',')

result = [arr.shift]

i = 0

while arr.length > 0
  case i % 4
  when 0
    result.push(arr.pop)
  when 1
    result.unshift(arr.pop)
  when 2
    result.push(arr.shift)
  when 3
    result.unshift(arr.shift)
  end
  i += 1
  # puts result.join(',')
end

# puts result.join(',')


diff = 0
result.each_cons(2) do |arr|
  # puts arr
  diff += (arr[0] - arr[1]).abs
end

puts diff

