CodeEff/ECCO huggingface dataset:
# Original solution
from collections import deque

def main():
    N, X, Y = list(map(int, input().split()))
    X -= 1
    Y -= 1

    ans = [0 for _ in range(N)]
    for s in range(N):
        dist = [-1 for _ in range(N)]
        dist[s] = 0

        d = deque([s])
        while(len(d) > 0):
            v = d.popleft()
            if v == X:
                if dist[Y] == -1:
                    d.append(Y)
                    dist[Y] = dist[v] + 1
            if v == Y:
                if dist[X] == -1:
                    d.append(X)
                    dist[X] = dist[v] + 1
            if v + 1 < N:
                if dist[v+1] == -1:
                    d.append(v+1)
                    dist[v+1] = dist[v] + 1
            if v - 1 >= 0:
                if dist[v-1] == -1:
                    d.append(v-1)
                    dist[v-1] = dist[v] + 1

        for i in range(N):
            ans[dist[i]] += 1
  
    for k in range(1, N):
        print((ans[k] // 2))


if __name__ == "__main__":
    main()

# Optimized solution
from collections import deque

def main():
    N, X, Y = list(map(int, input().split()))
    X -= 1
    Y -= 1

    ans = [0 for _ in range(N)]
    for s in range(N):
        dist = [-1 for _ in range(N)]
        dist[s] = 0

        d = deque([s])
        while(len(d) > 0):
            v = d.popleft()
            if v == X:
                if dist[Y] == -1:
                    d.append(Y)
                    dist[Y] = dist[v] + 1
            elif v == Y:
                if dist[X] == -1:
                    d.append(X)
                    dist[X] = dist[v] + 1
            if v + 1 < N:
                if dist[v+1] == -1:
                    d.append(v+1)
                    dist[v+1] = dist[v] + 1
            if v - 1 >= 0:
                if dist[v-1] == -1:
                    d.append(v-1)
                    dist[v-1] = dist[v] + 1

        for i in range(N):
            ans[dist[i]] += 1
 
    for k in range(1, N):
        print((ans[k] // 2))


if __name__ == "__main__":
    main()
# Original solution
n, x, y = list(map(int, input().split()))
li = [0]*(n-1)
num = 0

for i in range(1,n+1):
    for j in range(i+1,n+1):
        if j<=x or y<i:
            num = j-i
        elif i<=x and x<j<=y:
            num = (x-i)+min(j-x, y-j+1)
        elif i<=x and y<j:
            num = (x-i)+(j-y)+1
        elif x<i and j<=y:
            num = min(j-i,(i-x)+(y-j)+1)
        elif x<i<=y and y<j:
            num = min(i-x+1, y-i)+(j-y)
        li[num-1] += 1

for i in li:
    print(i)

# Optimized solution
n, x, y = list(map(int, input().split()))
li = [0] * (n - 1)
num = 0

for i in range(1, n + 1):
    for j in range(i + 1, n + 1):
        num = min(j-i, abs(i-x)+abs(j-y)+1)
        li[num - 1] += 1

for i in li:
    print(i)
# Original solution
from collections import deque
n,x,y=list(map(int,input().split()))
t=deque()
for i in range(1,n+1):
    for j in range(i+1,n+1):
        t.append(min(abs(j-i),abs(i-x)+abs(j-y)+1))



for k in range(1,n):
    print((t.count(k)))

# Optimized solution

n,x,y=map(int,input().split())
t=[0]*n
for i in range(1,n+1):
    for j in range(i+1,n+1):
        t[min(abs(j-i),abs(i-x)+abs(j-y)+1)]+=1


print(*t[1:],sep='\n')
# Original solution
n,x,y = list(map(int,input().split()))
ans = {}
for i in range(1,n):
    for j in range(i+1,n+1):
        dist = min(abs(i-j),abs(i-x)+abs(j-y)+1,abs(i-y)+abs(j-x)+1)
        if dist in list(ans.keys()):
            ans[dist] += 1
        else:
            ans[dist] = 1
for k in range(1,n):
    if k in list(ans.keys()):
        print((ans[k]))
    else:
        print((0))

# Optimized solution
n,x,y = list(map(int,input().split()))
ans = {}
s = (y-x+1)//2
s = x+s
for i in range(1,n):
    for j in range(i+1,n+1):
        if i <= s:
            dist = min(j-i,abs(i-x)+abs(j-y)+1)
        else:
            dist = j-i
        if dist in list(ans.keys()):
            ans[dist] += 1
        else:
            ans[dist] = 1
for k in range(1,n):
    if k in list(ans.keys()):
        print((ans[k]))
    else:
        print((0))
# Original solution
#D

line = [int(x) for x in input().split()]
n = line[0]
x = line[1]
y = line[2]

results =[0]*(n+2)

for i in range(1, n):
    for j in range(i+1,n+1):
        yeet = min([abs(j-i), abs(x-i) + 1 + abs(j-y), abs(y-i) + 1 + abs(j-x)])
        results[yeet-1] += 1

for i in range(0, n-1):
    print((results[i]))



# Optimized solution
#D

line = [int(x) for x in input().split()]
n = line[0]
x = line[1]
y = line[2]

results =[0]*(n+2)

for i in range(1, n):
    for j in range(i+1,n+1):
        results[min([abs(j-i), abs(x-i) + 1 + abs(j-y)])-1] += 1

for i in range(0, n-1):
    print((results[i]))
# Original solution
n,x,y=list(map(int,input().split()))
ans=[0]*n
for i in range(1,n+1):
    for j in range(i+1,n+1):
        a1=abs(i-j)
        a2=abs(x-i)+1+abs(y-j)
        a3=abs(y-i)+1+abs(x-j)
        d=min(a1,a2,a3)
        ans[d]+=1

for i in range(1,n):
    print((ans[i]))
   

# Optimized solution
n,x,y=list(map(int,input().split()))
ans=[0]*n #個数を数えるのにバケットを用意する
for i in range(1,n+1): #i<jなるすべての頂点の組について最短距離を求める
 for j in range(i+1,n+1):
   dist1=j-i
   dist2=abs(x-i)+abs(y-j)+1
   dist3=abs(y-i)+abs(x-j)+1
   d=min(dist1,dist2,dist3) #最短距離は上式により求められる
   ans[d]+=1 #最短距離がdとなる組の個数を1増やす
for i in range(1,n):
 print((ans[i]))
# Original solution
n,x,y=list(map(int,input().split()))
ans=[0]*n
for i in range(1,n+1):
    for j in range(i+1,n+1):
        a1=abs(i-j)
        a2=abs(x-i)+1+abs(y-j)
        a3=abs(y-i)+1+abs(x-j)    
        d=min(a1,a2,a3)
        ans[d]+=1
for i in range(1,n):
    print((ans[i]))

# Optimized solution
n,x,y=list(map(int,input().split()))
ans=[0]*n
for i in range(1,n+1):
    for j in range(i+1,n+1):
        a1=j-i
        a2=abs(x-i)+1+abs(y-j)
        a3=abs(y-i)+1+abs(x-j)    
        d=min(a1,a2,a3)
        ans[d]+=1
for i in range(1,n):
    print((ans[i]))
# Original solution
#!/usr/bin/env python3
from collections import deque

n, x, y = list(map(int, input().split()))
to = [[] for _ in range(n)]
for i in range(n):
    if i == 0:
        to[i].append(i+1)
    elif i == n-1:
        to[i].append(i-1)
    else:
        to[i].append(i+1) 
        to[n-i-1].append(n-i-2)
to[x-1].append(y-1)
to[y-1].append(x-1)

anss = [0 for _ in range(n-1)]

# 頂点'start'からBFS
def bfs(start):
    inf = 1001001001
    dist = [inf for _ in range(n)]
    q = deque()
    q.append(start)
    dist[start] = 0 

    while q:
        v = q.popleft()
        for u in to[v]:
            if dist[u] == inf:
                dist[u] = dist[v]+1
                q.append(u)
    # print('start = ', start, ': dist = ', dist)

    for k in range(1, n): 
        cnt = 0 
        for i in range(n):
            if cnt > 3:
                break
            if dist[i]-dist[start] == k:
                anss[k-1] += 1
                cnt += 1
    
for i in range(n):
    bfs(i)
for i in range(n-1):
    print((anss[i]//2))


# Optimized solution
#!/usr/bin/env python3
# TLE解
from collections import deque

n, x, y = list(map(int, input().split()))
to = [[] for _ in range(n)]
for i in range(n):
    if i == 0:
        to[i].append(i+1)
    elif i == n-1:
        to[i].append(i-1)
    else:
        to[i].append(i+1) 
        to[n-i-1].append(n-i-2)
to[x-1].append(y-1)
to[y-1].append(x-1)

ans = [0 for _ in range(n)]

# 頂点'start'からBFS
def bfs(start):
    inf = 1001001001
    dist = [inf for _ in range(n)]
    q = deque()
    q.append(start)
    dist[start] = 0 

    while q:
        v = q.popleft()
        for u in to[v]:
            if dist[u] == inf:
                dist[u] = dist[v]+1
                q.append(u)
    # print('start = ', start, ': dist = ', dist)

    # for k in range(1, n):
    #     for i in range(n):
    #         if dist[i]-dist[start] == k:
    #             ans[k-1] += 1

    for i in range(n):
        ans[dist[i]] += 1
    
for i in range(n):
    bfs(i)
for i in range(1, n): 
    print((ans[i]//2))
# Original solution
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)

# Optimized solution
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)
# Original solution
import math
from collections import defaultdict

def main():
    _ = int(eval(input()))
    nums = list(map(int, input().split()))
    n = len(nums)
    nums.sort()

    nums_cnt = defaultdict(int)
    for num in nums:
        nums_cnt[num] += 1

    cnt = 0
    #print(num_bin_digits)

    for cur in reversed(list(range(n))):
        num = nums[cur]
        if nums_cnt[num] <= 0:
            continue

        power_of_2 = 1 << math.ceil(math.log2(num))

        pair = power_of_2 - num


        if pair != 0 and nums_cnt[pair] > 0:
            nums_cnt[pair] -= 1
            nums_cnt[num] -= 1
            cnt += 1
        elif pair == 0 and nums_cnt[num] >= 2:
            nums_cnt[num] -= 2
            cnt += 1


        '''
        idx = bisect.bisect_left(nums, pair)
        if idx >= cur or nums[idx] != pair:
            #print('continue',pair, idx)
            continue

        while used[idx]:
            idx += 1

        if nums[idx] == pair:
            used[idx] = True
            cnt += 1

        #print(idx, num, power_of_2, pair)
        #print(cnt, nums, used)
        '''

        #print(nums_cnt)

    print(cnt)

    return

main()

# Optimized solution
import math
from collections import defaultdict

def main():
    n = int(eval(input()))
    nums = list(map(int, input().split()))
    nums.sort()

    nums_cnt = defaultdict(int)
    for num in nums:
        nums_cnt[num] += 1

    cnt = 0
    for num in reversed(nums):
        if nums_cnt[num] <= 0:
            continue

        power_of_2 = 1 << math.ceil(math.log2(num))
        pair = power_of_2 - num

        if pair != 0 and nums_cnt[pair] > 0:
            nums_cnt[pair] -= 1
            nums_cnt[num] -= 1
            cnt += 1
        elif pair == 0 and nums_cnt[num] >= 2:
            nums_cnt[num] -= 2
            cnt += 1

    print(cnt)
    return

main()
# Original solution
import bisect

import collections


n = int(eval(input()))
a = list(map(int, input().split()))
a_counter = collections.Counter(a)
a_keys = sorted(list(a_counter.keys()), reverse=True)

targets = []

t = 0
vt = 1
for v in a:
    while v >= vt:
        t += 1
        vt *= 2
        targets.append(vt)
targets.reverse()


cnt = 0
for key in a_keys:
    if a_counter[key] <= 0:
        continue
    for t in targets:
        if key == t-key:
            p = max(0, min(a_counter[key], a_counter[t-key])) // 2
        else:
            p = max(0, min(a_counter[key], a_counter[t-key]))
        a_counter[key] -= p
        a_counter[t-key] -= p
        cnt += p
print(cnt)


# Optimized solution
import bisect

import collections


n = int(eval(input()))
a = list(map(int, input().split()))
a_counter = collections.Counter(a)
a_keys = sorted(list(a_counter.keys()), reverse=True)

targets = []

t = 0
vt = 1
for v in a:
    while v >= vt:
        t += 1
        vt *= 2
        targets.append(vt)
targets.reverse()


cnt = 0
for key in a_keys:
    if a_counter[key] <= 0:
        continue
    for t in targets:
        if key >= t:
            break
        if key == t-key:
            p = max(0, min(a_counter[key], a_counter[t-key])) // 2
        else:
            p = max(0, min(a_counter[key], a_counter[t-key]))
        a_counter[key] -= p
        a_counter[t-key] -= p
        cnt += p
print(cnt)
# Original solution
n = int(eval(input()))
a = list(map(int,input().split()))
a.sort(reverse=True)
u = [0 for i in range(len(a))]

def binarySearch(alist, item,exhi):
    first = 0
    last = len(alist)-1
    found = False

    while first<=last and not found:
        midpoint = (first + last)//2
        if alist[midpoint] == item and u[midpoint] <= 0 and midpoint != exhi:
            found = True
            u[midpoint] += 1
        else:
            if item > alist[midpoint]:
                last = midpoint-1
            else:
                first = midpoint+1

    return found


b = [2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768, 65536, 
     131072, 262144, 524288, 1048576, 2097152, 4194304, 8388608, 16777216, 33554432, 
     67108864, 134217728, 268435456, 536870912]

sum = 0
i = 0

#print(a)
while True:

    if u[i] > 0:
        i = i + 1
        if i >= len(a)-1:
            break        
        continue

    t = 0
    for bb in b :
        if bb > a[i]:
            t = bb - a[i]
            break
    
    if t > a[i]:
        i = i + 1
        if i >= len(a)-1:
            break
        continue

    if t in a :
        idx = 0
        while True:
            try:
                idx = a.index(t,idx)
                if u[idx] == 0 and idx != i:
                    u[idx] += 1
                    sum += 1
                    break
                elif idx == i:
                    break
            except:
                break
            
    i = i + 1
    if i >= len(a)-1:
        break

print(sum)

# Optimized solution
from bisect  import bisect_left

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

sum = 0
for i in range (len(a)-1,-1,-1):

    b = 1
    while b <= a[i]:
        b = b<<1
    t = b - a[i]
    #print("2^",t)

    k = bisect_left(a,t)
    if a[k] == t and k < i:
        sum += 1
        a[k] -= 0.1
        a[i] += 0.1
print(sum)
# Original solution
def main():
    n = int(eval(input()))
    a = list(map(int, input().split()))
    dic = {}
    for v in a:
        if v in dic:
            dic[v] += 1
        else:
            dic[v] = 1
    key = [v for v in list(dic.keys())]
    key.sort(reverse=True)
    ans = 0
    for v in key:
        num = dic[v]
        if num > 0:
            for i in reversed(list(range(1, 35))):
                target = 2**i
                if 2*v < target or target < v:
                    continue
                u = target - v
                if v == u:
                    z = dic[v]//2
                    ans += z
                    dic[v] -= 2*z
                elif u in dic:
                    x, y = dic[v], dic[u]
                    z = 0
                    if x < y:
                        z = x
                    else:
                        z = y
                    dic[v] -= z
                    dic[u] -= z
                    ans += z
                if dic[v] == 0:
                    break
    print(ans)

if __name__ == "__main__":
    main()

# Optimized solution
def main():
    n = int(eval(input()))
    a = list(map(int, input().split()))
    dic = {}
    for v in a:
        if v in dic:
            dic[v] += 1
        else:
            dic[v] = 1
    key = [v for v in list(dic.keys())]
    key.sort(reverse=True)
    ans = 0
    for v in key:
        num = dic[v]
        if num > 0:
            for i in reversed(list(range(1, 32))):
                target = 2**i
                if 2*v < target:
                    continue
                if target < v:
                    break
                u = target - v
                if v == u:
                    z = dic[v]//2
                    ans += z
                    dic[v] -= 2*z
                elif u in dic:
                    x, y = dic[v], dic[u]
                    z = 0
                    if x < y:
                        z = x
                    else:
                        z = y
                    dic[v] -= z
                    dic[u] -= z
                    ans += z
                if dic[v] == 0:
                    break
    print(ans)

if __name__ == "__main__":
    main()
# Original solution
import bisect

N = int(eval(input()))
A = list(map(int,input().split()))
A.sort()
ans = 0
L=0
t=31
while(t>0):
    if len(A) == 0:
        break
    if A[-1] >= (1 << t):
        t -= 1
        L = 0
        continue
    if A[-1] < (1 << (t-1)):
        t -= 1
        L = 0
        continue

    large = A.pop(-1)
    tmp = bisect.bisect_left(A,(1<<t)-large,lo=L,hi=len(A))
    if tmp == len(A):
        t -= 1
        L = 0
        continue
    if A[tmp] == (1<<t)-large:
        del A[tmp]
        ans += 1
        L = max(0,tmp-1)

print(ans)


# Optimized solution
N = int(eval(input()))
A = list(map(int,input().split()))
A.sort(reverse=True)
dic = {}
for a in A:
    dic[a] = dic.get(a,0)+1
ans = 0

for a in A:
    small = (1<<(len(format(a,"b")))) - a
    if small == a:
        if dic[a] >= 2:
            dic[a] -= 2
            ans += 1
        continue
    if dic.get(a,0)>0 and dic.get(small,0)>0:
        dic[a] -= 1
        dic[small] -= 1
        ans += 1
print(ans)
# Original solution
from collections import defaultdict
import sys
input = sys.stdin.readline

N = int(eval(input()))
A = list(map(int, input().split()))
A.sort(reverse=True)
cnt = defaultdict(int)
for a in A:
    cnt[a] += 1
n = 1
while n <= 2 * A[0]:
    n *= 2
n //= 2
ans = 0
while n > 0:
    for a in A:
        if cnt[a] == 0:
            continue
        b = n - a
        if b > a:
            break
        c = 0
        if b == a and cnt[a] > 1:
            c = cnt[a] // 2
        elif b != a and cnt[b] > 0:
            c = min(cnt[a], cnt[b])
        cnt[a] -= c
        cnt[b] -= c
        ans += c
    n //= 2
print(ans)

# Optimized solution
from collections import defaultdict
import sys
input = sys.stdin.readline

N = int(eval(input()))
A = list(map(int, input().split()))
A.sort(reverse=True)
cnt = defaultdict(int)
for a in A:
    cnt[a] += 1
n = 1
while n <= 2 * A[0]:
    n *= 2
n //= 2
ans = 0
while n > 0:
    for a in A:
        if cnt[a] == 0:
            continue
        b = n - a
        if b < 0:
            continue
        if b > a:
            break
        c = 0
        if b == a and cnt[a] > 1:
            c = cnt[a] // 2
        elif b != a and cnt[b] > 0:
            c = min(cnt[a], cnt[b])
        cnt[a] -= c
        cnt[b] -= c
        ans += c
    n //= 2
print(ans)
# Original solution
import math
import bisect

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

alist.sort()
#print(alist)

flist=[False]*N
answer=0
for i in reversed(list(range(N))):
  if flist[i]:
    continue
  
  p1=alist[i]
  p2=2**math.ceil(math.log(p1+1,2))-p1
  #print(p1,p2)
  
  index1 = bisect.bisect_left(alist,p2,0,i+1)  
  index2 = bisect.bisect_right(alist,p2,index1,i+1)  
  #print(index1,index2)
  for j in range(index1,index2):
    if j != i and not flist[j]:
      flist[i]=True
      flist[j]=True
      answer+=1
      break
  
#print(flist)    
print(answer)


# Optimized solution
import bisect
N=int(eval(input()))
alist=list(map(int,input().split()))
alist.sort(reverse=True)

blist=[]
for a in alist:
  a2=a
  digit_a2=0
  while(a2>0):
    a2>>=1
    digit_a2+=1
  b=2**(digit_a2)-a
  blist.append(b)
#print(alist)
#print(blist)

dic_a={}
for a in alist:
  if a in dic_a:
    dic_a[a]+=1
  else:
    dic_a[a]=1

answer=0
for i in range(N):
  a=alist[i]
  b=blist[i]
  if a==b:
    if dic_a[a]>1:
      dic_a[a]-=2
      answer+=1
      #print(a,a)
  else:
    if dic_a[a]>0 and b in dic_a and dic_a[b]>0:
      dic_a[a]-=1
      dic_a[b]-=1
      answer+=1
      #print(a,b)
    
print(answer)
# Original solution
from collections import defaultdict
import sys
input = sys.stdin.readline
N = int(eval(input()))
a = list(map(int, input().split()))
pow2 = [1]
for i in range(31):
    pow2.append(pow2[-1] * 2)
a = sorted(a, reverse=True)
d = defaultdict(int)
for i in a:
    d[i] += 1


num = 0
for i in range(N):
    if d[a[i]] == 0:
        continue
    for k in range(30, -1, -1):
        if pow2[k] - a[i] != a[i]:
            if d[pow2[k] - a[i]] > 0 and d[a[i]] > 0:
                p = min(d[pow2[k] - a[i]], d[a[i]])
                num += p
                d[pow2[k] - a[i]] -= p
                d[a[i]] -= p
                break
        else:
            if d[a[i]] >= 2:
                num += d[a[i]] // 2
                d[a[i]] %= 2
                break
print(num)

# Optimized solution
from collections import defaultdict
import sys
input = sys.stdin.readline
N = int(eval(input()))
a = list(map(int, input().split()))
pow2 = [1]
for i in range(31):
    pow2.append(pow2[-1] * 2)
a = sorted(a, reverse=True)
d = defaultdict(int)
for i in a:
    d[i] += 1


num = 0
for i in range(N):
    if d[a[i]] == 0:
        continue
    for k in range(30, -1, -1):
        inv = pow2[k] - a[i]
        if inv < 0 or inv > a[i]:
            continue
        if inv != a[i]:
            if d[inv] > 0 and d[a[i]] > 0:
                p = min(d[inv], d[a[i]])
                num += p
                d[inv] -= p
                d[a[i]] -= p
                break
        else:
            if d[a[i]] >= 2:
                num += d[a[i]] // 2
                d[a[i]] %= 2
                break
print(num)
# Original solution
from collections import Counter

def larger_nibeki(i):
	return 2 ** len(format(i, "b"))

n = int(eval(input()))
a = list(map(int, input().split()))
a.sort(reverse=True)
ans = 0
c = Counter(a)

#print(larger_nibeki(n))
for i in range(n):
	if c[a[i]] == 0:
		continue
	else:
		c[a[i]] -= 1
		if c[larger_nibeki(a[i]) - a[i]] > 0:
			ans += 1
			c[larger_nibeki(a[i]) - a[i]] -= 1

print(ans)

# Optimized solution
from collections import Counter

def larger_nibeki(i):
	return 2 ** len(format(i, "b"))

n = int(eval(input()))
a = list(map(int, input().split()))
a.sort(reverse=True)
ans = 0
c = Counter(a)

for i in range(n):
	if c[a[i]] == 0:
		continue
	else:
		c[a[i]] -= 1
		if c[larger_nibeki(a[i]) - a[i]] > 0:
			ans += 1
			c[larger_nibeki(a[i]) - a[i]] -= 1

print(ans)
# Original solution
from bisect import bisect
N = int(eval(input()))
*A, = list(map(int, input().split()))
B = {}
for a in A:
    B[a] = B.get(a, 0) + 1
R = sorted(B.items())
C = []; D = []
for k, v in sorted(B.items()):
    C.append(k)
    D.append(v)
M = len(C)
j = 0
ans = 0
for i in range(M-1, -1, -1):
    if D[i] == 0:
        continue
    a = C[i]
    b = 2**(a).bit_length()
    j = bisect(C, b-a-1)
    if j < M and C[j] == b-a:
        if i == j:
            ans += D[i]//2
            D[i] %= 2
        else:
            c = min(D[i], D[j])
            ans += c
            D[i] -= c; D[j] -= c
print(ans)

# Optimized solution
from bisect import bisect
N = int(eval(input()))
*A, = list(map(int, input().split()))
B = {}
for a in A:
    B[a] = B.get(a, 0) + 1
R = sorted(B.items())
C = []; D = []
for k, v in sorted(B.items()):
    C.append(k)
    D.append(v)
M = len(C)
j = 0
ans = 0
for i in range(M-1, -1, -1):
    if D[i] == 0:
        continue
    a = C[i]
    b = 2**a.bit_length()
    j = bisect(C, b-a-1)
    if j < M and C[j] == b-a:
        if i == j:
            c = D[i]//2
        else:
            c = min(D[i], D[j])
        ans += c
        D[i] -= c; D[j] -= c
print(ans)