MOD = 10 ** 9 + 7 INF = 10 ** 12 import sys sys.setrecursionlimit(1000000) dy = (-1,0,1,0) dx = (0,1,0,-1) from itertools import permutations from math import gcd def main(): n,m,k = map(int,input().split()) l = input().split() b = [int(l[i]) for i in range(1,m + 1)] a = [int(input()) for _ in range(n)] if l[0] == '+': ans = 0 b = [i%k for i in b] a = [i%k for i in a] dic = {} for num in b: if num in dic: dic[num] += 1 else: dic[num] = 1 for num in a: if k - num in dic: ans += dic[k - num] print(ans) else: dica = {} for num in a: g = gcd(num,k) if g in dica: dica[g] += 1 else: dica[g] = 1 dicb = {} for num in b: g = gcd(num,k) if g in dicb: dicb[g] += 1 else: dicb[g] = 1 ans = 0 for ka in dica: for kb in dicb: if (ka * kb % k) == 0: ans += dica[ka] * dicb[kb] print(ans) if __name__ =='__main__': main()