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 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: d = defaultdict(int) for bi in B: d[gcd(bi, k)] += 1 ans = 0 for ai in A: c = gcd(ai, k) for key, value in d.items(): if key*c%k == 0: ans += value print(ans)