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 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 = k-(a[i]%k) if tmp in bmod: ans += bmod[tmp] print(ans) else: print(kk) div = make_divisors(k) bdiv = {} for i in div: tmp = 0 for j in range(m): if b[j]%i == 0: tmp += 1 bdiv[i] = tmp for i in range(n): tmp = math.gcd(a[i],k) ans += bdiv[k//tmp] print(ans)