import sys from collections import Counter from math import sqrt input = sys.stdin.readline N,M,K=map(int,input().split()) B=list(input().split()) A=[int(input()) for i in range(N)] ANS=0 if B[0]=="+": B=list(map(int,B[1:])) A=Counter([a%K for a in A]) B=Counter([b%K for b in B]) for c in A: ANS+=A[c]*B[K-c] print(ANS) sys.exit() B=list(map(int,B[1:])) x=K L=int(sqrt(x)) FACT=Counter() for i in range(2,L+2): while x%i==0: FACT[i]+=1 x=x//i if x!=1: FACT[x]=FACT.get(x,0)+1 fs=list(FACT.keys()) fv=list(FACT.values()) LEN=len(fs) SCA=Counter() SCB=Counter() for b in B: sc=[0]*LEN for i in range(LEN): f=fs[i] while b%f==0: sc[i]+=1 b//=f SCB[tuple(sc)]+=1 for a in A: sc=[0]*LEN for i in range(LEN): f=fs[i] while a%f==0: sc[i]+=1 a//=f SCA[tuple(sc)]+=1 def geq(sa,sb): for i in range(LEN): if fv[i]-sa[i]>sb[i]: return 0 return SCA[sa]*SCB[sb] for sa in SCA: for sb in SCB: ANS+=geq(sa,sb) print(ANS)