#include #include using namespace std; using namespace atcoder; using ll = long long; using ld = long double; int N, P, Q, A[202]; ll pow10[2020202], pow9[2020202], pow7[2020202], pow5[2020202], ans; int main() { cin >> N >> P >> Q; for (int i = 0; i < N; i++) cin >> A[i]; sort(A, A + N); pow10[0] = pow9[0] = pow7[0] = pow5[0] = 1; for (int i = 1; i <= 2000000; i++) { pow10[i] = (pow10[i - 1] * 10) % P; pow9[i] = (pow9[i - 1] * 9) % P; pow7[i] = (pow7[i - 1] * 7) % P; pow5[i] = (pow5[i - 1] * 5) % P; } for (int i = 0; i < N; i++) { for (int j = i + 1; j < N; j++) { for (int k = j + 1; k < N; k++) { for (int l = k + 1; l < N; l++) { int a = A[i], b = A[j], c = A[k], d = A[l]; if ((pow10[a] + pow9[b] + pow7[c] + pow5[d]) % P == Q) ans++; } } } } cout << ans << endl; return 0; }