from math import gcd n, m, k = map(int, input().split()) op, *B = input().split() B = [int(b) for b in B] A = [int(input()) for _ in range(n)] if op == "+": cnt = {} for b in B: cnt[b % k] = cnt.get(b % k, 0) + 1 ans = 0 for a in A: ans += cnt.get(-a % k, 0) print(ans) else: div = [] for i in range(1, int(k ** 0.5 + 1)): if k % i == 0: div.append(i) if i * i != k: div.append(k // i) else: pass else: pass cnt = {} for b in B: g = gcd(b, k) for d in div: if g % d == 0: cnt[d] = cnt.get(d, 0) + 1 else: pass ans = 0 for a in A: g = gcd(a, k) ans += cnt.get(k // g, 0) print(ans)