from collections import defaultdict N, P, C = map(int, input().split()) A = list(map(int, input().split())) ans = 0 if C == 0: total = N * (N + 1) // 2 # Count subarrays with no zero no_zero = 0 length = 0 for x in A: if x == 0: no_zero += length * (length + 1) // 2 length = 0 else: length += 1 no_zero += length * (length + 1) // 2 print(total - no_zero) else: freq = defaultdict(int) freq[1] = 1 prod = 1 for x in A: if x == 0: # reset at zero because products crossing zero become 0 freq.clear() freq[1] = 1 prod = 1 else: prod = prod * x % P # Need previous prefix q such that prod / q == C # q == prod / C need = prod * pow(C, P - 2, P) % P ans += freq[need] freq[prod] += 1 print(ans)