from math import gcd from collections import defaultdict N, M, K = map(int, input().split()) op, *B = input().split() B = [int(b) for b in B] A = [int(input()) for _ in range(N)] ans = 0 if op == '+': d = defaultdict(int) for b in B: d[b % K] += 1 for a in A: ans += d[(K - a) % K] else: # op == '*' dA = defaultdict(int) dB = defaultdict(int) for a in A: dA[gcd(K, a)] += 1 for b in B: dB[gcd(K, b)] += 1 for ka, va in dA.items(): for kb, vb in dB.items(): if not ka * kb % K: ans += va * vb print(ans)