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_a = Hash.new(0) gcd_counter_b = Hash.new(0) mod_counter = Hash.new(0) B.each do |b| mod_counter[b % K] += 1 gcd_counter_b[b.gcd(K)] += 1 end A.each do |a| gcd_counter_a[a.gcd(K)] += 1 end if op == '+' A.each do |a| if op == '+' ans += mod_counter[K - a % K] end end else gcd_counter_a.each do |a, m| gcd_counter_b.each do |b, n| next if (a * b) % K != 0 ans += m * n end end end puts ans