CodeEff/ECCO huggingface dataset:
# Original solution
def main():
    from collections import Counter
    import sys
    input = sys.stdin.buffer.readline

    _ = int(eval(input()))
    A = [int(i) for i in input().split()]

    ans = 0
    c = Counter(A)
    B = sorted(list(c.keys()), reverse=True)

    for b in B:
        if c[b] == 0:
            continue
        a = (2 ** b.bit_length()) - b
        if a == b:
            cur = c[b]//2
        else:
            if a in list(c.keys()):
                cur = min(c[a], c[b])
            else:
                cur = 0
        ans += cur
        # c[b] -= cur
        c[a] -= cur

    print(ans)


if __name__ == '__main__':
    main()


# Optimized solution
def main():
    from collections import Counter
    import sys
    input = sys.stdin.buffer.readline

    _ = int(eval(input()))
    A = [int(i) for i in input().split()]

    ans = 0
    c = Counter(A)
    B = sorted(list(c.keys()), reverse=True)

    for b in B:
        if c[b] == 0:
            continue
        a = (2 ** b.bit_length()) - b
        if a == b:
            cur = c[b]//2
        else:
            if a in c:
                cur = min(c[a], c[b])
            else:
                cur = 0
        ans += cur
        # c[b] -= cur
        c[a] -= cur

    print(ans)


if __name__ == '__main__':
    main()
# Original solution
import bisect
from collections import defaultdict

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

a.sort()
memo = defaultdict(int)
for i in range(n):
    memo[a[i]] += 1

count = 0
for t in reversed(list(range(1, 31))):
    for i in reversed(list(range(n))):
        if memo[a[i]] == 0:
            continue
        front = bisect.bisect_left(a, (1 << t) - a[i])
        back = bisect.bisect_right(a, (1 << t) - a[i])
        if front == back:
            continue
        if a[front] == a[i] and memo[a[i]] <= 1:
            continue
        if memo[a[front]] >= 1:
            memo[a[front]] -= 1
            memo[a[i]] -= 1
            count += 1

print(count)

# Optimized solution
from collections import defaultdict

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

a.sort()
memo = defaultdict(int)
for i in range(n):
    memo[a[i]] += 1

count = 0
for i in reversed(list(range(n))):
    if memo[a[i]] == 0:
        continue
    if (memo[(1 << (len(bin(a[i])) - 2)) - a[i]] > 0 and (1 << (len(bin(a[i])) - 2)) - a[i] != a[i]) or memo[(1 << (len(bin(a[i])) - 2)) - a[i]] > 1:
        memo[a[i]] -= 1
        memo[(1 << (len(bin(a[i])) - 2)) - a[i]] -= 1
        count += 1

print(count)
# Original solution
n = int(eval(input()))
A = list(map(int,input().split()))
A.append(-float("inf"))
n = len(A)

A.sort()
s = 2
while s <= A[-1]+A[-2]:
    s *= 2
s //= 2

U = [0] * n

ans = 0
while s > 0:
    ll = 0
    rr = n-1
    while rr >= 1 and rr-ll >= 2:
        # print("rr",rr,"ll",ll)
        t = s - A[rr]
        if t>s:
            break
        # print("s",s,"t",t)
        l = ll
        r = rr-1
        m = (r+l)//2
        while r-l > 1:
            # print("r",r,"l",l,"m",m)
            if A[m] >= t:
                r = m
            else:
                l = m
            m = (r+l)//2
        if A[l+1] == t:
            ans += 1
            U[l+1] = 1
            U[rr] = 1
            # print(ans)
            A[l+1] = -float("inf")
        ll = l
        rr -= 1
        # print(A)
    s //= 2

    B = []
    for i in range(len(A)):
        if U[i] == 0:
            B.append(A[i])
    A = B
    n = len(A)
    U = [0] * n
print(ans)


# Optimized solution
n = int(eval(input()))
A = list(map(int,input().split()))
A.append(-float("inf"))
n = len(A)

A.sort()
s = 2
while s <= A[-1]+A[-2]:
    s *= 2
s //= 2

U = [0] * n

