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


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

result1 = [arr1.shift]
result2 = [arr2.pop]

i = 0

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

# puts result1.join(',')
# puts result2.join(',')

diff1 = 0
diff2 = 0
result1.each_cons(2) do |arr|
  diff1 += (arr[0] - arr[1]).abs
end

result2.each_cons(2) do |arr|
  diff2 += (arr[0] - arr[1]).abs
end

puts diff1 > diff2 ? diff1 : diff2

