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_cnt = Counter([math.gcd(k,a) for a in A]) gcdb_cnt = Counter([math.gcd(k,b) for b in B]) ans = 0 for ga, gacnt in gcda_cnt.items(): for gb, gbcnt in gcdb_cnt.items(): if (ga * gb) % k == 0: ans += gacnt * gbcnt print(ans)