{-# 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 . either (Right . (l +)) Left

    xs <- M.getAssocs sticks
    return . getSum $
      (foldMap (either Sum Sum . snd) xs)
      <>
      (foldMap (Sum . fst . snd) . filter ((0 ==) . fst) . zip (cycle [0, 1]) $ filter (isLeft . snd) xs)
