n = gets.to_i
a = gets.split.map(&:to_i)
b = Hash.new(0)
a.each do |num|
    b[num] += 1
end
ans = 0
i = 32
b.keys.sort.reverse.each do |num|
    p = b[num]
    i.downto(1) do |j|
        q = b[2**j-num]
        next if q == 0
        r = (p < q ? p : q)
        if num*2 == 2**j
            r /= 2
        end
        ans += r
        p -= r
        b[2**j-num] -= r
        i = j if 2**j > num*2
        break if p == 0
    end
end
puts ans