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 mod_counter = Hash.new(0) B.each do |b| mod_counter[b % 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 ans += mod_counter[0] + mod_counter[a.mod_inverse(K)] end end end puts ans