from collections import Counter from copy import copy def maker(l, x): current = (l[-1]*x) % P for i, item in enumerate(l): if item == current: return (l[:i], l[i:]) return maker(l+[current], x) N, P, Q = map(int, input().split()) A = list(map(int, input().split())) A.sort() lo = [] for x in [10, 9, 7, 5]: loops = maker([x%P], x) lo.append([]) for a in A: a -= 1 if len(loops[0]) > a: lo[-1].append(loops[0][a]) a -= len(loops[0]) lo[-1].append(loops[1][a%len(loops[1])]) clo = [Counter(l) for l in lo] answer = 0 clo3 = clo[3] for i in range(N): x = lo[0][i] clo3[lo[3][i]] -= 1 tmp = copy(clo3) for j in range(i+1, N): tmp[lo[3][j]] -= 1 for k in range(j+1, N): tmp[lo[3][k]] -= 1 answer += tmp.get((Q-(x+lo[1][j]+lo[2][k])) % P, 0) for k in range(j+1, N): tmp[lo[3][k]] += 1 print(answer)