import Data.List
import Data.Ord

type Value = Int
type Point = Int

calcPoint :: [Value] -> Point
calcPoint [a] = 0
calcPoint [a, b] = a
calcPoint (a:b:cs) = a + calcPoint (b:cs)

main :: IO ()
main = do
  _ <- getLine
  friendnesses <- sortOn Down . map read . words <$> getLine :: IO [Int]
  let sorted = foldl (flip insertPoint) [] friendnesses
  -- print sorted
  print $ calcPoint friendnesses
