def make_divisors(n): divisors = [] for i in range(1, int(n**0.5)+1): if n % i == 0: divisors.append(i) if i != n // i: divisors.append(n//i) divisors.sort() return divisors import math from collections import defaultdict n,m,k = map(int,input().split()) opb = input().split() op = opb[0] b = [] for i in range(1,m+1): b.append(int(opb[i])) a = [int(input()) for i in range(n)] ans = 0 if op == "+": bmod = {}#[0]*(k) for i in range(m): tmp = b[i]%k #print(bmod,tmp) if tmp in bmod: bmod[tmp] += 1 else: bmod[tmp] = 1 for i in range(n): tmp = -a[i]%k if tmp in bmod: ans += bmod[tmp] print(ans) else: div = make_divisors(k) d = defaultdict(int) for i in range(m): tmp = math.gcd(b[i],k) d[tmp] += 1 for i in range(n): tmp = math.gcd(a[i],k) for key in d.keys(): if tmp*key%k == 0: #print(d[key]) ans += d[key] print(ans)