from collections import defaultdict from math import gcd from itertools import product def solve_add(a,b,k): cnt_a = defaultdict(int) cnt_b = defaultdict(int) for v in a: cnt_a[v%k] += 1 for v in b: cnt_b[v%k] += 1 return sum(cnt_a[i]*cnt_b[-i%k] for i in cnt_a.keys()) def solve_mul(a,b,k): cnt_a = defaultdict(int) cnt_b = defaultdict(int) for v in a: cnt_a[gcd(k,v)] += 1 for v in b: cnt_b[gcd(k,v)] += 1 res = 0 for (a,ca),(b,cb) in product(cnt_a.items(),cnt_b.items()): if a*b%k == 0: res += ca*cb return res n,m,k = map(int,input().split()) op, *b = input().split() b = list(map(int,b)) a = [int(input()) for _ in range(n)] if op == '+': print(solve_add(a,b,k)) else: print(solve_mul(a,b,k))