ans = 0
while s > 0:
    ll = 0
    rr = n-1
    while rr >= 1 and s <= A[rr]:
        rr -= 1
    while rr >= 1 and rr-ll >= 2:
        # print("rr",rr,"ll",ll)
        t = s - A[rr]

        # print("s",s,"t",t)
        l = ll
        r = rr-1
        m = (r+l)//2
        while r-l > 1:
            # print("r",r,"l",l,"m",m)
            if A[m] >= t:
                r = m
            else:
                l = m
            m = (r+l)//2
        if A[l+1] == t:
            ans += 1
            U[l+1] = 1
            U[rr] = 1
            # print(ans)
            A[l+1] = -float("inf")
        ll = l
        rr -= 1
        # print(A)
    s //= 2

    B = []
    for i in range(len(A)):
        if U[i] == 0:
            B.append(A[i])
    A = B
    n = len(A)
    U = [0] * n
print(ans)
# Original solution
import collections

N = eval(input())
A = list(map(int, input().split()))
C = collections.Counter(A)
K = list(C.keys())
K.sort(reverse=1)
res = 0
for i in K:
    for j in range(60):
        p = 2 ** j
        if i > p:
            continue
        elif i == p:
            res += C[i] // 2
            C[i] = C[i] // 2 * 2
        else:
            num = min(C[i], C[p - i])
            res += num
            C[i] -= num
            C[p - i] -= num
print(res)


# Optimized solution
import collections

N = eval(input())
A = list(map(int, input().split()))
C = collections.Counter(A)
K = list(C.keys())
K.sort(reverse=1)
res = 0
for i in K:
    for j in range(60):
        p = 2 ** j
        if i <= p:
            break
    if i == p:
      res += C[i] // 2
      C[i] = C[i] // 2 * 2
    else:
      num = min(C[i], C[p - i])
      res += num
      C[i] -= num
      C[p - i] -= num
print(res)
# Original solution
from bisect import bisect_right
n = int(eval(input()))
d = {}
amax = 0
for a in map(int, input().split()):
  if a in d:
    d[a] += 1
  else:
    d[a] = 1
amax = max(d.keys())
t = 1
valids = []
while t < 2 * amax:
  t *= 2
  valids.append(t)
result = 0
while True:
  prev = result
  keys = list(sorted(list(d.keys()), reverse = True))
  for x in keys:
    if x not in d:
      continue
    t = valids[bisect_right(valids, x)] - x
    while True:
      if t not in d:
        break
      if x == t and d[x] == 1:
        break
      result += 1
      if d[x] == 1:
        del d[x]
      else:
        d[x] -= 1
      if d[t] == 1:
        del d[t]
      else:
        d[t] -= 1
      if x not in d:
        break
  if prev == result:
    break
print(result)

# Optimized solution
from bisect import bisect_right
n = int(eval(input()))
d = {}
for a in map(int, input().split()):
  if a in d:
    d[a] += 1
  else:
    d[a] = 1
amax = max(d.keys())
t = 1
valids = []
while t < 2 * amax:
  t *= 2
  valids.append(t)
result = 0
keys = list(sorted(list(d.keys()), reverse = True))
for a in keys:
  if a not in d:
    continue
  t = valids[bisect_right(valids, a)] - a
  while True:
    if t not in d:
      break
    if a == t and d[a] == 1:
      break
    result += 1
    if d[a] == 1:
      del d[a]
    else:
      d[a] -= 1
    if d[t] == 1:
      del d[t]
    else:
      d[t] -= 1
    if a not in d:
      break
print(result)
# Original solution
from bisect import bisect_right
n = int(eval(input()))
d = {}
for a in map(int, input().split()):
  if a in d:
    d[a] += 1
  else:
    d[a] = 1
alist = list(sorted(list(d.keys()), reverse = True))
amax = alist[0]
t = 1
power_of_two = []
while t < 2 * amax:
  t *= 2
  power_of_two.append(t)
result = 0
for a in alist:
  if d[a] == 0:
    continue
  t = power_of_two[bisect_right(power_of_two, a)] - a
  while True:
    if t not in d or d[t] == 0:
      break
    if a != t:
      i = min(d[a], d[t])
    else:
      if d[a] == 1:
        break
      i = d[a] // 2
    result += i
    d[a] -= i
    d[t] -= i
    if d[a] == 0:
      break
print(result)


# Optimized solution
from bisect import bisect_right
n = int(eval(input()))
d = {}
for a in map(int, input().split()):
  if a in d:
    d[a] += 1
  else:
    d[a] = 1
alist = list(sorted(list(d.keys()), reverse = True))
amax = alist[0]
t = 1
power_of_two = []
while t < 2 * amax:
  t *= 2
  power_of_two.append(t)
