local n=io.read("n")
local a,a_map={},{}
for i=1,n do
    local x=io.read("n")
    a[i]=x
    a_map[x]=(a_map[x] or 0)+1
end
table.sort(a)

local counter=0
for i=n,2,-1 do
    local p=1
    while a[i]>=p do
        p=p*2
    end
    if a_map[a[i]] and a_map[a[i]]>0 then
        a_map[a[i]]=a_map[a[i]]-1
        if a_map[p-a[i]] and a_map[p-a[i]]>0 then
            a_map[p-a[i]]=a_map[p-a[i]]-1
            counter=counter+1
        end
    end
end
print(counter)