import sys

from collections import Counter



read = sys.stdin.read

readline = sys.stdin.readline



N, *A = list(map(int, read().split()))



A.sort()

a = Counter(A)

answer = 0

# 可能な最大の2冪

limit = 1 << ((2 * 10 ** 9 + 1).bit_length() - 1)



while A:

    n = A.pop()

    if a[n] == 0:

        continue



    a[n] -= 1

    s = limit

    while n < s:

        b = s - n

        if a[b] > 0:

            answer += 1

            a[b] -= 1

            break

        s //= 2



print(answer)

import sys

from collections import Counter



read = sys.stdin.read

readline = sys.stdin.readline



N, *A = list(map(int, read().split()))



A.sort()

a = Counter(A)

answer = 0





while A:

    n = A.pop()

    if a[n] == 0:

        continue



    a[n] -= 1

    # 実現可能な最大の2冪

    s = 1 << (2 * n).bit_length()

    while n < s:

        b = s - n

        if a[b] > 0:

            answer += 1

            a[b] -= 1

            break

        s //= 2



print(answer)

import sys
from collections import Counter

read = sys.stdin.read
readline = sys.stdin.readline
N, *A = list(map(int, read().split()))
A.sort()
a = Counter(A)
answer = 0
# 可能な最大の2冪
limit = 1 << ((2 * 10**9 + 1).bit_length() - 1)
while A:
    n = A.pop()
    if a[n] == 0:
        continue
    a[n] -= 1
    s = limit
    while n < s:
        b = s - n
        if a[b] > 0:
            answer += 1
            a[b] -= 1
            break
        s //= 2
print(answer)

import sys
from collections import Counter

read = sys.stdin.read
readline = sys.stdin.readline
N, *A = list(map(int, read().split()))
A.sort()
a = Counter(A)
answer = 0
while A:
    n = A.pop()
    if a[n] == 0:
        continue
    a[n] -= 1
    # 実現可能な最大の2冪
    s = 1 << (2 * n).bit_length()
    while n < s:
        b = s - n
        if a[b] > 0:
            answer += 1
            a[b] -= 1
            break
        s //= 2
print(answer)

-# 可能な最大の2冪 -limit = 1 << ((2 * 10**9 + 1).bit_length() - 1) -    s = limit +    # 実現可能な最大の2冪 +    s = 1 << (2 * n).bit_length()