import qualified Data.IntMap as M

main :: IO ()
main = do
  _ <- getLine
  vs <- map read . words <$> getLine
  print $ solve vs

solve :: [Int] -> Int
solve vs = solve' as bs
  where
    (as, bs) = deal vs

deal :: [Int] -> ([Int], [Int])
deal [] = ([], [])
deal (x:y:zs) = (x:xs, y:ys)
  where
    (xs, ys) = deal zs

solve' :: [Int] -> [Int] -> Int
solve' as bs
  | ka0 /= kb0 = sum ma0 + sum mb0
  | null ma0 && null mb0 = va0 `min` vb0
  | null ma0 = vb0 + sum mb1
  | null mb0 = va0 + sum ma1
  | otherwise = (sum mb0 + va0 + sum ma1) `min` (sum ma0 + vb0 + sum mb1)
  where
    ((ka0, va0), ma0) = M.deleteFindMax $ count as
    ((ka1, va1), ma1) = M.deleteFindMax ma0
    ((kb0, vb0), mb0) = M.deleteFindMax $ count bs
    ((kb1, vb1), mb1) = M.deleteFindMax mb0

count :: [Int] -> M.IntMap Int
count [] = M.empty
count (x:xs) = M.insertWith (+) x 1 $ count xs