def solve(ai)
  ai.sort!
  t1 = Math.log2(ai[0]).ceil
  t2 = Math.log2(ai[-1]).floor
  #pp t1,t2,ai

  def find_matching(a,counts)
    i = 0
    j = a.size-1
    while a[i] <= 0 and a[j] >= 0 and i < j
      # 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


  counts = Array.new(ai.size,0)
  (t1..t2).each do |t|
    x = 2**t
    mapped = ai.map {|a| a-x }
    find_matching(mapped, counts)
    #pp "mapped", mapped, "counts:", counts
  end

  # pp counts
  i = 0
  num_matching = 0
  while i < counts.size
    n = counts[i]
    num_a = 1
    while ai[i] == ai[i+1]
      i += 1
      n += counts[i]
      num_a += 1
    end
    i += 1
    num_matching += (num_a<=n) ? num_a : n
  end

  num_matching/2
end

if __FILE__ == $0
  N = readline.to_i
  ai = readline.split.map(&:to_i)

  puts solve(ai)
end
# puts (counts.count {|x| x>0})/2
