#!/usr/bin/env ruby

class Object
  def tapp
    debug = false
    if debug
      require 'PP'
      tap { PP.pp(self, $stderr) }
    else
      self
    end
  end
end

n = gets.to_i
as = gets.split.map(&:to_i)

pows = []
v = 2
while v < 2_000_000_000
  pows << v
  v *= 2
end

graph = Hash.new { |h, k| h[k] = [] }
(0...(n - 1)).each do |x|
  ((x + 1)...n).each do |y|
    if pows.include?(as[x] + as[y])
      graph[x] << y
      graph[y] << x
    end
  end
end

# graph.tapp
cnt = 0
loop do
  x = nil
  y = nil
  graph.each do |k, v|
    if v.count == 1
      cnt += 1
      x = k
      y = v.first
      break
    end
  end
  unless x && y
    break
  end
  # as.tapp
  # graph.tapp
  graph.delete(x)
  graph.delete(y)
  graph.each do |_, v|
    v.delete(y)
  end
  # graph[y].delete(x)
end
puts cnt