memo={} def gcd(a,b): if (a,b) in memo:return memo[(a,b)] while b:a,b=b,a%b memo[(a,b)]=a return a def main1(n,m,k,op,a,b): if k==1:return m*n if op=="+": ca=dict(Counter([x%k for x in a])) cb=dict(Counter([x%k for x in b])) ans=0 for key,value in ca.items(): if (k-key)%k in cb: ans+=cb[(k-key)%k]*value return ans else: ca=dict(Counter([gcd(x,k) for x in a])) cb=dict(Counter([gcd(x,k) for x in b])) ans=0 for x in ca: for y in cb: if (x*y)%k==0: ans+=ca[x]*cb[y] return ans import sys input=sys.stdin.readline if __name__=='__main__': n,m,k=map(int,input().split()) b=list(input().split()) op=b[0] b=list(map(int,b[1:])) a=[int(input()) for _ in range(n)] ret1=main1(n,m,k,op,a,b) print(ret1)