import qualified Data.Text.Lazy as T
import qualified Data.Text.Lazy.IO as T
import qualified Data.Text.Lazy.Read as T
import Data.List (sortBy)

main :: IO ()
main = do
  let
    f :: Int -> [Int]
    f = (:) <$> id <*> pure
  n <- unsafeTextToInt <$> T.getLine :: IO Int
  a : as <- sortBy (flip compare) . map unsafeTextToInt . T.words <$> T.getContents :: IO [Int]
  print . sum . (a :) . take (n - 2) . concatMap f $ as

unsafeTextToInt :: T.Text -> Int
unsafeTextToInt s = case T.signed T.decimal s of
  Right (n, _) -> n
{-# INLINE unsafeTextToInt #-}
