N = STDIN.gets.chomp.to_i
A = STDIN.gets.chomp.split(' ').map(&:to_i)

A.sort!

hash = {}
cnt = 0

A.each do |ai|
  hash[ai] ||= 0
  hash[ai] += 1
end

A.reverse_each do |ai|
  bits = ai.bit_length
  next_pow2 = 2 ** bits
  diff = next_pow2 - ai

  # puts hash
  # puts "#{ai}, next_p2:#{next_pow2}, diff:#{diff}"

  if hash.key?(diff) && hash[diff] > 0
    cnt += 1
    hash[diff] -= 1
  end
end

puts cnt
