N = gets.to_i
A = gets.split.map(&:to_i).sort

odds = A.select(&:odd?)
evens = A.select(&:even?)

def f(n)
  b = 2

  while b < n
    b *= 2
  end

  b - n
end

def c(list)
  cnt = 0

  until list.empty?
    n = list.pop
    t = f(n)
    r = list.bsearch_index { |x| x >= t }

    if r && list[r] == t
      list.delete_at(r)
      cnt += 1
    end
  end

  cnt
end

puts c(odds) + c(evens)
