n = gets.to_i
a = n.times.map{gets.to_i}.sort

if n==2
  p (a[0]-a[1]).abs
  exit
end



def f n,a
  ans = 0
  l = 1
  r = n-3
  #
  x = [a[-1],a[-2]]
  ans += (a[-1]-a[0]).abs + (a[-2]-a[0]).abs 
  #
  (n-3).times.map{|i|
    x.sort!
    if (x[1]-a[l]).abs > (x[0]-a[r]).abs
      ans += (x[1]-a[l]).abs
      x[1] = a[l]
      l += 1
    else
      ans += (x[0]-a[r]).abs
      x[0] = a[r]
      r -= 1
    end
  }
  ans
end

p [f(n,a),f(n,a.reverse)].max