import Data.List (sort,sortBy, group)
import Control.Arrow ((&&&))

main :: IO ()
main = do
  n <- read <$> getLine :: IO Int
  vs <- map read.words <$> getLine :: IO [Int]
  let odds = take 3 $ sortBy (flip compare) $ map (length&&&head) $ group $ sort $ map snd $ filter (odd.fst) $ zip [1..] vs
      evens = take 3 $ sortBy (flip compare) $ map (length&&&head) $ group $ sort $ map snd $ filter (even.fst) $ zip [1..] vs
      cs = [ lx+ly | (lx,x)<-odds, (ly,y)<-evens, x/=y ]
  if null cs
    then print (n`div`2)
    else print $ (+n) $ negate $ maximum cs
