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

def xxx(arr)
  a = arr.shift
  result = [a]
  while arr.length > 0 do
    b = arr.pop
    if (result[0] - b).abs > (result[-1] - b).abs
      result.unshift(b)
    else
      result.push(b)
    end
    break if arr.length == 0
    c = arr.shift
    if (result[0] - c).abs > (result[-1] - c).abs
      result.unshift(c)
    else
      result.push(c)
    end
  end
  ans = 0
  result.each_cons(2) do |r1, r2|
    ans += (r1 - r2).abs
  end
  ans
end

puts [xxx(a_arr), xxx(a_arr2)].max