import sys 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]=="+": from collections import Counter 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:])) import math x=K xr=math.ceil(math.sqrt(x)) LIST=[] for i in range(1,xr+1): if x%i==0: LIST.append(i) LIST.append(x//i) L=sorted(set(LIST),reverse=True) LEN=len(L) SC=[0]*LEN for i in range(LEN): l=L[i] for b in B: if b%l==0: SC[i]+=1 for a in A: for i in range(LEN): l=L[i] if a%l==0: ANS+=SC[LEN-i-1] break print(ANS)