N = readline.to_i
ai = readline.split.map(&:to_i).sort

T1 = Math.log2(ai[0]).ceil
T2 = Math.log2(ai[-1]).floor


def find_matching(a,counts)
  i = 0
  j = a.size-1
  while a[i] < 0 and a[j] > 0
    # pp "i,j,#{a[i]},#{a[j]}"
    if -a[i] == a[j]
      counts[i] += 1
      counts[j] += 1
      i += 1
      j -= 1
    elsif -a[i] > a[j]
      i += 1
    elsif -a[i] < a[j]
      j -= 1
    end
  end
end

#pp T1,T2,ai

counts = Array.new(N,0)
(T1..T2).each do |t|
  x = 2**t
  mapped = ai.map {|a| a-x }
  find_matching(mapped, counts)
end

#pp counts
puts (counts.count {|x| x>0})/2
