import Data.List

main :: IO ()
main = do
  getLine
  vs <- getInts
  print $ solve vs

getInts :: IO [Int]
getInts = map read . words <$> getLine

solve :: [Int] -> Int
solve vs = calc (count o) (count e)
  where (o,e) = sp vs

sp :: [Int] -> ([Int],[Int])
sp [] = ([],[])
sp (o:e:res) = let (o1,e1) = sp res in (o:o1,e:e1)

count :: [Int] -> [(Int,Int)]
count = map (\x -> (head x,length x)) . group . sort

calc :: [(Int,Int)] -> [(Int,Int)] -> Int
calc [] _ = 0
calc _ [] = 0
calc xs ys | o /= e = f os + f es
           | n > m = m + calc xs es
           | otherwise = n + calc os ys
  where
    f = sum . map snd
    (o,n,os) = select xs
    (e,m,es) = select ys

select :: [(Int,Int)] -> (Int,Int,[(Int,Int)])
select ((x0,n0):xs) = foldl' (\(x,n,xs) (y,m) -> if n > m then (x,n,(y,m):xs) else (y,m,(x,n):xs)) (x0,n0,[]) xs
