class Integer def mod_inverse(mod) self.pow(mod - 2, mod) end end N, M, K = gets.split.map(&:to_i) op, *B = gets.chomp.split B.map!(&:to_i) A = N.times.map { gets.to_i } ans = 0 gcd_counter = Hash.new(0) mod_counter = Hash.new(0) B.each do |b| mod_counter[b % K] += 1 gcd_counter[b.gcd(K)] += 1 end A.each do |a| if op == '+' mk = a % K ans += mod_counter[K - mk] else if a % K == 0 ans += M else gcd_counter.each do |e, cnt| ans += cnt if (e * a) % K == 0 end end end end puts ans