N,*as=`dd`.split.map(&:to_i)
as.sort!
def r(as)
  bs = (0...N).map{|i| as[i%2 == 0 ? i/2 : -(i+1)/2] }
  cs = (0...N).map{ |i| (bs[(i+1)%N] - bs[i]).abs }
  s = cs.inject(:+)
  cs.map{ |c| s - c }.max
end

p [r(as), r(as.reverse)].max