#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()); vector> mp(N); map cnt; for (ll c = N - 1; c >= 0; c--) { for (ll d = c + 1; d < N; d++) { ll m = (pow7[A[c]] + pow5[A[d]]) % P; cnt[m]++; } mp[c] = cnt; } ll ans = 0; for (ll a = 0; a < N; a++) { for (ll b = a + 1; b < N; b++) { ll m = (pow10[A[a]] + pow9[A[b]]) % P; if (b + 1 < N) ans += mp[b + 1][(Q - m + P) % P]; } } print1(ans); return 0; }