import bisect

import math

N = int(eval(input()))

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

T = [2 ** i for i in range(31)]

A.sort()

already = set()





def to_dic(A):

    d = {}

    for a in A:

        d[a] = d.setdefault(a, 0) + 1



    return d



def is_in(t, num):

    i = D.setdefault(t, 0)

    if i == 0:

        return 0

    s = min(i, num)

    D[t] -= s

    return s





res = 0

D = to_dic(A)

A2 = list(D.keys())

A2.sort()



for n in range(len(A2) - 1, -1, -1):

    a = A2[n]



    if a in T:

        res += D[a] // 2

        D[a] = 0



        if D[a] % 2 == 0:

            continue



    num = D[a]

    t = 1 << (int(math.log2(a)) + 1)



    while t > a:

        s = is_in(t - a, num)

        res += s

        num -= s

        if num == 0:

            break



        t >>= 1



print(res)

import bisect

import math

N = int(eval(input()))

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

A.sort()

already = set()

key = {}



def is_in(t, n):

    i = key.setdefault(t, bisect.bisect_left(A, t))

    if i >= n:

        return -1



    while i < n and t == A[i]:

        if i not in already:

            already.add(i)

            key[t] = i

            return i

        i += 1



    return -1



res = 0

for n in range(len(A) - 1, -1, -1):

    if n in already:

        continue



    a = A[n]

    t = 1 << (int(math.log2(a)) + 1)



    while t > a:

        i = is_in(t - a, n)

        if i != -1:

            res += 1

            break

        t >>= 1



print(res)

print("")

import bisect
import math

N = int(eval(input()))
A = list(map(int, input().split()))
T = [2**i for i in range(31)]
A.sort()
already = set()


def to_dic(A):
    d = {}
    for a in A:
        d[a] = d.setdefault(a, 0) + 1
    return d


def is_in(t, num):
    i = D.setdefault(t, 0)
    if i == 0:
        return 0
    s = min(i, num)
    D[t] -= s
    return s


res = 0
D = to_dic(A)
A2 = list(D.keys())
A2.sort()
for n in range(len(A2) - 1, -1, -1):
    a = A2[n]
    if a in T:
        res += D[a] // 2
        D[a] = 0
        if D[a] % 2 == 0:
            continue
    num = D[a]
    t = 1 << (int(math.log2(a)) + 1)
    while t > a:
        s = is_in(t - a, num)
        res += s
        num -= s
        if num == 0:
            break
        t >>= 1
print(res)

import bisect
import math

N = int(eval(input()))
A = list(map(int, input().split()))
A.sort()
already = set()
key = {}


def is_in(t, n):
    i = key.setdefault(t, bisect.bisect_left(A, t))
    if i >= n:
        return -1
    while i < n and t == A[i]:
        if i not in already:
            already.add(i)
            key[t] = i
            return i
        i += 1
    return -1


res = 0
for n in range(len(A) - 1, -1, -1):
    if n in already:
        continue
    a = A[n]
    t = 1 << (int(math.log2(a)) + 1)
    while t > a:
        i = is_in(t - a, n)
        if i != -1:
            res += 1
            break
        t >>= 1
print(res)
print("")

-T = [2**i for i in range(31)] +key = {} -def to_dic(A): -    d = {} -    for a in A: -        d[a] = d.setdefault(a, 0) + 1 -    return d - - -def is_in(t, num): -    i = D.setdefault(t, 0) -    if i == 0: -        return 0 -    s = min(i, num) -    D[t] -= s -    return s +def is_in(t, n): +    i = key.setdefault(t, bisect.bisect_left(A, t)) +    if i >= n: +        return -1 +    while i < n and t == A[i]: +        if i not in already: +            already.add(i) +            key[t] = i +            return i +        i += 1 +    return -1 -D = to_dic(A) -A2 = list(D.keys()) -A2.sort() -for n in range(len(A2) - 1, -1, -1): -    a = A2[n] -    if a in T: -        res += D[a] // 2 -        D[a] = 0 -        if D[a] % 2 == 0: -            continue -    num = D[a] +for n in range(len(A) - 1, -1, -1): +    if n in already: +        continue +    a = A[n] -        s = is_in(t - a, num) -        res += s -        num -= s -        if num == 0: +        i = is_in(t - a, n) +        if i != -1: +            res += 1 +print("")