def solve(n,a,i,j,ans,last,nextSmall)
  while (n-i+j+1) > 0
    if n-i+j == 0
      ans += [(a[i]-last.min).abs,(a[i]-last.max).abs ].max
      i += 1
    elsif nextSmall
      ans += last[0] + last[1] - a[i] - a[i+1]
      last = [a[i],a[i+1]]
      i += 2
      nextSmall = false
    else
      ans += a[j] + a[j-1] - last[0] - last[1]
      last = [a[j],a[j-1]]
      j -= 2
      nextSmall = true
    end
  end
  return ans
end

n = gets.to_i
a = []
n.times do
  a << gets.to_i
end
a.sort!
if n == 2
  p a[1] - a[0]
elsif
  ans = []
  # 最小値を中央
  i,j = 1,-3
  v = a[-1] + a[-2] - a[0] * 2
  last = [a[-1],a[-2]]
  ans << solve(n,a,i,j,v,last,true)
  #最大値を中央
  i,j = 2,-2
  v = a[-1] * 2 - a[0] - a[1]
  last = [a[0],a[1]]
  ans << solve(n,a,i,j,v,last,false)
  p ans.max
end
