import Data.List

main = do
    (n:as) <- map read . words <$> getContents :: IO [Int]
    let (small,large) = splitAt ((n+1) `div` 2) $ sort as
    let ss = sorting True [] [] (reverse small)
        ls = sorting True [] [] large
        ans1 = ds $ marge ss ls
        ans2 = ds $ marge ss (reverse ls)
        ans3 = ds $ marge ls ss
        ans4 = ds $ marge ls (reverse ss)
    print $ maximum [ans1, ans2, ans3, ans4]

sorting b ls rs (s:[]) = ls ++ [s] ++ (reverse rs)
sorting b ls rs (s:ss) | b = sorting False (s:ls) rs ss
                       | otherwise = sorting True ls (s:rs) ss

marge ls rs = concat $ transpose [ls,rs]

ds xs = sum $ zipWith (\a b -> abs (a - b)) xs (tail xs)