N = gets.to_i
as = gets.split.map(&:to_i)

mp = Hash.new(0)
as.each do |a|
    mp[a] += 1
end

ans = 0
mp.keys.sort.reverse.each do |a|
    30.downto(0) do |i|
        break if mp[a] == 0
        b = (1<<i) - a
        next if mp[b] == 0
        if a == b
            add = mp[a]/2
        else
            add = mp[a] < mp[b] ? mp[a] : mp[b]
        end
        ans += add
        mp[a] -= add
        mp[b] -= add
    end
end
puts ans