result = 0
for a in alist:
  if d[a] == 0:
    continue
  t = power_of_two[bisect_right(power_of_two, a)] - a
  if t not in d or d[t] == 0:
    continue
  if a != t:
    i = min(d[a], d[t])
  else:
    if d[a] == 1:
      continue
    i = d[a] // 2
  result += i
  d[a] -= i
  d[t] -= i
print(result)
# Original solution
from bisect import bisect_right
n = int(eval(input()))
d = {}
for a in map(int, input().split()):
  if a in d:
    d[a] += 1
  else:
    d[a] = 1
alist = list(sorted(list(d.keys()), reverse = True))
amax = alist[0]
t = 1
power_of_two = []
while t < 2 * amax:
  t *= 2
  power_of_two.append(t)
result = 0
for a in alist:
  if d[a] == 0:
    continue
  t = power_of_two[bisect_right(power_of_two, a)] - a
  if t not in d or d[t] == 0:
    continue
  if a != t:
    i = min(d[a], d[t])
  else:
    if d[a] == 1:
      continue
    i = d[a] // 2
  result += i
  d[a] -= i
  d[t] -= i
print(result)


# Optimized solution
from bisect import bisect_right
n = int(eval(input()))
d = {}
for a in map(int, input().split()):
  if a in d:
    d[a] += 1
  else:
    d[a] = 1
alist = list(sorted(list(d.keys()), reverse = True))
amax = alist[0]
t = 1
power_of_two = []
while t < 2 * amax:
  t *= 2
  power_of_two.append(t)
result = 0
for a in alist:
  if a not in d:
    continue
  t = power_of_two[bisect_right(power_of_two, a)] - a
  if t not in d:
    continue
  if a != t:
    i = min(d[a], d[t])
  else:
    if d[a] == 1:
      continue
    i = d[a] // 2
  result += i  
  if d[a] == i:
    del d[a]
  else:
    d[a] -= i
  if d[t] == i:
    del d[t]
  else:
    d[t] -= i
print(result)
# Original solution
from bisect import bisect_right
n = int(eval(input()))
d = {}
for a in map(int, input().split()):
  if a in d:
    d[a] += 1
  else:
    d[a] = 1
alist = list(sorted(list(d.keys()), reverse = True))
amax = alist[0]
t = 1
power_of_two = []
while t < 2 * amax:
  t *= 2
  power_of_two.append(t)
result = 0
for a in alist:
  if a not in d:
    continue
  t = power_of_two[bisect_right(power_of_two, a)] - a
  if t not in d:
    continue
  if a != t:
    i = min(d[a], d[t])
  else:
    if d[a] == 1:
      continue
    i = d[a] // 2
  result += i  
  if d[a] == i:
    del d[a]
  else:
    d[a] -= i
  if d[t] == i:
    del d[t]
  else:
    d[t] -= i
print(result)


# Optimized solution
from bisect import bisect_right
n = int(eval(input()))
d = {}
for a in map(int, input().split()):
  if a in d:
    d[a] += 1
  else:
    d[a] = 1
alist = list(sorted(list(d.keys()), reverse = True))
amax = alist[0]
t = 1
power_of_two = []
while t < 2 * amax:
  t *= 2
  power_of_two.append(t)
result = 0
for a in alist:
  if a not in d:
    continue
  t = power_of_two[bisect_right(power_of_two, a)] - a
  if t not in d:
    continue
  if a != t:
    if d[a] < d[t]:
      i = d[a]
    else:
      i = d[t]
  else:
    if d[a] == 1:
      continue
    i = d[a] // 2
  result += i  
  if d[a] == i:
    del d[a]
  else:
    d[a] -= i
  if d[t] == i:
    del d[t]
  else:
    d[t] -= i
print(result)
# Original solution
N = int(eval(input()))
A_list = list(map(int, input().split()))
two_list = [2 ** i for i in range(32)]
count = 0
items = {}
for a in A_list:
    if a in items:
        items[a] += 1
 
    else:
        items[a] = 1
A_list.sort(reverse=True)
 
for a in A_list:
    if items[a] >= 1:
 
        for t in two_list:
            m = t -a
            if m in items:
                if m == a and items[a] >= 2:
                    count += 1
                    items[a] -= 1
                    items[m] -= 1
                    break
 
                elif m != a and items[m] >= 1 and items[a] >=1:
                    count += 1
                    items[a] -= 1
                    items[m] -= 1
                    break
