import Control.Monad
import Data.List
import Data.Ord
import qualified Data.ByteString.Char8 as B
import qualified Data.IntMap as M

mf n Nothing = Just n
mf n (Just a) = Just (n+a)

main = do
    n<-readLn::IO Int
    vs<-unfoldr (B.readInt.B.dropWhile(==' '))<$>B.getLine::IO[Int]
    print $ sol vs
---
sol vs
    | length mo == 1 && length me == 1 && (fst.head) mo /= (fst.head) me = 0
    | length mo == 1 && length me == 1 = min (length os) (length es)
    | length mo == 1 && (fst.head) mo == (fst.head) me = length es - snd (me !! 1)
    | length mo == 1 = length me - (snd.head) me
    | length me == 1 && (fst.head) me == (fst.head) mo = length os - snd (mo !! 1)
    | length me == 1 = length os - (snd.head) mo
    | (fst.head) me /= (fst.head) mo = (length os) - (snd.head) mo + (length es) - (snd.head) me
    | otherwise = max ((length os)-(snd.head)mo + (length es) - (snd (me!!1))) ((length es)-(snd.head)me+(length os)-(snd(mo!!1)))
    where
        os = map fst $ filter (odd.snd) $ zip vs [1..]
        es = map fst $ filter (even.snd) $ zip vs [1..]
        mo = sortBy (flip $ comparing snd) $ M.toList $ foldl' (flip (M.alter (mf 1))) M.empty os
        me = sortBy (flip $ comparing snd) $ M.toList $ foldl' (flip (M.alter (mf 1))) M.empty es
