import Control.Monad
import Data.List
import Data.Maybe
import qualified Data.Map as Map
import Debug.Trace

main = do
    n <- readLn :: IO Int
    temp <- map read . words <$> getLine :: IO [Int]
    let ns =  reverse . sort $ temp
    -- print $ ns
    -- print $ group ns
    let inputs = map (\x -> let val = x !! 0 in (val, length x)) $ group ns
    let m = Map.fromList inputs
    -- print $ m
    -- print $ foldl greedyCnt (0,m) $ nub ns
    print $ fst . foldl greedyCnt (0,m) $ nub ns

greedyCnt :: (Int, Map.Map Int Int) -> Int -> (Int, Map.Map Int Int)
greedyCnt (n,m) val = case (Map.lookup pair m) of 
    -- Just x -> trace ("value " ++  show pair ++ " has Just x : " ++ show x ++ " at " ++ show val) $ (n+x, m)
    Just numOfPair -> let dif = numOfPair - numOfVal in case dif of 
        hoge
            | hoge < 0 -> (n+numOfPair, Map.delete pair m)
        -- corner case 
            | hoge == 0 && isPow2 val -> (n+ numOfVal `div` 2, m)
            | otherwise -> (n+numOfVal, Map.insert pair dif $ Map.delete pair m)
    Nothing -> (n,m)
    where 
        numOfVal = fromJust $ Map.lookup val m
        pair = 2 ^ ceiling (logBase 2 val) - val

isPow2 :: Int -> Bool
isPow2 val
    | val == 1 = True
    | amari == 0 = isPow2 (val `div` 2)
    | amari == 1 = False
    where
        amari = val `mod` 2 

-- traceはおそらくその文全体が式として評価されたときに動く
-- 問題としては，最適状態が達成されたときの状況を考えるのが重要