import collections def divisors(n): ret=[] for i in range(1,int(n**0.5)+1): if n%i==0: ret.append(i) if i!=n//i: ret.append(n//i) return ret def gcd(a,b): if b==0: return a return gcd(b,a%b) n,m,k=map(int,input().split()) tmp=list(map(str,input().split())) op=tmp[0] arr1=[int(tmp[i]) for i in range(1,m+1)] arr2=[int(input()) for i in range(n)] ans=0 if op=='+': dic=collections.defaultdict(int) for i in range(m): arr1[i]%=k for i in range(n): arr2[i]%=k dic[arr2[i]]+=1 for i in range(m): ans+=dic[k-arr1[i]] else: divs=divisors(k) l=len(divs) dic1=collections.defaultdict(int) dic2=collections.defaultdict(int) for i in range(m): dic1[gcd(k,arr1[i])]+=1 for i in range(n): dic2[gcd(k,arr2[i])]+=1 for i in range(l): for j in range(l): if divs[i]*divs[j]%k==0: ans+=dic1[divs[i]]*dic2[divs[j]] print(ans)