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: div_num = {} for a in A: d = K // gcd(a, K) if d in div_num: ans += div_num[d] else: div_num[d] = 0 for b in B: if b % d == 0: div_num[d] += 1 ans += div_num[d] print(ans) if __name__ == '__main__': main()