n = gets.chomp.to_i
a = gets.chomp.split(' ').map(&:to_i).sort

i = n - 1
answer = 0
while (i >= 0)
  l = a[i].to_s(2).length
  t = (1 << l) - a[i]
  a.delete_at(i)
  i -= 1
  j = a.bsearch_index { |k| t - k }
  if j
    a.delete_at(j)
    answer += 1
    i -= 1
  end
end
puts answer
