n = gets.to_i
a = gets.split.map(&:to_i)
b = Hash.new(0)
p = 34
n.times do |i|
    b[a[i]] += 1
end
c = b.keys.sort.reverse
ans = 0
c.each do |i|
    while i*2 < 1 << p
        p -= 1
    end
    if b[i] > 0
        if i*2 == (1 << p)
            ans += b[i]/2
        else
            m = (b[i] < b[(1 << p)-i] ? b[i] : b[(1 << p)-i])
            ans += m
            b[(1 << p)-i] -= m
        end
    end
end
p ans