from collections import defaultdict from math import gcd from itertools import product def solve_add(a,b,k): cnt_a = [0]*k cnt_b = [0]*k 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] for i in range(k)) 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(tuple(cnt_a.items()),tuple(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))