import sys from math import gcd def I(): return int(sys.stdin.readline().rstrip()) def MI(): return map(int,sys.stdin.readline().rstrip().split()) def LS(): return list(sys.stdin.readline().rstrip().split()) N,M,K = MI() X = LS() op = X[0] B = [int(X[i]) for i in range(1,M+1)] A = [I() for _ in range(N)] if op == '+': count_A = {} count_B = {} for i in range(N): a = A[i] % K if a in count_A.keys(): count_A[a] += 1 else: count_A[a] = 1 for i in range(M): b = B[i] % K if b in count_B.keys(): count_B[b] += 1 else: count_B[b] = 1 ans = 0 for i in count_A.keys(): j = (K-i) % K if j in count_B.keys(): ans += count_A[i]*count_B[j] else: count_A = {} count_B = {} for a in A: g = gcd(a,K) if g in count_A.keys(): count_A[g] += 1 else: count_A[g] = 1 for b in B: g = gcd(b,K) if g in count_B.keys(): count_B[g] += 1 else: count_B[g] = 1 ans = 0 for da in count_A.keys(): e = K//da for db in count_B.keys(): if db % e == 0: ans += count_A[da]*count_B[db] print(ans)