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

p2s = map (2^) [1..31]
main=do
    _<-getLine
    (a:as)<-reverse.sort.unfoldr (B.readInt.B.dropWhile(==' '))<$>B.getLine
    let m = foldl' (\m x->M.insert x 1 m) M.empty $ filter (>0) $ map (\x->x-a) p2s
    let (_,c) = foldl' f (m,0) as
    print c
f (m,c) a = case M.lookup a m of
    Nothing -> (im m a, c)
    Just k|k>0 -> (rm m a, c+1)
    _ -> (im m a, c)
im m a = foldl' (\m x->M.insertWith(+)x 1 m) m $ filter (<a) $ map (\x->x-a) p2s

rm m a = foldl' g m $ filter (<v) $ map (\x->x-v) p2s
    where
        k = flip (-) a $  head $ dropWhile (<a) p2s
        v = if k==0 then a else k
g m a = case M.lookup a m of
    Nothing -> m
    Just k -> M.insert a (max 0 (k-1)) m