from collections import defaultdict from math import gcd N,M,K=map(int, input().split()) S=input().split() op=S[0] B=list(map(int,S[1:])) A=list(int(input()) for _ in range(N)) res=0 if op=="+": C=defaultdict(int) for b in B: C[b%K]+=1 for a in A: a%=K res+=C[K-a] print(res) else: C=defaultdict(int) D=defaultdict(int) for a in A: C[gcd(a,K)]+=1 for b in B: D[gcd(b,K)]+=1 for key,val in C.items(): for key2, val2 in D.items(): if key*key2%K==0: res+=val*val2 print(res)