import sys, math from itertools import groupby, product n, m, k = map(int, input().split()) op, *B = input().split() def c(it): return [(i, len(list(u))) for i, u in groupby(sorted(it))] if op=="+": s = sorted(c(int(a)%k for a in sys.stdin) + c(-int(b)%k for b in B)) print(sum(u*v for (i, u), (j, v) in zip(s, s[1:]) if i==j)) else: s = product( c(math.gcd(int(a), k) for a in sys.stdin), c(math.gcd(int(b), k) for b in B)) print(sum(u*v for (i, u), (j, v) in s if i*j%k==0))