import Data.List
main = do
    (n:as) <- map read . words <$> getContents :: IO [Int]
    print $ if n == 2 then maximum as - minimum as else max (solve1 as) (solve2 as)

solve1 as | odd n =  sum (map (*2) asl) + sum (map (*(-2)) ass) + m2 + m1
          | even n = sum (map (*2) asl) + sum (map (*(-2)) ass) + m2 - m1
    where n = length as
          as' = sort as
          ns = n `div` 2
          ass = take ns as'
          (m1:m2:_) = take 2 $ drop ns as'
          asl = drop (ns + 2) as'

solve2 as | odd n =  sum (map (*2) asl) + sum (map (*(-2)) ass) - m2 - m1
          | even n = sum (map (*2) asl) + sum (map (*(-2)) ass) + m2 - m1
    where n = length as
          as' = sort as
          ns = n `div` 2 - 1
          ass = take ns as'
          (m1:m2:_) = take 2 $ drop ns as'
          asl = drop (ns + 2) as'