
DBG = !true
nl = "\n"

n = gets.to_i
a = gets.split.map{|x| x.to_i}
h = {}
for i in 0...a.size
  x = a[i]
  if h.keys.include?(x)
    h[x] += 1
  else
    h[x] = 1
  end
end

b = []
for k in h.keys
  b << [k, h[k]]
end
b.sort_by!{|x| x[0]}

puts "bsz: #{b.size}" if DBG
print b if DBG
puts "" if DBG

sum = 0
(b.size - 1).downto(0) { |i|
  c = b[i]
  key   = c[0]
  #card  = c[1]
  card  = h[key]

  # find msb
  msb = 2**32
  while (msb & key) == 0
    msb /= 2
  end

  bud = 2*msb - key
  print "i: #{i} ky:#{key} cd:#{card} msb:#{msb} bud:#{bud}#{nl}" if DBG

  next if !h.keys.include?(bud)
  if bud != key
    bcard = h[bud]
    npairs = [card, bcard].min
    sum += npairs
    h[bud] -= npairs
  else
    npairs = card/2
    sum += npairs
  end
}

print sum
