from collections import Counter as C import math n,m,k,o,*A = open(0).read().split() m,k,*A = map(int,[m,k]+A) f = lambda x:[math.gcd(k,x),x%k][o=="+"] a = C(map(f,A[:m])).items() b = C(map(f,A[m:])) print([sum(v*w*(i*j%k==0) for j,w in b.items() for i,v in a),sum(v*b[-i%k] for i,v in a)][o=="+"])