ary1 = []
ary2 = []
ans1 = 0
ans2 = 0

n, ary0* = gets.to_i.map &:to_i

ary0.sort!
ary1[0] = ary0[0]
ary2[0] = ary0[-1]

for i in 0 .. n-2

  case i%4
  when 0
    ary1.unshift( ary0[-(i/4*2+1)] )
    ary2.unshift( ary0[i/4*2] )
  when 1
    ary1 << ary0[-(i/4*2+2)]
    ary2 << ary0[i/4*2+1]
  when 2
    ary1.unshift( ary0[i/4*2+1] )
    ary2.unshift( ary0[-(i/4*2+2)] )
  when 3
    ary1 << ary0[i/4*2+2]
    ary2 << ary0[-(i/4*2+3)]
  end

end

for i in 0 .. n-2
  ans1 += ( ary1[i+1] - ary1[i] ).abs
  ans2 += ( ary2[i+1] - ary2[i] ).abs
end

puts ans1 > ans2 ? ans1 : ans2
