n = gets.to_i
array = gets.split.map(&:to_i)
even = []
odd = []
exp = []
cnt = 0
array.map { |e|
  if e%2==0
    even << e
  else
    odd << e
  end
}

even.sort!.reverse!
odd.sort!.reverse!

exp_odd = []
exp_even = []

max = even[0]
x = 2
while x < max
  exp_even << x
  x = x*2
end
exp_even << x

even.size.times do |i|
  (i+1).upto(even.size) do |j|
    if even[j]==nil
      break
    end
    if exp_even.include?(even[i]+even[j])
      cnt += 1
      even.delete_at(j)
      break
    end
  end
end

max = odd[0]
x = 2
while x < max
  exp_odd << x
  x = x*2
end
exp_odd << x

odd.size.times do |i|
  (i+1).upto(odd.size) do |j|
    if odd[j]==nil
      break
    end
    #puts odd[i]
    #puts odd[j]
    #puts odd[i]+odd[j]
    #puts
    if exp_odd.include?(odd[i]+odd[j])
      cnt += 1
      odd.delete_at(j)
      break
    end
  end
end

puts cnt