print(count)

# Optimized solution
N = int(eval(input()))
A_list = list(map(int, input().split()))
two_list = [2 ** i for i in range(32)]

count = 0
items = {}
for a in A_list:
    if a in list(items.keys()):
        items[a] += 1
    else:
        items[a] = 1
A_list.sort(reverse=True)
import bisect

for a in A_list:
    if items[a] >= 1:
        index = bisect.bisect_left(two_list, a)
        for t in two_list[index:]:
            m = t - a
            if m in list(items.keys()):
                if m == a and items[a] >= 2:
                    count += 1
                    items[a] -= 2
                    break

                elif m != a and items[m] >= 1 and items[a] >= 1:
                    count += 1
                    items[a] -= 1
                    items[m] -= 1
                    break
print(count)
# Original solution
N = int(input().rstrip())
A = [int(s) for s in input().rstrip().split()]
A.sort()

squared = [2]
tmp = 2
while tmp < 2 * 10**9:
    tmp *= 2
    squared.append(tmp)

pairs = []
for i in range(N):
    for j in range(i+1, N):
        if A[i] + A[j] in squared:
            pairs.append([A[i], A[j]])

adopt = [format(i, 'b').rjust(len(pairs), '0') for i in range(2**len(pairs))]
max_pair = 0

for i in range(len(adopt)):
    num = []
    for j in range(len(pairs)):
        if adopt[i][j] == '1':
            num.append(pairs[j][0])
            num.append(pairs[j][1])
    if len(num) == len(set(num)) and len(num) > max_pair:
        max_pair = len(num) // 2

print(max_pair)

# Optimized solution
N = int(input().rstrip())
A = [int(s) for s in input().rstrip().split()]
A.sort()

squared = [2]
tmp = 2
while tmp < 2 * 10**9:
    tmp *= 2
    squared.append(tmp)

cnt = 0
while A:
    max_num = A.pop()
    for i in range(len(A)):
        if max_num + A[i] in squared:
            cnt += 1
            A.pop(i)
            break

print(cnt)
# Original solution
N=int(eval(input()))
a=list(map(int,input().split()))
a_=sorted(a,key=lambda x:-x)
ans=0
from collections import Counter
c=Counter(a_)
for i in a_:
    if c[i]==0:
        continue
    c[i]-=1
    for n in range(i):
        if i<2**n:
            t=n
            break
        elif i==2**n:
            t=n+1
            break
    j=2**t-i
    if j in c and c[j]>0:
        ans+=1
        c[j]-=1
print(ans)

# Optimized solution
N=int(eval(input()))
a=list(map(int,input().split()))
a_=sorted(a,key=lambda x:-x)
ans=0
from collections import Counter
c=Counter(a_)
for i in a_:
    if c[i]==0:
        continue
    c[i]-=1
    m=1<<i.bit_length()
    j=m-i
    if j in c and c[j]>0:
        ans+=1
        c[j]-=1
print(ans)
# Original solution
N = int(eval(input()))
A = [int(a) for a in input().split()]

A.sort()
used = [0]*N

import bisect

ans = 0
for i in range(N-1, -1, -1):
    if used[i] == 1:
        continue
    num = pow(2, len(bin(A[i]))-2) - A[i]
    idx = bisect.bisect_left(A, num)
    while idx < i and used[idx] == 1:
        idx += 1
    if A[idx] == num and idx < i:
        ans += 1
        used[idx] = 1
        used[i] = 1

print(ans)

# Optimized solution
N = int(eval(input()))
A = [int(a) for a in input().split()]

dic = {}
for a in A:
    if a in dic:
        dic[a] += 1
    else:
        dic[a] = 1
        
A.sort(reverse=True)
ans = 0
for a in A:
    if dic[a] == 0:
        continue
    dic[a] -= 1
    num = pow(2, len(bin(a))-2) - a
    if num in dic and dic[num] > 0:
        ans += 1
        dic[num] -= 1

print(ans)
# Original solution
import math

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

count = 0
a.sort()
a.reverse()

while(a!=[]):
    temp = a[0]
    a.pop(0)
    b=2**math.floor(math.log2(temp))
    if a ==[]:
        break
    if 2*b-temp in a:
        count += 1
        a.pop(a.index(2*b-temp))
    
    


print(count)

