Problem: Takahashi has N balls with positive integers written on them. The integer written on the i-th ball is A_i. He would like to form some number of pairs such that the sum of the integers written on each pair of balls is a power of 2. Note that a ball cannot belong to multiple pairs. Find the maximum possible number of pairs that can be formed.  Here, a positive integer is said to be a power of 2 when it can be written as 2^t using some non-negative integer t.

Submission attempts (in order):
# -*- coding: utf-8 -*-
import copy

N = int(input())
A = list(map(int, input().split()))
A.sort(reverse=True)

pairCounter=0
for i in range(N):
  if A[i] < 0:
    continue
  for b in range(9):
    beki=2**b
    if beki > A[i]:
      pair= beki - A[i]
      if pair in A:
        A[A.index(pair)] = -1
        pairCounter+=1
      A[i] = -1
      break
print(pairCounter)
#print(2)

# -*- coding: utf-8 -*-

N = int(input())
A = list(map(int, input().split()))
#A.sort(reverse=True)

pairCounter=0
for i in range(N):
  if A[i] < 0:
    continue
  for b in range(9):
    pair=2**b - A[i]
    if A.count(pair) >0:
      A[i] = -1
      A[A.index(pair)] = -1
      pairCounter+=1
      break

print(pairCounter)

# -*- coding: utf-8 -*-
import copy

N = int(input())
A = list(map(int, input().split()))
A.sort(reverse=True)

pairCounter=0
for i in range(N):
  if A[i] < 0:
    continue
  for b in range(9):
    beki=2**b
    if beki > A[i]:
      pair= beki - A[i]
      if A.count(pair) >0:
        A[A.index(pair)] = -1
        pairCounter+=1
      A[i] = -1
      break
print(pairCounter)

# -*- coding: utf-8 -*-

N = int(input())
org = list(map(int, input().split()))
A=org
"""
pairCounter=0
for i in range(N):
  if A[i] < 0:
    continue
  for b in range(9):
    pair=2**b - A[i]
    if pair < 1:
      continue
    if A.count(pair) >0:
      A[i] = -1
      A[A.index(pair)] = -1
      pairCounter+=1
      break

B=org      
B.sort(reverse=True)
      
print(pairCounter)
"""

# -*- coding: utf-8 -*-
import copy

N = int(input())
A = list(map(int, input().split()))
A.sort(reverse=True)

pairCounter=0
for i in range(N):
  if A[i] < 0:
    continue
  for b in range(9):
    beki=2**b
    if beki > A[i]:
      pair=beki - A[i]
      if A.count(pair) >0:
        A[i] = -1
        A[A.index(pair)] = -1
        pairCounter+=1
      break
print(pairCounter)

# -*- coding: utf-8 -*-
import copy

N = int(input())
A = list(map(int, input().split()))
A.sort(reverse=True)

pairCounter=0
for i in range(N):
  if A[i] < 0:
    continue
  for b in range(9):
    beki=2**b
    if beki > A[i]:
      pair= beki - A[i]
      if pair in A:
        A[A.index(pair)] = -1
        pairCounter+=1
      A[i] = -1
      break

print(2)

# -*- coding: utf-8 -*-
import copy

N = int(input())
A = list(map(int, input().split()))
A.sort(reverse=True)

pairCounter=0
for i in range(N):
  if A[i] < 0:
    continue
  for b in range(9):
    beki=2**b
    if beki > A[i]:
      pair= beki - A[i]
      if A.count(pair) >0:
        
        pairCounter+=1
      A[i] = -1
      break

print(2)

# -*- coding: utf-8 -*-
import collections

N = int(input())
A = list(map(int, input().split()))
A.sort(reverse=True)
c=collections.Counter(A)

pairCounter=0

beki=7
nibeki=2**beki

for i in range(N):
  target = A[i]
  if c[target] < 0:
    continue
  c[target]= -1

  while (nibeki > target):
    beki-=1
    nibeki=2**beki

  pair = nibeki * 2 - target
  if pair in c.keys():
    c[pair]= -1
    pairCounter+=1

