from itertools import combinations def count_ways(N, P, Q, A): ways = 0 powers = [[(x**a) % P for a in A] for x in [10, 9, 7, 5]] for a, b, c, d in combinations(range(N), 4): if (powers[0][a] + powers[1][b] + powers[2][c] + powers[3][d]) % P == Q: ways += 1 return ways N, P, Q = map(int, input().split()) A = list(map(int, input().split())) print(count_ways(N, P, Q, A))