import math

import bisect

n=int(eval(input()))

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

a.sort()

b=[]

for i in range(1,50):

  b.append(2**i)

ct=0

check=[1]*n

for i in range(n-1,-1,-1):

  if a[i]==1:

    break

  if check[i]==1 and a[i] not in b:

    check[i]=0

    x=math.floor(math.log2(a[i]))

    x=b[x]-a[i]

    y=bisect.bisect_left(a,x)

    z=bisect.bisect_right(a,x)

    t=bisect.bisect_left(check[y:z],1)+y

    if t!=z:

      check[t]=0

      ct+=1



ctb=0

w=1

for i in range(n):

  if a[i] in b or a[i]==1:

    if a[i]==w:

      if check[i]==1:

        ctb+=1

    else:

      ct+=ctb//2

      w=a[i]

      if check[i]==1:

        ctb=1

      else:

        ctb=0

  else:

    ct+=ctb//2

    ctb=0

ct+=ctb//2



print(ct)
import math

import bisect

n=int(eval(input()))

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

a.sort()

x=a[0]

ctn=1

l=[]

l2=[]

for i in range(1,n):

  if x==a[i]:

    ctn+=1

  else:

    l.append([x,ctn])

    l2.append(x)

    x=a[i]

    ctn=1

l.append([x,ctn])

l2.append(x)



b=[]

for i in range(1,50):

  b.append(2**i)



ct=0

for i in range(len(l2)-1,-1,-1):

    x=math.floor(math.log2(l2[i]))

    x=b[x]-l2[i]

    y=bisect.bisect_left(l2,x)

    if l2[y]==x:

      if l2[y]!=l2[i]:

        m=min(l[i][1],l[y][1])

      else:

        m=l[i][1]//2

      l[i][1]-=m

      l[y][1]-=m

      ct+=m

print(ct)
import math
import bisect

n = int(eval(input()))
a = list(map(int, input().split()))
a.sort()
b = []
for i in range(1, 50):
    b.append(2**i)
ct = 0
check = [1] * n
for i in range(n - 1, -1, -1):
    if a[i] == 1:
        break
    if check[i] == 1 and a[i] not in b:
        check[i] = 0
        x = math.floor(math.log2(a[i]))
        x = b[x] - a[i]
        y = bisect.bisect_left(a, x)
        z = bisect.bisect_right(a, x)
        t = bisect.bisect_left(check[y:z], 1) + y
        if t != z:
            check[t] = 0
            ct += 1
ctb = 0
w = 1
for i in range(n):
    if a[i] in b or a[i] == 1:
        if a[i] == w:
            if check[i] == 1:
                ctb += 1
        else:
            ct += ctb // 2
            w = a[i]
            if check[i] == 1:
                ctb = 1
            else:
                ctb = 0
    else:
        ct += ctb // 2
        ctb = 0
ct += ctb // 2
print(ct)

import math
import bisect

n = int(eval(input()))
a = list(map(int, input().split()))
a.sort()
x = a[0]
ctn = 1
l = []
l2 = []
for i in range(1, n):
    if x == a[i]:
        ctn += 1
    else:
        l.append([x, ctn])
        l2.append(x)
        x = a[i]
        ctn = 1
l.append([x, ctn])
l2.append(x)
b = []
for i in range(1, 50):
    b.append(2**i)
ct = 0
for i in range(len(l2) - 1, -1, -1):
    x = math.floor(math.log2(l2[i]))
    x = b[x] - l2[i]
    y = bisect.bisect_left(l2, x)
    if l2[y] == x:
        if l2[y] != l2[i]:
            m = min(l[i][1], l[y][1])
        else:
            m = l[i][1] // 2
        l[i][1] -= m
        l[y][1] -= m
        ct += m
print(ct)

+x = a[0] +ctn = 1 +l = [] +l2 = [] +for i in range(1, n): +    if x == a[i]: +        ctn += 1 +    else: +        l.append([x, ctn]) +        l2.append(x) +        x = a[i] +        ctn = 1 +l.append([x, ctn]) +l2.append(x) -check = [1] * n -for i in range(n - 1, -1, -1): -    if a[i] == 1: -        break -    if check[i] == 1 and a[i] not in b: -        check[i] = 0 -        x = math.floor(math.log2(a[i])) -        x = b[x] - a[i] -        y = bisect.bisect_left(a, x) -        z = bisect.bisect_right(a, x) -        t = bisect.bisect_left(check[y:z], 1) + y -        if t != z: -            check[t] = 0 -            ct += 1 -ctb = 0 -w = 1 -for i in range(n): -    if a[i] in b or a[i] == 1: -        if a[i] == w: -            if check[i] == 1: -                ctb += 1 +for i in range(len(l2) - 1, -1, -1): +    x = math.floor(math.log2(l2[i])) +    x = b[x] - l2[i] +    y = bisect.bisect_left(l2, x) +    if l2[y] == x: +        if l2[y] != l2[i]: +            m = min(l[i][1], l[y][1]) -            ct += ctb // 2 -            w = a[i] -            if check[i] == 1: -                ctb = 1 -            else: -                ctb = 0 -    else: -        ct += ctb // 2 -        ctb = 0 -ct += ctb // 2 +            m = l[i][1] // 2 +        l[i][1] -= m +        l[y][1] -= m +        ct += m