from collections import defaultdict as dd 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] #cnt = dd(int) 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: continue for k in range(j, N): if j==k: continue for l in range(k, N): if k==l: continue val = A_div[i][0]+A_div[j][1]+A_div[k][2]+A_div[l][3] val %= P if val == Q: ans += 1 print(ans)