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()) 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 #print(da) #print(db) if op == '+': ans = 0 for i in range(k): if i not in da: continue else: if i == 0: j = 0 else: j = 13-i if j in db: ans += da[i]*db[j] else: ans = 0 for i in range(1, k): if i not in da: continue for j in range(1, k): if j not in db: continue if (i * j)%k == 0: ans += da[i]*db[j] if 0 in da and 0 in db: ans += da[0]*m + db[0]*n - da[0]*db[0] elif 0 in da and 0 not in db: ans += da[0]*m elif 0 not in da and 0 in db: ans += db[0]*n else: pass print(ans)