# Optimized solution
n = int(eval(input()))
a = list(map(int, input().split()))
a.sort()
b = {}
for i in range(len(a)):
    if a[i] in b:
        b[a[i]] += 1
    else:
        b[a[i]] = 1
twins = []
now = 1
while now <= a[-1]:
    now *= 2
    twins.append(now)
for i in range(len(a) - 1, -1, -1):
    tmpa = 0
    if  b[a[i]] == 0:
        continue
    for j in range(len(twins) - 1, -1, -1):
        if twins[j] <= a[i]:
            break
        tmpa = twins[j] - a[i]
    if tmpa == a[i]:
        if b[tmpa] >= 2:
            b[tmpa] -= 2
    elif tmpa in b and b[tmpa] != 0:
        b[tmpa] -= 1
        b[a[i]] -= 1
countb = 0
for i in b:
    countb += b[i]
print(((n - countb) // 2))
# Original solution
import queue
N=int(eval(input()))
A=sorted([int(i) for i in input().split()],reverse=True)
B=[2**(len(bin(i))-2) for i in A]
R=[0 for i in range(N)]
D=dict()
for i in range(N):
    if not(A[i] in D):
        D[A[i]]=queue.Queue()
    D[A[i]].put(i)
ans=0
for i in range(N):
    if R[i]==1:
        continue
    if B[i]==2*A[i]:
        if A[i] in D:
            flag=0
            x=0;y=0
            if not(D[A[i]].empty()):
                x=D[A[i]].get()
                flag=1
            if flag==1 and not(D[A[i]].empty()):
                y=D[A[i]].get()
                flag=2
            if flag==2:
                R[x]=1
                R[y]=1
                ans+=1
    else:
        if (B[i]-A[i]) in D:
            if not(D[B[i]-A[i]].empty()):
                it=D[A[i]].get()
                j=D[B[i]-A[i]].get()
                R[i]=1
                R[j]=1
                ans+=1
print(ans)



# Optimized solution
N=int(eval(input()))
A=sorted([int(i) for i in input().split()],reverse=True)
B=[2**(len(bin(i))-2) for i in A]
D=dict()
for i in range(N):
    if not(A[i] in D):
        D[A[i]]=1
    else:
        D[A[i]]+=1
ans=0
for i in range(N):
    if D[A[i]]<=0:
        continue
    if B[i]==2*A[i]:
        if D[A[i]]>=2:
            D[A[i]]-=2
            ans+=1
    else:
        if (B[i]-A[i]) in D:
            if D[B[i]-A[i]]!=0:
                D[A[i]]-=1
                D[B[i]-A[i]]-=1
                ans+=1
print(ans)
# Original solution
# https://beta.atcoder.jp/contests/agc029/submissions/3804087
from collections import Counter

N = int(eval(input()))
a = list(map(int, input().split()))
a = sorted(a, reverse=True)
b = Counter(a)

ans = 0
for t in a:
    if b[t] == 0: continue
    s = (1 << t.bit_length()) - t
    if t == s:
        ans += b[t] // 2
        b[t] %= 2
    else:
        u = min(b[s], b[t])
        ans += u
        b[s] -= u
        b[t] -= u

print(ans)


# Optimized solution
N = int(eval(input()))
a = list(map(int, input().split()))
a = sorted(a, reverse=True)

cnt = {}
for n in a:
    cnt[n] = cnt.get(n, 0) + 1

ans = 0
for n in a:
    g = 2 ** n.bit_length()
    s = g - n
    if n == s:
        pair = cnt.get(s, 0) // 2
        ans += pair
        cnt[s] = cnt.get(s, 0) % 2
    else:
        pair = min(cnt.get(n, 0), cnt.get(s, 0))
        ans += pair
        cnt[n] = cnt.get(n, 0) - pair
        cnt[s] = cnt.get(s, 0) - pair
print(ans)
# Original solution
import collections
N=int(eval(input()))
x=list(map(int,input().split()))
c=collections.Counter(x)
t=[2**i for i in range(len(str(bin(max(x)*2))[2:])+1)[::-1]]
count=0
x.sort()
for i in range(len(x))[::-1]:
    for j in range(len(t)):
        if t[j]-x[i] in list(c.keys()):
            if t[j] < x[i]:
                break
            if t[j]-x[i] == x[i]:
                if c[x[i]] >= 2:
                    c[x[i]] -= 2
                    count +=1
            else:
                if c[t[j]-x[i]]>0 and c[x[i]]>0:
                    c[t[j]-x[i]] -= 1
                    c[x[i]] -= 1
                    count+=1
print(count)

# Optimized solution
import collections
N=int(eval(input()))
x=list(map(int,input().split()))
c=collections.Counter(x)
t=[2**i for i in range(len(str(bin(max(x)*2))[2:])+1)[::-1]]
count=0
start=0
x.sort()
for i in range(len(x))[::-1]:
    for j in range(start,len(t)):
        if t[j] > 2*x[i]:
            start = j
        if t[j] < x[i]:
            break
        if t[j]-x[i] in list(c.keys()):
            if t[j]-x[i] == x[i]:
                if c[x[i]] >= 2:
                    c[x[i]] -= 2
                    count +=1
            else:
                if c[t[j]-x[i]]>0 and c[x[i]]>0:
                    c[t[j]-x[i]] -= 1
                    c[x[i]] -= 1
                    count+=1
print(count)
# Original solution
from bisect import bisect_left
N = int(eval(input()))
A = sorted(list(map(int,input().split())))
cnt = 0
hist = [0 for _ in range(N)]
for i in range(N-1,0,-1):
    if hist[i]==0:
        a = A[i]
        k = 0
        while 2**k<=a:
            k += 1
        b = 2**k-a
        ind = bisect_left(A,b)
        if ind<i and A[ind]==b and hist[ind]==0:
            hist[i]=1
            hist[ind]=1
            cnt += 1
        elif ind<i and A[ind]==b and hist[ind]==1:
            ind += 1
            while A[ind]==b and ind<i:
                if hist[ind]==0:
                    hist[i]=1
                    hist[ind]=1
                    cnt += 1
                    break
                ind += 1
print(cnt)

# Optimized solution
from bisect import bisect_left
N = int(eval(input()))
A = sorted(list(map(int,input().split())))
A = [[A[i],0] for i in range(N)]
cnt = 0
for i in range(N-1,0,-1):
    if A[i][1]==0:
        a = A[i][0]
        A[i][1]=1
        k = 0
        while 2**k<=a:
            k += 1
        b = 2**k-a
        ind = bisect_left(A,[b,1])
        ind -= 1
        if ind<i and A[ind]==[b,0]:
            A[ind][1]=1
            cnt += 1
print(cnt)
# Original solution
import sys

nbs = list(sorted(map(int, list(sys.stdin)[1].strip().split())))
used = set()
count = 0

for k in reversed(list(range(1, 31))):
    p = 1 << k
    j = len(nbs) - 1
    for i, a in enumerate(nbs):
        if i not in used:
            while j > i and (nbs[j] > p - a or j in used):
                j -= 1
            if j <= i:
                break
            if nbs[j] == p - a:
                used.add(i)
                used.add(j)
                count += 1

print(count)

# Optimized solution
eval(input())
nbs = list(map(int, input().split()))

answer = 0
count = {}

for nb in nbs:
    count[nb] = count.get(nb, 0) + 1

for nb in sorted(list(count.keys()), reverse=True):
    searching = (1 << nb.bit_length()) - nb
    nb_count = count[nb]
    sr_count = count.get(searching, 0)
    if sr_count:
        if nb == searching:
            increment = nb_count // 2
        else:
            increment = nb_count if nb_count < sr_count else sr_count
            count[searching] -= increment
        answer += increment

print(answer)
# Original solution
from collections import Counter

n = int(eval(input()))
nums = sorted(list(map(int, input().split())), reverse=True)

num_map = Counter(nums)

answer = 0
for num in nums:
    pair = (1 << (num.bit_length())) - num

    if num_map[num] > 0 and num_map[pair]:
        if num == pair and num_map[num] > 1:
            answer += 1
            num_map[num] -= 2
        if num > pair:
            answer += 1
            num_map[num] -= 1
            num_map[pair] -= 1

print(answer)

# Optimized solution
from collections import Counter

n = int(eval(input()))
nums = sorted(list(map(int, input().split())), reverse=True)

num_map = Counter(nums)

answer = 0
for num in nums:
    pair = (1 << (num.bit_length())) - num

    if num_map[num] > 0 and num_map[pair]:
        if num == pair and num_map[num] > 1:
            answer += 1
            num_map[num] -= 2
        if not num == pair:
            answer += 1
            num_map[num] -= 1
            num_map[pair] -= 1

print(answer)
# Original solution
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)

# Optimized solution
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)