import sys

F = sys.stdin

N = int(F.readline().strip("\n"))

A = list(map(int, F.readline().strip("\n").split()))

A.sort()



pair_sum = 0

A_dict = dict()

for a in A:

    if a not in A_dict: A_dict[a] = 1

    else: A_dict[a] += 1



for i in reversed(list(range(1, N))):

    if A_dict[A[i]] > 0:

        nowA = A[i]

        temp_a = A[i]

        k = 0

        while temp_a > 0:

            temp_a //= 2

            k += 1

        opposite = 2 ** k - nowA

        if opposite in A_dict:

            if opposite == nowA and A_dict[opposite] > 1:

                pair_sum += 1

                A_dict[opposite] -= 2

            elif opposite != nowA and A_dict[opposite] > 0:

                pair_sum += 1

                A_dict[opposite] -= 1

                A_dict[nowA] -= 1



print(pair_sum)
import sys



def solve():

    input = sys.stdin.readline

    N = int(eval(input()))

    A = [int(a) for a in input().split()]

    A.sort()

    nDict = dict()

    for i, a in enumerate(A):

        if a in nDict: nDict[a] += 1

        else: nDict[a] = 1



    count = 0

    for i in reversed(list(range(N))):

        if nDict[A[i]] == 0: continue

        k = 1

        while k <= A[i]: k <<= 1

        if k - A[i] in nDict:

            if k - A[i] == A[i] and nDict[k - A[i]] > 1:

                count += 1

                nDict[A[i]] -= 2

            elif k - A[i] != A[i] and nDict[k - A[i]] > 0:

                count += 1

                nDict[A[i]] -= 1

                nDict[k - A[i]] -= 1

    print(count)

        



    return 0



if __name__ == "__main__":

    solve()
import sys

F = sys.stdin
N = int(F.readline().strip("\n"))
A = list(map(int, F.readline().strip("\n").split()))
A.sort()
pair_sum = 0
A_dict = dict()
for a in A:
    if a not in A_dict:
        A_dict[a] = 1
    else:
        A_dict[a] += 1
for i in reversed(list(range(1, N))):
    if A_dict[A[i]] > 0:
        nowA = A[i]
        temp_a = A[i]
        k = 0
        while temp_a > 0:
            temp_a //= 2
            k += 1
        opposite = 2**k - nowA
        if opposite in A_dict:
            if opposite == nowA and A_dict[opposite] > 1:
                pair_sum += 1
                A_dict[opposite] -= 2
            elif opposite != nowA and A_dict[opposite] > 0:
                pair_sum += 1
                A_dict[opposite] -= 1
                A_dict[nowA] -= 1
print(pair_sum)

import sys


def solve():
    input = sys.stdin.readline
    N = int(eval(input()))
    A = [int(a) for a in input().split()]
    A.sort()
    nDict = dict()
    for i, a in enumerate(A):
        if a in nDict:
            nDict[a] += 1
        else:
            nDict[a] = 1
    count = 0
    for i in reversed(list(range(N))):
        if nDict[A[i]] == 0:
            continue
        k = 1
        while k <= A[i]:
            k <<= 1
        if k - A[i] in nDict:
            if k - A[i] == A[i] and nDict[k - A[i]] > 1:
                count += 1
                nDict[A[i]] -= 2
            elif k - A[i] != A[i] and nDict[k - A[i]] > 0:
                count += 1
                nDict[A[i]] -= 1
                nDict[k - A[i]] -= 1
    print(count)
    return 0


if __name__ == "__main__":
    solve()

-F = sys.stdin -N = int(F.readline().strip("\n")) -A = list(map(int, F.readline().strip("\n").split())) -A.sort() -pair_sum = 0 -A_dict = dict() -for a in A: -    if a not in A_dict: -        A_dict[a] = 1 -    else: -        A_dict[a] += 1 -for i in reversed(list(range(1, N))): -    if A_dict[A[i]] > 0: -        nowA = A[i] -        temp_a = A[i] -        k = 0 -        while temp_a > 0: -            temp_a //= 2 -            k += 1 -        opposite = 2**k - nowA -        if opposite in A_dict: -            if opposite == nowA and A_dict[opposite] > 1: -                pair_sum += 1 -                A_dict[opposite] -= 2 -            elif opposite != nowA and A_dict[opposite] > 0: -                pair_sum += 1 -                A_dict[opposite] -= 1 -                A_dict[nowA] -= 1 -print(pair_sum) + +def solve(): +    input = sys.stdin.readline +    N = int(eval(input())) +    A = [int(a) for a in input().split()] +    A.sort() +    nDict = dict() +    for i, a in enumerate(A): +        if a in nDict: +            nDict[a] += 1 +        else: +            nDict[a] = 1 +    count = 0 +    for i in reversed(list(range(N))): +        if nDict[A[i]] == 0: +            continue +        k = 1 +        while k <= A[i]: +            k <<= 1 +        if k - A[i] in nDict: +            if k - A[i] == A[i] and nDict[k - A[i]] > 1: +                count += 1 +                nDict[A[i]] -= 2 +            elif k - A[i] != A[i] and nDict[k - A[i]] > 0: +                count += 1 +                nDict[A[i]] -= 1 +                nDict[k - A[i]] -= 1 +    print(count) +    return 0 + + +if __name__ == "__main__": +    solve()