n = STDIN.gets.to_i
numbers = STDIN.gets.split(' ').map(&:to_i)

# 最大値とペアを組んでべき乗になる値は一意
# A1 <= A2 ... <= An
# x = An
# 2のべき乗になるようなyを選ぶ
# x < x + y <= 2x

numbers = numbers.sort.reverse
count = 0

loop do
  break if numbers.empty?

  max = numbers.shift
  tmp = max
  power = 0
  while tmp > 0
    tmp /= 2
    power += 1
  end

  index = numbers.index(2 ** power - max)
  # p '----'
  # p max, power, index
  # p '----'
  if index
    numbers.delete_at(index)
    count += 1
  end
end

puts count
