n,m,k,op,*ab = open(0).read().split() m,k = int(m),int(k) from collections import Counter from math import gcd a = map(int,ab[:m]) b = [int(i)%k for i in ab[m:]] if op == "+": d = Counter(b) print(sum(d[-ai%k] for ai in a)) exit() r = [] for i in range(1,k+1): if i*i > k: break if k%i==0: r.append(i) if i*i != k: r.append(k//i) da = Counter(gcd(i,k) for i in a) db = Counter(gcd(i,k) for i in b) ans = 0 for ai,w in da.items(): for bi,v in db.items(): if ai*bi%k==0: ans += w*v print(ans)