import sys reader = (s.rstrip() for s in sys.stdin) input = reader.__next__ n,m,k = map(int, input().split()) op, *B = input().split() B = list(map(int, B)) A = [int(input()) for i in range(n)] from collections import defaultdict from math import gcd def divisor(n): ret = [] for i in range(1,int(n**0.5)+1): if n%i == 0: ret.append(i) if i**2 == n: continue ret.append(n//i) return ret if op == "+": d = defaultdict(int) for bi in B: d[bi%k] += 1 ans = 0 for ai in A: target = (-ai)%k ans += d[target] else: divisors = divisor(k) d = defaultdict(int) for bi in B: for ki in divisors: if bi%ki == 0: d[ki] += 1 ans = 0 for ai in A: target = k // gcd(k, ai) ans += d[target] print(ans)