import Data.List
import qualified Data.IntMap.Strict as M
import qualified Data.ByteString.Char8 as B

p2s = map (2^) [1..32]
main=do
    _<-getLine
    as<-foldl' (\m a->M.insertWith (+) a 1 m) M.empty.unfoldr (B.readInt.B.dropWhile(==' '))<$>B.getLine
    print $ sum $ unfoldr s as
s as
    | M.null as = Nothing
    | fcc == k  = Just(a`div`2, as')
    | otherwise = case M.lookup fcc as' of
        Nothing -> Just(0, as')
        Just b  -> if b<=a
                    then Just(b, M.delete fcc as')
                    else Just(a, M.insert fcc (b-a) as')
    where
        ((k,a), as') = M.deleteFindMax as
        fc = head $ dropWhile (<k) p2s
        fcc = if fc==k then k else fc-k