import collections import math N, M, K = [int(x) for x in input().split()] C = [x for x in input().split()] B = [int(x) for x in C[1:]] A = [int(input()) for _ in range(N)] B_K = [] A_K = [] c_B_K = None c_A_K = None if C[0] == '+': B_K = [x % K for x in B] c_B_K = collections.Counter(B_K) else: B_K = [math.gcd(x, K) for x in B] A_K = [math.gcd(x, K) for x in A] c_B_K = collections.Counter(B_K) c_A_K = collections.Counter(A_K) ans = 0 if C[0] == '+': for j in range(N): ans += c_B_K[K - A[j] % K] else: for b in c_B_K.keys(): for a in c_A_K.keys(): if (a * b) % K == 0: ans += c_B_K[b] * c_A_K[a] print(ans)