{-# LANGUAGE LambdaCase #-}

import           Data.Either
import           Data.Maybe

import qualified Data.Array.IArray   as I
import qualified Data.Array.MArray   as M

import           Data.Array.IO       (IOArray)
import           Data.Array.ST       (STArray)

import qualified Data.List           as L

import           Data.Bifunctor
import           Data.Function
import           Data.Monoid

import           Control.Applicative
import           Control.Monad
import           Control.Monad.ST
import           Data.Functor

main :: IO ()
main = do
    n <- read <$> getLine
    ls <- getSeq
    print $ solve ls n

getSeq :: Read a => IO [a]
getSeq = map read . words <$> getLine

solve :: [Int] -> Int -> Int
solve ls n = runST $ do
    sticks <- M.newArray (1, 100) (Right 0) :: ST s (STArray s Int (Either Int Int))
    forM_ ls $ \l -> M.readArray sticks l >>= M.writeArray sticks l . \case
      Right x -> Left    x
      Left  x -> Right $ x + l

    xs <- M.getAssocs sticks
    let f :: Either Int Int -> Sum Int
        f (Right x) = Sum x
        f (Left  x) = Sum x
        x = foldl (\x l -> case x of Right (y, m) -> Left (y + m); Left y -> Right (y, l))
          (Left $ getSum $ foldMap f $ map snd xs)
          $ map fst $ filter (isLeft . snd) xs
    return $ case x of
      Right (y, _) -> y
      Left   y     -> y
