from collections import Counter from math import gcd N, M, K = map(int, input().split()) s = input().split() op = s[0] B = [int(x) for x in s[1:]] A = [] for _ in range(N): A.append(int(input())) def calc_add(): bb = Counter([b % K for b in B]) res = 0 for a in A: x = (K - a) % K res += bb[x] return res def calc_mul(): aa = Counter([gcd(a, K) for a in A]) bb = Counter([gcd(b, K) for b in B]) res = 0 for k1, v1 in aa.items(): for k2, v2 in bb.items(): if k1 * k2 % K == 0: res += v1 * v2 return res if op == '+': print(calc_add()) else: print(calc_mul())