N,P,Q = map(int,input().split()) A = list(map(int,input().split())) A.sort() Z = [10,9,7,5] pw = [[pow(z,a,P) for a in A] for z in Z] dp = [{} for _ in range(5)] dp[0] = {0:1} for i in range(N): ndp = [{} for _ in range(5)] for j in range(5): for k,v in dp[j].items(): if k in ndp[j]: ndp[j][k] += v else: ndp[j][k] = v if j==4: break nk = (k + pw[j][i]) % P if nk in ndp[j+1]: ndp[j+1][nk] += v else: ndp[j+1][nk] = v dp = ndp if Q in dp[-1]: print(dp[-1][Q]) else: print(0)