import sys input = sys.stdin.readline from collections import * from math import gcd N, M, K = map(int, input().split()) B = input().split() op = B.pop(0) B = list(map(int, B)) A = [-1] * N for i in range(N): A[i] = int(input()) ans = 0 if op == "+": D = defaultdict(int) for b in B: D[b%K] += 1 for a in A: ans += D[(-a)%K] else: D = defaultdict(int) for b in B: D[gcd(b, K)] += 1 for a in A: a = gcd(a, K) for k, v in D.items(): if (a * k) % K == 0: ans += v print(ans)