def div(n)
  x = 0
  while n>1
    x += 1
    n /= 2
  end
  list = [2]
  x.times do |i|
    list << list[i]*2
  end
  return list
end

size = gets.to_i
a_list = gets.split.map(&:to_i).sort.reverse
res = 0
two = div(a_list.first)

a_list.each_with_index do |x, i|
  two.pop if two.last < x
  target = two.last - x

  (i+1).upto(size-1) do |y|
    if target == a_list[y]    
      res += 1
      a_list.delete_at(y)
      break
    end
  end
end

puts res
