import sys input = sys.stdin.readline from collections import * from math import gcd N, M, K = map(int, input().split()) inp = list(input().split()) op = inp[0] B = list(map(int, inp[1:])) A = [int(input()) for _ in range(N)] if op=='+': cnt = Counter(Bi%K for Bi in B) print(sum(cnt[(K-Ai%K)%K] for Ai in A)) else: cnt1 = Counter(gcd(Ai, K) for Ai in A) cnt2 = Counter(gcd(Bi, K) for Bi in B) ans = 0 for k1 in cnt1: for k2 in cnt2: if k1*k2%K==0: ans += cnt1[k1]*cnt2[k2] print(ans)