local N = io.read("n")
local A = {}
local S = {}
for i=1,N do
    local n = io.read("n")
    A[i] = n
    if not S[n] then
        S[n] = 0
    end
    S[n] = S[n] + 1
end
table.sort(A)

local function target(r)
    local r2 = r + 1
    local t = 2
    while t < r2 do
        t = t * 2
    end
    return t, t - r
end

local ans = 0
for i=N,2,-1 do
    local r = A[i]
    local t, c = target(r)
    local hit = false
    if S[r] > 0 then
        S[r] = S[r] - 1
        if S[c] and S[c] > 0 then
            ans = ans + 1
            S[c] = S[c] - 1
            hit = true
        end
    end
    --print(r, t, c, hit)
end
print(ans)