def calc(k)
    i = 2
    while k > i
        i **= 2
    end
    i - k
end

n = gets.to_i
ns = gets.split.map(&:to_i).sort

hash = Hash.new(0)
ns.each do |i|
    hash[i] += 1
end

ans = 0

(n-1).downto(0) do |i|
    while hash[ns[i]] > 0
        hash[ns[i]] -= 1    
        pair = calc(ns[i])
        if hash[pair] > 0
            hash[pair] -= 1
            ans += 1
        end
    end
end
puts ans