def main(): import sys from collections import defaultdict from math import sqrt, gcd input = sys.stdin.buffer.readline N, M, K = map(int, input().split()) line = input().split() op = line[0].decode() B = list(map(int, line[1:])) A = [0] * N for i in range(N): A[i] = int(input()) ans = 0 if op == '+': dic_B = defaultdict(int) for b in B: dic_B[b%K] += 1 for a in A: ans += dic_B[(K - a%K)%K] else: nmax = int(sqrt(K)) div = [] div_append = div.append for d in range(1, nmax + 1): if K % d == 0: div_append(d) div_append(K // d) if nmax ** 2 == K: div.pop() div.sort() dic_A = {d: 0 for d in div} dic_B = {d: 0 for d in div} for a in A: dic_A[gcd(a, K)] += 1 for b in B: dic_B[gcd(b, K)] += 1 for d in div: for e in div: if e < d and d%e == 0: dic_B[e] += dic_B[d] for d in dic_A: ans += dic_A[d] * dic_B[K//d] print(ans) if __name__ == '__main__': main()