from bisect import bisect

N = int(eval(input()))

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

B = {}

for a in A:

    B[a] = B.get(a, 0) + 1

R = sorted(B.items())

C = []; D = []

for k, v in sorted(B.items()):

    C.append(k)

    D.append(v)

M = len(C)

j = 0

ans = 0

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

    if D[i] == 0:

        continue

    a = C[i]

    b = 2**(a).bit_length()

    j = bisect(C, b-a-1)

    if j < M and C[j] == b-a:

        if i == j:

            ans += D[i]//2

            D[i] %= 2

        else:

            c = min(D[i], D[j])

            ans += c

            D[i] -= c; D[j] -= c

print(ans)
from bisect import bisect

N = int(eval(input()))

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

B = {}

for a in A:

    B[a] = B.get(a, 0) + 1

R = sorted(B.items())

C = []; D = []

for k, v in sorted(B.items()):

    C.append(k)

    D.append(v)

M = len(C)

j = 0

ans = 0

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

    if D[i] == 0:

        continue

    a = C[i]

    b = 2**a.bit_length()

    j = bisect(C, b-a-1)

    if j < M and C[j] == b-a:

        if i == j:

            c = D[i]//2

        else:

            c = min(D[i], D[j])

        ans += c

        D[i] -= c; D[j] -= c

print(ans)
from bisect import bisect

N = int(eval(input()))
(*A,) = list(map(int, input().split()))
B = {}
for a in A:
    B[a] = B.get(a, 0) + 1
R = sorted(B.items())
C = []
D = []
for k, v in sorted(B.items()):
    C.append(k)
    D.append(v)
M = len(C)
j = 0
ans = 0
for i in range(M - 1, -1, -1):
    if D[i] == 0:
        continue
    a = C[i]
    b = 2 ** (a).bit_length()
    j = bisect(C, b - a - 1)
    if j < M and C[j] == b - a:
        if i == j:
            ans += D[i] // 2
            D[i] %= 2
        else:
            c = min(D[i], D[j])
            ans += c
            D[i] -= c
            D[j] -= c
print(ans)

from bisect import bisect

N = int(eval(input()))
(*A,) = list(map(int, input().split()))
B = {}
for a in A:
    B[a] = B.get(a, 0) + 1
R = sorted(B.items())
C = []
D = []
for k, v in sorted(B.items()):
    C.append(k)
    D.append(v)
M = len(C)
j = 0
ans = 0
for i in range(M - 1, -1, -1):
    if D[i] == 0:
        continue
    a = C[i]
    b = 2 ** a.bit_length()
    j = bisect(C, b - a - 1)
    if j < M and C[j] == b - a:
        if i == j:
            c = D[i] // 2
        else:
            c = min(D[i], D[j])
        ans += c
        D[i] -= c
        D[j] -= c
print(ans)

-    b = 2 ** (a).bit_length() +    b = 2 ** a.bit_length() -            ans += D[i] // 2 -            D[i] %= 2 +            c = D[i] // 2 -            ans += c -            D[i] -= c -            D[j] -= c +        ans += c +        D[i] -= c +        D[j] -= c