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) mod_counter_plus = Hash.new(0) B.each do |b| mod_counter[b % (K - 1)] += 1 mod_counter_plus[b % K] += 1 end A.each do |a| if op == '+' mk = a % K ans += mod_counter_plus[K - mk] else if a % K == 0 ans += M else ans += mod_counter[1] + mod_counter[K - 1 - a.mod_inverse(K - 1)] end end end puts ans