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(): bb = Counter([gcd(b, K) for b in B]) res = 0 for a in A: x = gcd(a, K) for k, v in bb.items(): if x * k % K == 0: res += v return res if op == '+': print(calc_add()) else: print(calc_mul())