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)<-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 -> (M.insertWith(+)a (-1) m, c+1)
im m a = foldl' (\m x->M.insertWith(+)a 1 m) m $ filter (>0) $ map (\x->x-a) p2s