import Data.List
import qualified Data.IntSet as S
import qualified Data.ByteString.Char8 as B

p2s = map (2^) [1..31]
main=do
    _<-getLine
    as<-S.fromList.unfoldr (B.readInt.B.dropWhile(==' '))<$>B.getLine
    print $ sol 0 as
sol c as
    | S.null as = c
    | otherwise = if S.member (fc-m) b
                    then sol (c+1) (S.delete (fc-m) b)
                    else sol c b
    where
        (m,b) = S.deleteFindMax as
        fc = head $ dropWhile (<m) p2s
