import sys input = sys.stdin.readline N,M,K = map(int,input().split()) op,*B = input().split() A = [int(input()) for i in range(N)] B = [int(b) for b in B] from collections import Counter ans = 0 if op=='+': c = Counter() for a in A: c[a%K] += 1 for b in B: ans += c[(K-b%K)%K] else: ds = set() m = 1 while m*m <= K: if K%m==0: ds.add(m) ds.add(K//m) m += 1 ds = sorted(list(ds), reverse=True) c = Counter() for a in A: for d in ds: if a%d==0: c[d] += 1 break for b in B: for d in ds: if (b*d)%K == 0: ans += c[d] print(ans)