N = gets.to_i
array = [],x=2,cnt=0
array = gets.split.map(&:to_i)
array.sort!.reverse!
array.each_index {|i|
  while x <= array[i]
    a = array[i+1..-1].bsearch_index {|b| b==(array[i]-x).abs}
    if a
      array.delete_at(i+1+a)
      cnt += 1
      break
    end
    x *=2
  end
  x = 2
}
puts cnt
