def div(n)
  x = 0
  while n>1
    x += 1
    n /= 2
  end
  x += 1
end

n = gets.to_i
a_list = gets.split.map(&:to_i).sort.reverse
size = a_list.length
res = 0

a_list.each_with_index do |x, i|
  target = 2**div(x) - x
  (i+1).upto(size-1) do |y|
    if target == a_list[y]    
      res += 1
      a_list[y] = -99999999999
      break
    end
  end
end

puts res
