n = gets.chomp.to_i
a_arr = n.times.map { gets.chomp.to_i }.sort_by{|a| -a}
a_arr2 = a_arr.sort_by{|a| a}

def xxx(arr)
  a = arr.shift
  result = [a]
  b = arr.pop
  c = arr.pop
  result.unshift(b) unless b.nil?
  result.push(c) unless c.nil?
  while arr.length > 0 do
    a = arr.shift
    b = arr.pop
    if result[0] < result[-1]
      result.unshift(a)
      result.unshift(b) unless b.nil?
    else
      result.push(a)
      result.push(b) unless b.nil?
    end
  end
  ans = 0
  result.each_cons(2) do |a, b|
    ans += (a - b).abs
  end
  ans
end
puts [xxx(a_arr), xxx(a_arr2)].max
