n, m, k = map(int, input().split()) l = list(map(str, input().split())) b = [int(l[i]) for i in range(1, m+1)] op = l[0] #print(op) #rint(b) a = [0]*n for i in range(n): a[i] = int(input()) if op == '+': da = {} for i in range(n): if a[i]%k not in da: da[a[i]%k] = 1 else: da[a[i]%k] += 1 db = {} for i in range(m): if b[i]%k not in db: db[b[i]%k] = 1 else: db[b[i]%k] += 1 ans = 0 for i in da: if i == 0: j = 0 else: j = k-i if j in db: ans += da[i]*db[j] else: import math da = {} for i in range(n): g = math.gcd(a[i], k) if g not in da: da[g] = 1 else: da[g] += 1 db = {} for i in range(m): g = math.gcd(b[i], k) if g not in db: db[g] = 1 else: db[g] += 1 ans = 0 for i in da: for j in db: if (i*j)%k == 0: ans += da[i]*db[j] #print(da) #print(db) print(ans)