import Control.Monad
import Data.Maybe
import qualified Data.ByteString.Char8 as BS
import Data.List
import Data.Ord

readInt = fst . fromJust . BS.readInt
readIntList = map readInt . BS.words
getInt = readInt <$> BS.getLine
getIntList = readIntList <$> BS.getLine

main = do
    n <- getInt
    (os,es) <- f <$> getIntList
    print $ solve os es

f [] = ([],[])
f (a:b:xs) = let (as,bs) = f xs in (a:as, b:bs)

solve os es | snd o /= snd e = sumo + sume
            | null os' && null es' = fst o
            | otherwise = min (sum (map fst (o : (tail os'))) + sume) (sum (map fst (e : (tail es'))) + sumo)
    where (o:os') = fm os
          (e:es') = fm es
          sumo = sum $ map fst os'
          sume = sum $ map fst es'

fm xs = sortOn Down . map (\g -> (length g, head g)) . group $ sort xs