import Data.List

scan :: [Int] -> Int
scan l = iter 0 sl where
    iter c [] = c
    iter c (x:xs) = case exist (f x) xs of
        Just nl -> iter (c+1) nl
        Nothing -> iter c xs
        where
            exist y = iter [] where
                iter _ [] = Nothing
                iter ac (x:xs)
                    | x == y = Just (join ac xs)
                    | otherwise = iter (x:ac) xs
            f x = iter 2 where
                iter p
                    | x < p = p - x
                    | otherwise = iter (p*2)
            join [] ys = ys
            join (x:xs) ys = join xs (x:ys)
             
    sl = reverse (sort l)

    
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