import Control.Arrow
import Data.List
import qualified Data.ByteString.Char8 as B

main :: IO ()
--main = getLine >> breads >>= print . solve 
main = readLn >>= main'
    where
        main' n = breads >>= print . solve n 

solve :: Int -> [Int] -> Int
solve n xs
    | all (\x -> head xs == x) (tail xs) = n `div` 2
    | otherwise = add (count ys) $ count zs
    where
        count = map (\x -> (head x, length x)) . group . sortBy (flip compare)
        add [(va, la)] [(vb, lb)]
            | va == vb = min la lb
            | otherwise = 0
        add a@[(va, _)] ((vb, lb) : bs)
            | va /= vb = add a bs
            | otherwise = lb
        add ((va, la) : as) b@[(vb, _)] 
            | va /= vb = add as b
            | otherwise = la
        add ((va, la) : as) ((vb, lb) : bs)
            | va /= vb = n - la - lb 
            | la > lb = add ((va, la) : as) bs
            | otherwise = add as $ (vb, lb) : bs
        (ys, zs) = fst $ foldl' ff (([], []), True) xs
        ff ((a, b), c) x
            | c = ((x : a, b), not c)
            | otherwise = ((a, x : b), not c)

breads :: IO [Int]
breads = unfoldr (\s -> second (maybe B.empty snd . B.uncons) <$> B.readInt s) <$> B.getLine