n,*a=$<.map &:to_i
a.sort!
p [
  (0...n).map{|i|i%2==0 ? a[i/2] : a[n-i/2-1]},
  (0...n).map{|i|i%2==1 ? a[i/2] : a[n-i/2-1]}
].map{|b|
  c=(0...n).map{|i|(b[i-1]-b[i]).abs}
  c.reduce(:+)-c.min
}.max