def calc(k)
    i = 1
    loop do
        i *= 2
        break if k < i
    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|
    next if hash[ns[i]] <= 0
    hash[ns[i]] -= 1    
    pair = calc(ns[i])
    if hash[pair] > 0
        hash[pair] -= 1
        ans += 1
    end
end
puts ans