from collections import Counter



N = int(eval(input()))

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

ctr = Counter(A)

lctr = sorted(list(ctr.items()),reverse=True)



ans = 0

for k,_ in lctr:

    beki = 2**(len(bin(k))-2)

    a = beki-k

    if a == k:

        ans += ctr[k]//2

    else:

        tmp = min(ctr[k], ctr[a])

        ans += tmp

        ctr[a] -= tmp

print(ans)
from collections import Counter

N = int(eval(input()))

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

ctr = Counter(A)

sa = sorted(list(ctr.keys()),reverse=True)



ans = 0

for a in sa:

    p = 2**(len(bin(a))-2)

    rem = p - a

    if a == rem:

        v = ctr[a] // 2

    else:

        v = min(ctr[a], ctr[rem])

    ans += v

    ctr[a] -= v

    ctr[rem] -= v

print(ans)
from collections import Counter

N = int(eval(input()))
A = list(map(int, input().split()))
ctr = Counter(A)
lctr = sorted(list(ctr.items()), reverse=True)
ans = 0
for k, _ in lctr:
    beki = 2 ** (len(bin(k)) - 2)
    a = beki - k
    if a == k:
        ans += ctr[k] // 2
    else:
        tmp = min(ctr[k], ctr[a])
        ans += tmp
        ctr[a] -= tmp
print(ans)

from collections import Counter

N = int(eval(input()))
A = list(map(int, input().split()))
ctr = Counter(A)
sa = sorted(list(ctr.keys()), reverse=True)
ans = 0
for a in sa:
    p = 2 ** (len(bin(a)) - 2)
    rem = p - a
    if a == rem:
        v = ctr[a] // 2
    else:
        v = min(ctr[a], ctr[rem])
    ans += v
    ctr[a] -= v
    ctr[rem] -= v
print(ans)

-lctr = sorted(list(ctr.items()), reverse=True) +sa = sorted(list(ctr.keys()), reverse=True) -for k, _ in lctr: -    beki = 2 ** (len(bin(k)) - 2) -    a = beki - k -    if a == k: -        ans += ctr[k] // 2 +for a in sa: +    p = 2 ** (len(bin(a)) - 2) +    rem = p - a +    if a == rem: +        v = ctr[a] // 2 -        tmp = min(ctr[k], ctr[a]) -        ans += tmp -        ctr[a] -= tmp +        v = min(ctr[a], ctr[rem]) +    ans += v +    ctr[a] -= v +    ctr[rem] -= v