import Data.List
import qualified Data.Map as Map

scan :: [Int] -> Int
scan l = iter 0 (load l) where
    iter c m
        | Map.null m = c
        | otherwise  =
            if Map.member y m1
                then iter (c+1) (remove y m1)
                else iter c m1
                where
                    (x,_) = Map.findMax m
                    m1 = remove x m
                    y = iter 2 where
                            iter p
                                | x < p = p - x
                                | otherwise = iter (p*2)
    load = iter Map.empty where
        iter m [] = m :: Map.Map Int Int
        iter m (x:xs) = case Map.lookup x m of
            Just n  -> iter (Map.update (\n -> Just (n+1)) x m) xs 
            Nothing -> iter (Map.insert x 1 m) xs
    remove x m = case Map.lookup x m of
        Just 1  -> Map.delete x m
        Just n  -> Map.update (\n -> Just (n-1)) x m
        Nothing -> m
    
readData :: IO [Int]
readData = do
    line1 <- getLine
    let xs = map (\x -> read x :: Int) (words line1)
    return xs

main :: IO() 
main = do
    n  <- readLn :: IO Int
    la <- readData
    let ans = scan la
    print ans