import sys readline=sys.stdin.readline from collections import defaultdict from math import gcd as GCD def Divisors(N): divisors=[] for i in range(1,N+1): if i**2>=N: break elif N%i==0: divisors.append(i) if i**2==N: divisors+=[i]+[N//i for i in divisors[::-1]] else: divisors+=[N//i for i in divisors[::-1]] return divisors N,M,K=map(int,readline().split()) op,*B=readline().split() for m in range(M): B[m]=int(B[m]) A=[int(readline()) for n in range(N)] if op=="+": cnt=defaultdict(int) for b in B: cnt[b%K]+=1 ans=0 for a in A: ans+=cnt[(-a)%K] else: cnt=defaultdict(int) D=Divisors(K) for b in B: for d in D: if b%d==0: cnt[d]+=1 ans=0 for a in A: g=GCD(a,K) ans+=cnt[K//g] print(ans)