n=int(eval(input()))

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

arr=sorted(arr,reverse=True)

dic={}

for val in arr:

  if val not in dic:

    dic[val]=1

  else:

    dic[val]+=1

ans=0

for val in arr:

  for i in range(40):

    if val<2**i:

      persuit=2**i

      break

  if persuit-val==val:

    if val in dic:

      if dic[val]>=2:

        ans+=1

        dic[val]-=2

        if dic[val]==0:

          del dic[val]

      else:

        continue

    else:

      continue

  else:

    if val in dic and persuit-val in dic:

      ans+=1

      dic[val]-=1

      if dic[val]==0:

        del dic[val]

      dic[persuit-val]-=1

      if dic[persuit-val]==0:

        del dic[persuit-val]

    else:

      continue

print(ans)
from bisect import bisect_left



n=int(eval(input()))

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

arr=sorted(arr,reverse=True)

dic={}

for val in arr:

  if val not in dic:

    dic[val]=1

  else:

    dic[val]+=1

arr2=[]

for i in range(40):

  arr2.append(2**i)

ans=0

for val in arr:

  pos=bisect_left(arr2,val)

  if val==arr2[pos]:

    persuit=arr2[pos+1]

  else:

    persuit=arr2[pos]

  if persuit-val==val:

    if val in dic:

      if dic[val]>=2:

        ans+=1

        dic[val]-=2

        if dic[val]==0:

          del dic[val]

      else:

        continue

    else:

      continue

  else:

    if val in dic and persuit-val in dic:

      ans+=1

      dic[val]-=1

      if dic[val]==0:

        del dic[val]

      dic[persuit-val]-=1

      if dic[persuit-val]==0:

        del dic[persuit-val]

    else:

      continue

print(ans)
n = int(eval(input()))
arr = list(map(int, input().split()))
arr = sorted(arr, reverse=True)
dic = {}
for val in arr:
    if val not in dic:
        dic[val] = 1
    else:
        dic[val] += 1
ans = 0
for val in arr:
    for i in range(40):
        if val < 2**i:
            persuit = 2**i
            break
    if persuit - val == val:
        if val in dic:
            if dic[val] >= 2:
                ans += 1
                dic[val] -= 2
                if dic[val] == 0:
                    del dic[val]
            else:
                continue
        else:
            continue
    else:
        if val in dic and persuit - val in dic:
            ans += 1
            dic[val] -= 1
            if dic[val] == 0:
                del dic[val]
            dic[persuit - val] -= 1
            if dic[persuit - val] == 0:
                del dic[persuit - val]
        else:
            continue
print(ans)

from bisect import bisect_left

n = int(eval(input()))
arr = list(map(int, input().split()))
arr = sorted(arr, reverse=True)
dic = {}
for val in arr:
    if val not in dic:
        dic[val] = 1
    else:
        dic[val] += 1
arr2 = []
for i in range(40):
    arr2.append(2**i)
ans = 0
for val in arr:
    pos = bisect_left(arr2, val)
    if val == arr2[pos]:
        persuit = arr2[pos + 1]
    else:
        persuit = arr2[pos]
    if persuit - val == val:
        if val in dic:
            if dic[val] >= 2:
                ans += 1
                dic[val] -= 2
                if dic[val] == 0:
                    del dic[val]
            else:
                continue
        else:
            continue
    else:
        if val in dic and persuit - val in dic:
            ans += 1
            dic[val] -= 1
            if dic[val] == 0:
                del dic[val]
            dic[persuit - val] -= 1
            if dic[persuit - val] == 0:
                del dic[persuit - val]
        else:
            continue
print(ans)

+from bisect import bisect_left + +arr2 = [] +for i in range(40): +    arr2.append(2**i) -    for i in range(40): -        if val < 2**i: -            persuit = 2**i -            break +    pos = bisect_left(arr2, val) +    if val == arr2[pos]: +        persuit = arr2[pos + 1] +    else: +        persuit = arr2[pos]