def main(): import sys from collections import defaultdict from math import sqrt, gcd input = sys.stdin.readline def prime(n): ret = defaultdict(int) dmax = int(sqrt(n)) for d in range(2, dmax+1): while n%d == 0: n //= d ret[d] += 1 if n != 1: ret[n] += 1 return ret N, M, K = map(int, input().split()) line = input().split() op = line[0] 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] else: K_prime = prime(K) nmax = int(sqrt(K)) div = [] for d in range(1, nmax+1): if K%d == 0: div.append(d) if d **2 != K: div.append(K//d) div_num = defaultdict(int) for d in div: for b in B: if b%d == 0: div_num[d] += 1 for a in A: d = K // gcd(a, K) ans += div_num[d] print(ans) if __name__ == '__main__': main()