n = gets.chop.to_i
as = []
n.times do
  as << gets.chop.to_i
end

as.sort!
ans = 0

tmp = [as.pop]
(n-1).times do |i|
  f_f = (as.first - tmp.first).abs
  f_l = (as.first - tmp.last).abs
  l_f = (as.last - tmp.first).abs
  l_l = (as.last - tmp.last).abs
  max_abs = [f_f, f_l, l_f, l_l].max
  if f_f == max_abs
    tmp.unshift(as.shift)
  elsif f_l == max_abs
    tmp.push(as.shift)
  elsif l_f == max_abs
    tmp.unshift(as.pop)
  elsif l_l == max_abs
    tmp.push(as.pop)
  end
  ans += max_abs
end
puts ans

# small_flag = true
# (n-1).times do |i|
#   if small_flag
#     num = as.shift
#     first = (num - tmp.first).abs
#     last = (num - tmp.last).abs
#     if first > last
#       tmp.unshift(num)
#       ans += first
#     else
#       tmp.push(num)
#       ans += last
#     end
#     small_flag = !(small_flag) if i.odd?
#   else
#     num = as.pop
#     first = (num - tmp.first).abs
#     last = (num - tmp.last).abs
#     if first > last
#       tmp.unshift(num)
#       ans += first
#     else
#       tmp.push(num)
#       ans += last
#     end
#     small_flag = !(small_flag) if i.odd?
#   end
# end