import bisect

from collections import Counter



N = int(eval(input()))

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

A.sort()





two_bekis = []

tmp = 1

while tmp < 2*10**9:

    two_bekis.append(tmp)

    tmp *= 2



ans = 0

cnt = Counter(A)

seta = set(A)

for i, a in enumerate(reversed(A)):

    idx = bisect.bisect_right(two_bekis, a)

    two_beki = two_bekis[idx]

    b = two_beki - a

    if b not in seta:

        continue



    if a == b and cnt[a] >= 2:

        ans += 1

        cnt[a] -= 2

    elif a != b and cnt[a] >= 1 and cnt[b] >= 1:

        ans += 1

        cnt[a] -= 1

        cnt[b] -= 1

print(ans)

import bisect

from collections import Counter



N = int(eval(input()))

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

A.sort()



two_bekis = [2**i for i in range(31)]



ans = 0

cnt = Counter(A)

seta = set(A)

for i, a in enumerate(reversed(A)):

    b = two_bekis[bisect.bisect_right(two_bekis, a)] - a

    if b not in seta:

        continue



    if a == b and cnt[a] >= 2:

        ans += 1

        cnt[a] -= 2

    elif a != b and cnt[a] >= 1 and cnt[b] >= 1:

        ans += 1

        cnt[a] -= 1

        cnt[b] -= 1

print(ans)

import bisect
from collections import Counter

N = int(eval(input()))
A = list(map(int, input().split()))
A.sort()
two_bekis = []
tmp = 1
while tmp < 2 * 10**9:
    two_bekis.append(tmp)
    tmp *= 2
ans = 0
cnt = Counter(A)
seta = set(A)
for i, a in enumerate(reversed(A)):
    idx = bisect.bisect_right(two_bekis, a)
    two_beki = two_bekis[idx]
    b = two_beki - a
    if b not in seta:
        continue
    if a == b and cnt[a] >= 2:
        ans += 1
        cnt[a] -= 2
    elif a != b and cnt[a] >= 1 and cnt[b] >= 1:
        ans += 1
        cnt[a] -= 1
        cnt[b] -= 1
print(ans)

import bisect
from collections import Counter

N = int(eval(input()))
A = list(map(int, input().split()))
A.sort()
two_bekis = [2**i for i in range(31)]
ans = 0
cnt = Counter(A)
seta = set(A)
for i, a in enumerate(reversed(A)):
    b = two_bekis[bisect.bisect_right(two_bekis, a)] - a
    if b not in seta:
        continue
    if a == b and cnt[a] >= 2:
        ans += 1
        cnt[a] -= 2
    elif a != b and cnt[a] >= 1 and cnt[b] >= 1:
        ans += 1
        cnt[a] -= 1
        cnt[b] -= 1
print(ans)

-two_bekis = [] -tmp = 1 -while tmp < 2 * 10**9: -    two_bekis.append(tmp) -    tmp *= 2 +two_bekis = [2**i for i in range(31)] -    idx = bisect.bisect_right(two_bekis, a) -    two_beki = two_bekis[idx] -    b = two_beki - a +    b = two_bekis[bisect.bisect_right(two_bekis, a)] - a