import Control.Applicative
import Control.Monad
import qualified Data.ByteString.Char8 as B
import Data.Maybe (fromJust)
import Data.List (sort)
import qualified Data.Sequence as S
import Text.Printf
import Debug.Trace

getInts :: IO [Int]
getInts = map (fst . fromJust . B.readInt) . B.words <$> B.getLine

hd s = s `S.index` 0
tl s = S.drop 1 s
lst s = s `S.index` (S.length s - 1)
ini s = S.take (S.length s - 1) s

solve (s,acc)
  | S.length s <= 1 = acc
  | otherwise = solve $ eat $ (dropb $ dropf s, acc)
  where
    dropf s
      | S.length s <= 1 = s
      | hd s == (hd . tl) s = s
      | otherwise = dropf $ S.drop 1 s
    dropb s
      | S.length s <= 1 = s
      | lst s == (lst . ini) s = s
      | otherwise = dropb $ ini s
    eat (s,acc)
      | S.length s <= 1 = (s,acc)
      | otherwise = ((ini . tl) s, acc+2)

main = do
  [n] <-getInts
  s <- S.fromList . sort <$> getInts
  print $ n - solve (s,0)
  
