import qualified Data.ByteString.Char8 as C
import Data.Maybe ( fromJust )
import Data.List ( sortBy )

readInt :: IO Int
readInt = fst . fromJust . C.readInt <$> C.getLine

readInts :: IO [Int]
readInts = map (fst . fromJust . C.readInt) . C.words <$> C.getLine

main :: IO ()
main = do
  n   <- readInt
  ass <- readInts
  print $ f n ass

sort' :: [Int] -> [Int]
sort' = sortBy (flip compare)

f :: Int -> [Int] -> Int
f n ass = h (sort' ass) n 0

h :: [Int] -> Int -> Int -> Int
h _        0 acc = acc
h (_:b:bs) n acc = h bs (n-1) (b+acc)
