import math from collections import Counter n, m, k = map(int, input().split()) line = input().split() op = line[0] B = list(map(int, line[1:])) A = [int(input()) for _ in range(n)] if op == '+': mod = [a % k for a in A] modcnt = Counter(mod) ans = sum([modcnt[(k - (b%k)) % k] for b in B]) else: gcda = [math.gcd(k,a) for a in A] gcdb = [math.gcd(k,b) for b in B] ans = 0 for ga in gcda: for gb in gcdb: if (ga * gb) % k == 0: ans += 1 print(ans)