{-# LANGUAGE BangPatterns #-}

import Data.Bits
import Data.List
import Data.IntMap.Strict (IntMap)
import qualified Data.IntMap.Strict as IntMap
import qualified Data.ByteString.Char8 as B

freqMapWithParity :: [Int] -> (IntMap Int, IntMap Int)
freqMapWithParity
  = foldl' (\(!now,!prev) k -> (prev, IntMap.insertWith (+) k 1 now))
    $ (IntMap.empty, IntMap.empty)

obtainFreq :: IntMap Int -> (Int, Int, Int, Int)
obtainFreq = IntMap.foldlWithKey' loop (minBound, 0, minBound, 0)
  where
    loop (!v1, !n1, !v2, !n2) !v !n
      | n >= n1   = (v,  n,  v1, n1)
      | n >= n2   = (v1, n1, v,  n)
      | otherwise = (v1, n1, v2, n2)

chooseBest ::
  (Int, Int, Int, Int) -> (Int, Int, Int, Int) -> ((Int, Int), (Int, Int))
chooseBest (!lv1, !ln1, !lv2, !ln2) (!rv1, !rn1, !rv2, !rn2)
  | lv1 /= rv1             = ((lv1, ln1), (rv1, rn1))
  | ln1 + rn2 >= ln2 + rn1 = ((lv1, ln1), (rv2, rn2))
  | otherwise              = ((lv2, ln2), (rv1, rn1))

query :: Int -> [Int] -> Int
query n vs = n - ln - rn
  where
    (l,r) = freqMapWithParity vs
    lf = obtainFreq l
    rf = obtainFreq r
    ((_, ln), (_, rn)) = chooseBest lf rf

main :: IO ()
main = do
  n <- read <$> getLine
  vs <- unfoldr (B.readInt . B.dropWhile (== ' ')) <$> B.getLine
  putStrLn $ show $ query n vs