import collections import fractions 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 = [x % K for x in B] c_B_K = collections.Counter(B_K) ans = 0 for j in range(N): if C[0] == '+': ans += c_B_K[(K - A[j] % K) % K] else: if A[j] % K == 0: ans += M continue z = (A[j] * K) // fractions.gcd(A[j], K) ans += c_B_K[z // A[j]] ans += c_B_K[0] print(ans)