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)
  ans = 0
  a = arr.shift
  result = [a]
  while arr.length > 0 do
    b = arr.pop
    l_diff = (result[0] - b).abs
    r_diff = (result[-1] - b).abs
    if l_diff > r_diff
      result.unshift(b)
      ans += l_diff
    else
      result.push(b)
      ans += r_diff
    end

    break if arr.length == 0
    c = arr.shift
    l_diff = (result[0] - c).abs
    r_diff = (result[-1] - c).abs
    if l_diff > r_diff
      result.unshift(c)
      ans += l_diff
    else
      result.push(c)
      ans += r_diff
    end
  end
  ans
end

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