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

  pow = 0
  1.upto(30) do |i|
    if (2 ** i) > max
      pow = i
      break
    end
  end

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

puts count
