_n = STDIN.gets.to_i
numbers = STDIN.gets.split(' ').map(&:to_i)

# 最大値とペアを組んでべき乗になる値は一意
# A1 <= A2 ... <= An
# x = An
# 2のべき乗になるようなyを選ぶ
# x < x + y <= 2x

map = Hash.new { 0 }

numbers.each do |n|
  map[n] += 1
end

count = 0
map.keys.sort.reverse.each do |number|
  tmp = number
  power = 0
  while tmp > 0
    tmp /= 2
    power += 1
  end

  if map[number] <= 0
    next
  end

  base = 2 ** power - number

  if map[base] <= 0
    next
  end

  # p "number: #{number} base: #{base}"
  # p map[2 ** power - number]

  if base == number
    add = map[number] / 2
    map[number] /= 2
    count += add
    next
  end

  add = if map[base] > map[number]
          map[number]
        else
          map[base]
        end
  map[2 ** power - number] -= add
  map[number] -= add
  count += add
end

puts count
