N, P, Q = map(int, input().split()) A = list(map(int, input().split())) A.sort() base = [10, 9, 7, 5] g = [[pow(base[c], A[i], P) for i in range(N)] for c in range(4)] st = set() st.add(g[0][0]) ans = 0 for b in range(1, N): for c in range(b + 1, N): for d in range(c + 1, N): Y = (g[1][b] + g[2][c] + g[3][d]) % P if (Q - Y) % P in st: ans += 1 st.add(g[0][b]) # print(g) print(ans)