import sys, math from collections import Counter n, m, k = map(int, input().split()) op, *B = input().split() ca = Counter({"+":int(a)%k, "*":math.gcd(int(a), k)}[op] for a in sys.stdin) cb = Counter({"+":-int(b)%k, "*":math.gcd(int(b), k)}[op] for b in B) if op=="+": print(sum(ca[i]*cb[i] for i in ca if i in cb)) else: print(sum(ca[i]*cb[j] for i in ca for j in cb if i*j%k==0))