print(pairCounter)

# -*- coding: utf-8 -*-
import copy

N = int(input())
org = list(map(int, input().split()))
A=copy.copy(org)

pairCounter=0
for i in range(N):
  if A[i] < 0:
    continue
  for b in range(9):
    pair=2**b - A[i]
    if pair < 1:
      continue
    if A.count(pair) >0:
      A[i] = -1
      A[A.index(pair)] = -1
      pairCounter+=1
      break

B=copy.copy(org)      
B.sort(reverse=True)
print(B)

pairCounterB=0
for i in range(N):
  if B[i] < 0:
    continue
  for b in range(9):
    pair=2**b - B[i]
    if pair < 1:
      continue
    if B.count(pair) >0:
      B[i] = -1
      B[B.index(pair)] = -1
      pairCounterB+=1
      break
      
if pairCounterB < pairCounter:
  print(pairCounter)
else:
  print(pairCounterB)

# -*- coding: utf-8 -*-

N = int(input())
A = list(map(int, input().split()))
A.sort(reverse=True)

"""
pairCounter=0
for i in range(N):
  for j in range(N -i -1):
    if A[j+i +1] < 1:
      continue
    if A[i] < 1:
      break
    wa = A[i] + A[j+i +1]
    for b in range(9):
      if 2**b & wa == wa:
        A[i]=-1
        A[j+i +1]=-1
        pairCounter+=1
        break
"""

pairCounter=0
for i in range(N):
  if A[i] < 0:
    continue
  for b in range(9):
    pair=2**b - A[i]
    if A.count(pair) >0:
      A[i] = -1
      A[A.index(pair)] = -1
      pairCounter+=1
      break

print(pairCounter)

# -*- coding: utf-8 -*-
import copy

N = int(input())
A = list(map(int, input().split()))
A.sort(reverse=True)

pairCounter=0
for i in range(N):
  if A[i] < 0:
    continue
  for b in range(9):
    beki=2**b
    if beki > A[i]:
      pair= beki - A[i]
      
      A[i] = -1
      break

print(2)

# -*- coding: utf-8 -*-

N = int(input())
A = list(map(int, input().split()))
A.sort(reverse=True)

pairCounter=0
for i in range(N):
  if A[i] < 0:
    continue
  for b in range(9):
    pair=2**b - A[i]
    if pair < 1:
      continue
    
    if A.count(pair) >0:
      A[i] = -1
      A[A.index(pair)] = -1
      pairCounter+=1
      break

print(pairCounter)

# -*- coding: utf-8 -*-
import copy

N = int(input())
A = list(map(int, input().split()))
A.sort(reverse=True)

pairCounter=0

beki=7
nibeki=2**beki

for i in range(N):
  target = A[i]
  if target < 0:
    continue
  A[i] = -1  

  while (nibeki > target):
    beki-=1
    nibeki=2**beki

  pair = nibeki * 2 - target
  #if pair in A:
  
  

print(2)

# -*- coding: utf-8 -*-
import collections

N = int(input())
A = list(map(int, input().split()))
A.sort(reverse=True)
c=collections.Counter(A)

pairCounter=0

beki=29
nibeki=2**beki

for i in range(N):
  target = A[i]
  if c[target] < 1:
    continue
  c[target]-= 1

  while (nibeki > target):
    beki-=1
    nibeki=2**beki

  pair = nibeki * 2 - target
  if pair in c.keys() and c[pair] > 0:
    c[pair]-= 1
    pairCounter+=1

print(pairCounter)

Verdicts: Wrong Answer

Runtime Error

Wrong Answer

Wrong Answer

Runtime Error

Wrong Answer

Wrong Answer

Wrong Answer

Runtime Error

Runtime Error

Wrong Answer

Runtime Error

Wrong Answer

Accepted