output_description: Print the maximum possible number of pairs such that the sum of the integers
  written on each pair of balls is a power of 2.
  
  * * *
input_description: Input is given from Standard Input in the following format:
  
      
      
      N
      A_1 A_2 ... A_N
attempt: _ = input()
  s = input()
  data = list(map(int, s.split()))
  
  even = []
  odd = []
  for it in data:
      if it % 2 == 0:
          even.append(it)
      else:
          odd.append(it)
  
  
  # src is sorted
  def get_pair(src, target):
      pair = []
      pair_id = []
      for i, first in enumerate(src):
          if first > target:
              break
          for j, second in enumerate(src[i + 1 :]):
              if first + second == target:
                  pair.append([first, second])
                  pair_id.append([i, j + i + 1])
              elif first + second > target:
                  break
  
      #     print('pair,',pair)
      #     print('pair_id',pair_id)
      return pair, pair_id
  
  
  two = []
  tmp = 1
  while True:
      tmp *= 2
      if tmp > max_num:
          break
      two.append(tmp)
  
  # for odd
  all_pair = []
  all_pair_id = []
  if len(odd) > 1:
      for target in two:
          pair, pair_id = get_pair(odd, target)
          all_pair += pair
          all_pair_id += pair_id
  
  # make list
  p_list = [[] for it in range(len(odd))]
  for it in all_pair_id:
      p_list[it[0]].append(it[1])
      p_list[it[1]].append(it[0])
  
  cnt = 0
  while True:
      END = True
      for i, it in enumerate(p_list):
          if len(it) == 1:
              p_list[it[0]] = []
              p_list[i] = []
              END = False
              cnt += 1
              break
      if END:
          break
  
  # for even
  all_pair = []
  all_pair_id = []
  if len(even) > 1:
      for target in two:
          pair, pair_id = get_pair(even, target)
          all_pair += pair
          all_pair_id += pair_id
  
  # make list
  p_list = [[] for it in range(len(even))]
  for it in all_pair_id:
      p_list[it[0]].append(it[1])
      p_list[it[1]].append(it[0])
  
  while True:
      END = True
      for i, it in enumerate(p_list):
          if len(it) == 1:
              p_list[it[0]] = []
              p_list[i] = []
              END = False
              cnt += 1
              break
      if END:
          break
  print(cnt)
  
problem_description: Statement
  
  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.
samples: [{"input": "3\n    1 2 3", "output": "1\n    \n\nWe can form one pair whose sum of the written numbers is 4 by pairing the\nfirst and third balls. Note that we cannot pair the second ball with itself.\n\n* * *"}, {"input": "5\n    3 11 14 5 13", "output": "2"}]