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

print h if DBG

for x in h.keys
  for t in 0..31
    y = 2**t - x
    if x == y
      h[x][1] = true
    elsif h.keys.include?(y)
      h[x][2] << y
    end
  end
end

puts "----" if DBG
print h if DBG
puts "----" if DBG

slf = 0
pairs = 0
for x in h.keys
  print h[x][2] if DBG
  puts "====" if DBG
  pairslocal = h[x][2].empty? ? 0 :
       h[x][2].map{|y| h[y][0]}.inject(:+)
  if pairslocal > h[x][0]
    pairslocal = h[x][0]
  end
  printf("pl:%d\n", pairslocal) if DBG
  pairs += [pairslocal, h[x][0]].min
  rest = h[x][0] - pairslocal
  slf += rest / 2
end

print slf + pairs/2
