from collections import Counter



N = int(eval(input()))

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

A.sort(reverse=True)

c = Counter(A)



ans = 0

for a in A:

    b = (1 << a.bit_length()) - a

    if a == b and c[a] > 1:

        c[a] -= 2

        ans += 1

    elif a != b and c[a] > 0 and c[b] > 0:

        c[a] -= 1

        c[b] -= 1

        ans += 1



print(ans)
from collections import Counter



N = int(eval(input()))

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

A.sort(reverse=True)

c = Counter(A)



ans = 0

for a in A:

    b = (1 << a.bit_length()) - a

    if b in list(c.keys()):

        if a == b and c[a] > 1:

            c[a] -= 2

            ans += 1

        elif a != b and c[a] > 0 and c[b] > 0:

            c[a] -= 1

            c[b] -= 1

            ans += 1



print(ans)
from collections import Counter

N = int(eval(input()))
A = list(map(int, input().split()))
A.sort(reverse=True)
c = Counter(A)
ans = 0
for a in A:
    b = (1 << a.bit_length()) - a
    if a == b and c[a] > 1:
        c[a] -= 2
        ans += 1
    elif a != b and c[a] > 0 and c[b] > 0:
        c[a] -= 1
        c[b] -= 1
        ans += 1
print(ans)

from collections import Counter

N = int(eval(input()))
A = list(map(int, input().split()))
A.sort(reverse=True)
c = Counter(A)
ans = 0
for a in A:
    b = (1 << a.bit_length()) - a
    if b in list(c.keys()):
        if a == b and c[a] > 1:
            c[a] -= 2
            ans += 1
        elif a != b and c[a] > 0 and c[b] > 0:
            c[a] -= 1
            c[b] -= 1
            ans += 1
print(ans)

-    if a == b and c[a] > 1: -        c[a] -= 2 -        ans += 1 -    elif a != b and c[a] > 0 and c[b] > 0: -        c[a] -= 1 -        c[b] -= 1 -        ans += 1 +    if b in list(c.keys()): +        if a == b and c[a] > 1: +            c[a] -= 2 +            ans += 1 +        elif a != b and c[a] > 0 and c[b] > 0: +            c[a] -= 1 +            c[b] -= 1 +            ans += 1