#include // clang-format off using namespace std; using ll=long long; using ull=unsigned long long; using pll=pair; const ll INF=4e18; void print0(){}; template void print0(H h,T... t){cout<void print1(H h,T... t){print0(h);if(sizeof...(T)>0)print0(" ");print1(t...);} void ioinit() { cout<> N >> P >> Q; vector pow10(2000001, 1); vector pow9(2000001, 1); vector pow7(2000001, 1); vector pow5(2000001, 1); for (ll 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; } vector A(N); for (ll i = 0; i < N; i++) { cin >> A[i]; } sort(A.begin(), A.end()); ll ans = 0; for (ll a = 0; a < N; a++) { ll asum = pow10[A[a]] % P; for (ll b = a + 1; b < N; b++) { ll bsum = (asum + pow9[A[b]]) % P; for (ll c = b + 1; c < N; c++) { ll csum = (bsum + pow7[A[c]]) % P; for (ll d = c + 1; d < N; d++) { if ((csum + pow5[A[d]]) % P == Q) ans++; } } } } print1(ans); return 0; }