import sys input = sys.stdin.readline N, P, Q = map(int, input().split()) A = list(map(int, input().split())) A.sort() dp = [[0 for _ in range(P)] for _ in range(N+1)] for i in range(N): q = pow(5, A[i], P) for j in range(P): if j==q: dp[i+1][j] = dp[i][j]+1 else: dp[i+1][j] = dp[i][j] ans = 0 for i in range(N): a = A[i] for j in range(i+1, N): b = A[j] for k in range(j+1, N): c = A[k] tmp = pow(10, a, P)+pow(9, b, P)+pow(7, c, P) tmp %= P tmp = (Q-tmp)%P cnt = dp[N][tmp]-dp[k+1][tmp] ans += cnt print(ans)