
DBG = !true
DBG2 = !true
nl = "\n"

n = gets.to_i
a = gets.split.map{|x| x.to_i}
puts "after split" if DBG2

h = Hash.new(0)
for i in 0...a.size
  x = a[i]
  #if h.keys.include?(x)
    h[x] += 1
  #else
  #  h[x] = 1
  #end
end
puts "after create h" if DBG2

b = []
for k in h.keys
  b << k
end
b.sort!

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

puts "before loop" if DBG2

sum = 0
(b.size - 1).downto(0) { |i|
  c = b[i]
  key   = c
  #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

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

print sum
