import sys import math from collections import defaultdict, Counter def main(): N, M, K = map(int, sys.stdin.readline().split()) op_line = sys.stdin.readline().split() op = op_line[0] B = list(map(int, op_line[1:1+M])) A = [int(sys.stdin.readline()) for _ in range(N)] if op == '+': # Handle addition case B_mod = [b % K for b in B] cnt = Counter(B_mod) total = 0 for a in A: a_mod = a % K req = (-a_mod) % K total += cnt.get(req, 0) print(total) else: # Handle multiplication case B_mod = [b % K for b in B] cnt_b = Counter(B_mod) # Function to get all divisors of K def get_divisors(k): divisors = set() for i in range(1, int(math.isqrt(k)) + 1): if k % i == 0: divisors.add(i) divisors.add(k // i) return list(divisors) divisors_list = get_divisors(K) # Precompute divisor counts divisor_counts = defaultdict(int) for s in divisors_list: divisor_counts[s] = 0 for x, count in cnt_b.items(): g = math.gcd(x, K) for s in divisors_list: if g % s == 0: divisor_counts[s] += count # Calculate total total = 0 for a in A: a_mod = a % K d = math.gcd(a_mod, K) s = K // d total += divisor_counts.get(s, 0) print(total) if __name__ == "__main__": main()