import Control.Monad
import Data.List
import Data.Maybe
import qualified Data.ByteString.Char8 as B

main = do
    n<-readLn::IO Int
    as<-replicateM n $ fst.fromJust.B.readInt <$> B.getLine ::IO[Int]
    print $ sol n $ sort as
--
sol n as
    | n==2 = a2-a1
    | n==3 = max (b3*2-b2-b1) (b3+b2-b1*2)
    | even n = sum e4*2+e3-e2-sum e1*2
    | odd n = max (sum oa4*2+oa3+oa2-sum oa1*2) (sum ob4*2-ob3-ob2-sum ob1*2)
    where
        [a1,a2] = as
        [b1,b2,b3] = as
        (e1,e2:e3:e4) = splitAt ((n-2)`div`2) as
        (oa1,oa2:oa3:oa4) = splitAt ((n-1)`div`2) as
        (ob1,ob2:ob3:ob4) = splitAt ((n-2)`div`2) as