n, m, k = gets.chomp.split.map!(&:to_i) op, *b = gets.chomp.split b.map!(&:to_i) a = [] * n n.times do a << gets.chomp.to_i % k end z = 0 if op == '+' h = Hash.new(0) b.each do |bi| h[bi % k] += 1 end a.each do |ai| z += h[k - ai] end else ha = Hash.new(0) hb = Hash.new(0) a.each do |ai| ha[ai.gcd(k)] += 1 end b.each do |bi| hb[bi.gcd(k)] += 1 end ha.map{|ka, va| hb.map{|kb, vb| if ka * kb % k == 0 z += va * vb end } } end puts z