from collections import defaultdict import math n, m, k = map(int, input().split()) op, *b = list(input().split()) cnt = defaultdict(int) ans = 0 if op == "+": for x in b: cnt[int(x) % k] += 1 for _ in range(n): ai = int(input()) ans += cnt[(- ai) % k] elif op == "*": for x in b: x = int(x) for d in range(1, int(math.sqrt(x)) + 1): if x % d == 0: if d != x // d: cnt[x // d] += 1 cnt[d] += 1 for _ in range(n): ai = int(input()) x = k // math.gcd(ai, k) ans += cnt[x] print(ans)