from collections import Counter

N, *A = list(map(int, open(0).read().split()))

A.sort(reverse=True)

C = Counter(A)

ans = 0

for a in A:

    if C[a] == 0:

        continue

    C[a] -= 1

    partner = (2 ** (a.bit_length())) - a

    if C[partner] > 0:

        ans += 1

        C[partner] -= 1

print(ans)
def solve(C):

    ans = 0

    for a in sorted(C, reverse=True):

        if C[a] <= 0:

            continue

        ma = 1 << a.bit_length()

        b = ma - a

        if b in C and C[b] > 0:

            if a == b:

                pair = C[a] // 2

            else:

                pair = min(C[a], C[b])

                C[b] -= pair

            ans += pair

    return ans



from collections import defaultdict

N, *A = list(map(int, open(0).read().split()))

C_e = defaultdict(int)

C_o = defaultdict(int)

for a in A:

    if a % 2 == 0:

        C_e[a] += 1

    else:

        C_o[a] += 1

print((solve(C_e) + solve(C_o)))
from collections import Counter

N, *A = list(map(int, open(0).read().split()))
A.sort(reverse=True)
C = Counter(A)
ans = 0
for a in A:
    if C[a] == 0:
        continue
    C[a] -= 1
    partner = (2 ** (a.bit_length())) - a
    if C[partner] > 0:
        ans += 1
        C[partner] -= 1
print(ans)

def solve(C):
    ans = 0
    for a in sorted(C, reverse=True):
        if C[a] <= 0:
            continue
        ma = 1 << a.bit_length()
        b = ma - a
        if b in C and C[b] > 0:
            if a == b:
                pair = C[a] // 2
            else:
                pair = min(C[a], C[b])
                C[b] -= pair
            ans += pair
    return ans


from collections import defaultdict

N, *A = list(map(int, open(0).read().split()))
C_e = defaultdict(int)
C_o = defaultdict(int)
for a in A:
    if a % 2 == 0:
        C_e[a] += 1
    else:
        C_o[a] += 1
print((solve(C_e) + solve(C_o)))

-from collections import Counter +def solve(C): +    ans = 0 +    for a in sorted(C, reverse=True): +        if C[a] <= 0: +            continue +        ma = 1 << a.bit_length() +        b = ma - a +        if b in C and C[b] > 0: +            if a == b: +                pair = C[a] // 2 +            else: +                pair = min(C[a], C[b]) +                C[b] -= pair +            ans += pair +    return ans + + +from collections import defaultdict -A.sort(reverse=True) -C = Counter(A) -ans = 0 +C_e = defaultdict(int) +C_o = defaultdict(int) -    if C[a] == 0: -        continue -    C[a] -= 1 -    partner = (2 ** (a.bit_length())) - a -    if C[partner] > 0: -        ans += 1 -        C[partner] -= 1 -print(ans) +    if a % 2 == 0: +        C_e[a] += 1 +    else: +        C_o[a] += 1 +print((solve(C_e) + solve(C_o)))