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

powers = 1.upto(30).map do |t|
  2 ** t
end.reverse

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

numbers.sort.reverse
count = 0

loop do
  break if numbers.empty?

  max = numbers.pop
  numbers.each_with_index do |n, i|
    if powers.include?(max + n)
      numbers.delete_at(i)
      count += 1
    end
  end
end

puts count
