import sys from collections import Counter readline = sys.stdin.readline def gcd(a,b): if b == 0: return a return gcd(b,a%b) #約数列挙 def divi(n): res = [] for i in range(1, int(n**0.5)+1): if n % i == 0: res.append(i) if i != n // i: res.append(n//i) return res N, M, K = map(int, readline().split()) op, *A = readline().strip().split() A = [int(a) for a in A] B = [int(readline()) for _ in range(N)] if op == '+': C = Counter() for a in A: C[a%K] += 1 res = 0 for b in B: res += C[(-b)%K] print(res) else: R = divi(K) R.sort() lr = len(R) Dr = Counter() table1 = [0]*lr table2 = [0]*lr for i in range(lr): Dr[R[i]] = i for a in A: table1[Dr[gcd(a, K)]] += 1 for i in range(lr): k = R[i] v = table1[i] for j in range(i+1): if not k%R[j]: table2[j] += v ans = 0 for b in B: ans += table2[Dr[K//gcd(b, K)]] print(ans)