from collections import defaultdict as dd import bisect def pow(x, n, mod): ans = 1 #n が 0 になるまで計算を続ける while n: if n % 2: ans *= x ans %= mod x *= x n >>= 1 return ans%mod N,P,Q = map(int, input().split()) A = list(map(int, input().split())) A = list(set(A)) A.sort() N = len(A) A_div = [ [0 for i in range(4)] for _ in range(N)] num = [10,9,7,5] for i in range(N): for j in range(4): A_div[i][j] = pow(num[j], A[i], P) ans = 0 for i in range(N): for j in range(i, N): if i==j or A[i]>=A[j]: continue for k in range(j, N): if j==k or A[j]>=A[k]: continue for l in range(k, N): if l==k or A[k]>=A[l]: continue if A[i]<A[j]<A[k]<A[l]: rem = A_div[i][0]+A_div[j][1]+A_div[k][2]+A_div[l][3] rem %= P if rem == Q: ans += 1 else: continue print(ans)