n = gets.to_i
a = gets.chomp.split(" ").map(&:to_i)
a = a.sort
ans = 0
two = []
for i in 1..40
  two.push(2**i)
  if 2**i > 2*(10**9)
    two.delete_at(-1)
    break
  end
end
for i in 1..two.length
  min = 0
  max = a.length-1
  while max > min
    if a[min] + a[max] > two[-i]
      max -= 1
    elsif a[min] + a[max] < two[-i]
      min += 1
    elsif a[min] + a[max] == two[-i]
      ans += 1
      a.delete_at(min)
      a.delete_at(max)
      max -= 2
    end
  end
end
puts ans