N, M, K = gets.split.map(&:to_i) op, *B = gets.split B.map!(&:to_i) A = [] * N N.times do A << gets.chomp.to_i end z = 0 if op == '+' d = Hash.new(0) B.each do |b| d[b % K] += 1 end A.each do |a| z += d[-a % K] end else da = Hash.new(0) db = Hash.new(0) B.each do |b| g = b.gcd(K) db[g] += 1 end A.each do |a| g = a.gcd(K) da[a.gcd(K)] += 1 end da.each do |ka, va| db.each do |kb, vb| if ka * kb % K == 0 z += va * vb end end end end p z