import bisect N,M,K = map(int, input().split()) B = [i for i in input().split()] op = B.pop(0) A = [int(input()) for _ in range(N)] for i in range(M): B[i] = int(B[i]) def gcd(a, b): if a < b: a, b = b, a if a%b == 0: return b return gcd(b, a%b) if op == "+": for i in range(N): A[i] %= K for j in range(M): B[j] %= K B.sort() ans = 0 for a in A: ans += bisect.bisect_right(B, K-a) - bisect.bisect_left(B, K-a) else: dic = {} i = 1 while i < K**0.5: if K%i == 0: dic[i] = 0 dic[K//i] = 0 i += 1 if K**0.5 == int(K**0.5): dic[int(K**0.5)] = 0 cnt = 0 for b in B: if gcd(b, K) == 1: continue if b%K == 0: cnt += 1 continue for key in dic: if b%key == 0: dic[key] += 1 ans = cnt*N for a in A: ans += dic[K//gcd(a, K)] print(ans)