from collections import*

from bisect import*

p=[1]

for _ in range(30):p+=p[-1]*2,

n,*a=list(map(int,open(0).read().split()))

d=Counter(a)

c=0

for b in sorted(a)[::-1]:

  if d[b]<1:continue

  d[b]-=1

  x=p[bisect(p,b)]-b

  if d[x]:

    d[x]-=1

    c+=1

print(c)
from collections import*

C=Counter(a:=sorted(map(int,[*open(r:=0)][1].split())))

for x in a[::-1]:

 if C[x]>0:y=2**x.bit_length()-x;C[x]-=1;r+=C[y]>0;C[y]-=1

print(r)
from collections import *
from bisect import *

p = [1]
for _ in range(30):
    p += (p[-1] * 2,)
n, *a = list(map(int, open(0).read().split()))
d = Counter(a)
c = 0
for b in sorted(a)[::-1]:
    if d[b] < 1:
        continue
    d[b] -= 1
    x = p[bisect(p, b)] - b
    if d[x]:
        d[x] -= 1
        c += 1
print(c)

from collections import *

C = Counter(a := sorted(map(int, [*open(r := 0)][1].split())))
for x in a[::-1]:
    if C[x] > 0:
        y = 2 ** x.bit_length() - x
        C[x] -= 1
        r += C[y] > 0
        C[y] -= 1
print(r)

-from bisect import * -p = [1] -for _ in range(30): -    p += (p[-1] * 2,) -n, *a = list(map(int, open(0).read().split())) -d = Counter(a) -c = 0 -for b in sorted(a)[::-1]: -    if d[b] < 1: -        continue -    d[b] -= 1 -    x = p[bisect(p, b)] - b -    if d[x]: -        d[x] -= 1 -        c += 1 -print(c) +C = Counter(a := sorted(map(int, [*open(r := 0)][1].split()))) +for x in a[::-1]: +    if C[x] > 0: +        y = 2 ** x.bit_length() - x +        C[x] -= 1 +        r += C[y] > 0 +        C[y] -= 1 +print(r)