N,*xs = `dd`.split.map(&:to_i)
xn = Hash.new(0)
xs.each{ |x| xn[x] = (xn[x] || 0) + 1 }
xs.sort!.reverse!
ans = 0
P = (0..xs[0].bit_length).map{ |b| 1 << b }
xs.each{ |x|
  next if xn[x] == 0
  xn[x] -= 1
  m = x.bit_length
  y = P[m] - x
  if xn[y] > 0
    ans += 1
    xn[P[m] - x] -= 1
  end
}
p ans
