import math

from collections import defaultdict

def larger_nibeki(i):

    return 2 ** len(format(i, 'b'))

N = int(eval(input()))

A = sorted(map(int, input().split()), reverse=True)

C = defaultdict(int)

for a in A:

    C[a] += 1

ans = 0

for a in A:

    if C[a] == 0:

        continue

    C[a] -= 1

    partner = larger_nibeki(a) - a

    if C[partner] > 0:

        ans += 1

        C[partner] -= 1

print(ans)
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 = (1 << (a.bit_length())) - a

    if C[partner] > 0:

        ans += 1

        C[partner] -= 1

print(ans)
import math
from collections import defaultdict


def larger_nibeki(i):
    return 2 ** len(format(i, "b"))


N = int(eval(input()))
A = sorted(map(int, input().split()), reverse=True)
C = defaultdict(int)
for a in A:
    C[a] += 1
ans = 0
for a in A:
    if C[a] == 0:
        continue
    C[a] -= 1
    partner = larger_nibeki(a) - a
    if C[partner] > 0:
        ans += 1
        C[partner] -= 1
print(ans)

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 = (1 << (a.bit_length())) - a
    if C[partner] > 0:
        ans += 1
        C[partner] -= 1
print(ans)

-import math -from collections import defaultdict +from collections import Counter - -def larger_nibeki(i): -    return 2 ** len(format(i, "b")) - - -N = int(eval(input())) -A = sorted(map(int, input().split()), reverse=True) -C = defaultdict(int) -for a in A: -    C[a] += 1 +N, *A = list(map(int, open(0).read().split())) +A.sort(reverse=True) +C = Counter(A) -    partner = larger_nibeki(a) - a +    partner = (1 << (a.bit_length())) - a