N = int(eval(input()))

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

two_list = [2 ** i for i in range(32)]

count = 0

items = {}

for a in A_list:

    if a in items:

        items[a] += 1

 

    else:

        items[a] = 1

A_list.sort(reverse=True)

 

for a in A_list:

    if items[a] >= 1:

 

        for t in two_list:

            m = t -a

            if m in items:

                if m == a and items[a] >= 2:

                    count += 1

                    items[a] -= 1

                    items[m] -= 1

                    break

 

                elif m != a and items[m] >= 1 and items[a] >=1:

                    count += 1

                    items[a] -= 1

                    items[m] -= 1

                    break

print(count)
N = int(eval(input()))

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

two_list = [2 ** i for i in range(32)]



count = 0

items = {}

for a in A_list:

    if a in list(items.keys()):

        items[a] += 1

    else:

        items[a] = 1

A_list.sort(reverse=True)

import bisect



for a in A_list:

    if items[a] >= 1:

        index = bisect.bisect_left(two_list, a)

        for t in two_list[index:]:

            m = t - a

            if m in list(items.keys()):

                if m == a and items[a] >= 2:

                    count += 1

                    items[a] -= 2

                    break



                elif m != a and items[m] >= 1 and items[a] >= 1:

                    count += 1

                    items[a] -= 1

                    items[m] -= 1

                    break

print(count)

N = int(eval(input()))
A_list = list(map(int, input().split()))
two_list = [2**i for i in range(32)]
count = 0
items = {}
for a in A_list:
    if a in items:
        items[a] += 1
    else:
        items[a] = 1
A_list.sort(reverse=True)
for a in A_list:
    if items[a] >= 1:
        for t in two_list:
            m = t - a
            if m in items:
                if m == a and items[a] >= 2:
                    count += 1
                    items[a] -= 1
                    items[m] -= 1
                    break
                elif m != a and items[m] >= 1 and items[a] >= 1:
                    count += 1
                    items[a] -= 1
                    items[m] -= 1
                    break
print(count)

N = int(eval(input()))
A_list = list(map(int, input().split()))
two_list = [2**i for i in range(32)]
count = 0
items = {}
for a in A_list:
    if a in list(items.keys()):
        items[a] += 1
    else:
        items[a] = 1
A_list.sort(reverse=True)
import bisect

for a in A_list:
    if items[a] >= 1:
        index = bisect.bisect_left(two_list, a)
        for t in two_list[index:]:
            m = t - a
            if m in list(items.keys()):
                if m == a and items[a] >= 2:
                    count += 1
                    items[a] -= 2
                    break
                elif m != a and items[m] >= 1 and items[a] >= 1:
                    count += 1
                    items[a] -= 1
                    items[m] -= 1
                    break
print(count)

-    if a in items: +    if a in list(items.keys()): +import bisect + -        for t in two_list: +        index = bisect.bisect_left(two_list, a) +        for t in two_list[index:]: -            if m in items: +            if m in list(items.keys()): -                    items[a] -= 1 -                    items[m] -= 1 +                    items[a] -= 2