import bisect

from collections import Counter

n = int(eval(input()))

A = list(map(int,input().split()))

A.sort()

C = Counter(A)

ans = 0

for i in range(n-1,-1,-1):

    temp = A[i]

    beki = 1

    while beki <= temp:

        beki *= 2

    counterpart = beki-temp

    if C[counterpart] > 0 and C[temp] > 0 and counterpart != temp:

        C[counterpart] -= 1

        C[temp] -= 1

        ans += 1

    elif counterpart == temp and C[counterpart] > 1:

        C[counterpart] -= 2

        ans += 1

print(ans)

from collections import Counter

n = int(eval(input()))

A = list(map(int,input().split()))

A.sort()

C = Counter(A)

ans = 0

for i in range(n-1,-1,-1):

    temp = A[i]

    beki = 1

    if C[temp] == 0:

        continue

    while beki <= temp:

        beki *= 2

    counterpart = beki-temp

    if C[counterpart] > 0 and C[temp] > 0 and counterpart != temp:

        C[counterpart] -= 1

        C[temp] -= 1

        ans += 1

    elif counterpart == temp and C[counterpart] > 1:

        C[counterpart] -= 2

        ans += 1

print(ans)

import bisect
from collections import Counter

n = int(eval(input()))
A = list(map(int, input().split()))
A.sort()
C = Counter(A)
ans = 0
for i in range(n - 1, -1, -1):
    temp = A[i]
    beki = 1
    while beki <= temp:
        beki *= 2
    counterpart = beki - temp
    if C[counterpart] > 0 and C[temp] > 0 and counterpart != temp:
        C[counterpart] -= 1
        C[temp] -= 1
        ans += 1
    elif counterpart == temp and C[counterpart] > 1:
        C[counterpart] -= 2
        ans += 1
print(ans)

from collections import Counter

n = int(eval(input()))
A = list(map(int, input().split()))
A.sort()
C = Counter(A)
ans = 0
for i in range(n - 1, -1, -1):
    temp = A[i]
    beki = 1
    if C[temp] == 0:
        continue
    while beki <= temp:
        beki *= 2
    counterpart = beki - temp
    if C[counterpart] > 0 and C[temp] > 0 and counterpart != temp:
        C[counterpart] -= 1
        C[temp] -= 1
        ans += 1
    elif counterpart == temp and C[counterpart] > 1:
        C[counterpart] -= 2
        ans += 1
print(ans)

-import bisect +    if C[temp] == 0: +        continue