n,*a=$<.map(&:to_i)
a.sort!
s = 0
res = -1
if n&1 == 1
  med = a[n/2]

  a = a[0,n/2].zip(a[n/2+1,n/2].reverse).flatten

  [a,a.rotate,a.rotate(-1)].each{|x|
    s = 0
    x.each_cons(2){|x,y|s += (x-y).abs}
    res = [res,(med-x[0]).abs+s,(x[-1]-med).abs+s].max
  }

else
  a = a[0,n/2].zip(a[n/2,n/2].reverse).flatten
  [a,a.rotate,a.rotate(-1)].each{|x|

    s = 0
    x.each_cons(2){|x,y|s += (x-y).abs}
    res = [res,s].max
  }
end
p res