#!/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

freq = Hash.new(0)
as.each { |a| freq[a] += 1 }

m = freq.size
graph = Hash.new { |h, k| h[k] = [] }
(0...(m - 1)).each do |x|
  ((x + 1)...m).each do |y|
    vx = freq.keys[x]
    vy = freq.keys[y]
    if pows.include?(vx + vy)
      graph[vx] << vy
      graph[vy] << vx
    end
  end
end

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

  freq[x] -= 1
  freq[y] -= 1

  if freq[x] == 0
    graph.delete(x)
    graph[y].delete(x)
  end
  if freq[y] == 0
    graph.delete(y)
    graph.each do |_, v|
      v.delete(y)
    end
  end
end

freq.each do |k, v|
  while pows.include?(k) && v >= 2
    cnt += 1
    v -= 2
  end
end

puts cnt
