import math n,m,k = map(int,input().split()) L = list(input().split()) op = L[0] B = [int(b) for b in L[1:]] A = [int(input()) for i in range(n)] if op == "+": dic = {} for b in B: dic[b%k] = dic.get(b%k,0)+1 ans = 0 for a in A: ans += dic.get((k-a)%k,0) else: dicB = {} for b in B: g = math.gcd(b,k) dicB[g] = dicB.get(g,0)+1 dicA = {} for a in A: g = math.gcd(a,k) dicA[g] = dicA.get(g,0)+1 divs = set() for i in range(1,int(k**0.5)+1): if k%i: continue divs.add(i) divs.add(k//i) ans = 0 for i in divs: for j in divs: x = i*j if math.gcd(x,k) != k: continue ans += dicA.get(i,0)*dicB.get(j,0) print(ans)