import Data.List

main=do
    n <- getLine
    xs <- words <$> getLine
    print $ ans (read n :: Int) (sort (map (read::String -> Int) xs))

ans n xs = if (even n)
            then (sum $ drop (div (n) 2) xs)*2 - (last xs)
            else (sum $ drop (div (n) 2) xs)*2 - (last xs) - (head xs)