{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE TupleSections #-}
{-# LANGUAGE ExplicitForAll #-}
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE MultiWayIf #-}
{-# LANGUAGE Unsafe #-}

import Data.Bits
import Data.List
import qualified Data.ByteString.Char8 as BS
import qualified Data.ByteString.Lazy.Char8 as BSL
import Data.IntMap.Strict (IntMap)
import qualified Data.IntMap.Strict as IMS
import Data.IntSet (IntSet)
import qualified Data.IntSet as IS
import qualified Data.Array.IArray as A
import qualified Data.Array.MArray.Safe as A
-- import qualified Data.Array.MArray as A
import Data.Array (Array)
import Data.Array.Unboxed (UArray)
import Data.Array.IArray (IArray)
import Data.Array.MArray.Safe (MArray)
import Data.Array.IO.Safe (IOArray, IOUArray)
import Data.Array.ST.Safe (STArray, STUArray, runSTArray, runSTUArray)
import qualified Data.Vector.Unboxed as VU
import qualified Data.Vector.Unboxed.Mutable as VUM
import Control.Monad
import Control.Monad.ST
-- import Control.Monad.ST.Safe
import Control.Applicative
import Data.Maybe
import Data.Tuple
import Data.Ord
import Control.Monad.State.Strict
import Data.Int
import System.IO

main :: IO ()
main = do
  n <- read <$> getLine :: IO Int
  as <- IMS.fromListWith (+)  . map (,1::Int) .
        unfoldr (BS.readInt . BS.dropWhile (==' ')) <$>
          BS.getLine
  print $ query as 0

counterpart :: Int -> Int
counterpart larger = bit highestplus1 - larger
  where
    highestplus1 = finiteBitSize larger - countLeadingZeros larger

query :: IntMap Int -> Int -> Int
query !as !acc | IMS.null as = acc
query !as !acc
  | k == k' = query as' (acc + count1 `div` 2)
  | otherwise = query rest $ acc + min count1 count2
  where
    ((k, count1), as') = IMS.deleteFindMax as
    k' = counterpart k
    (cnt2, rest) = IMS.updateLookupWithKey
                   (\_ count2 -> if count1 < count2
                                 then Just (count2 - count1)
                                 else Nothing)
                   k' as'
    count2 = fromMaybe 0 cnt2
