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

c = {}
n.times do |i|
  if c[a[i]]
    c[a[i]] += 1
  else
    c[a[i]] = 1
  end
end

answer = 0
(n - 1).downto(0) do |i|
  next if c[a[i]] <= 0
  c[a[i]] -= 1
  l = a[i].to_s(2).length
  t = (1 << l) - a[i]
  if c[t] && c[t] > 0
    c[t] -= 1
    answer += 1
  end
end
puts answer
