#include using namespace std; using ll = long long; int main(){ cin.tie(nullptr); ios_base::sync_with_stdio(false); ll N, M=2e6, P, Q, ans=0, a, b, c, d; cin >> N >> P >> Q; vector p10(M+1), p9(M+1), p7(M+1), p5(M+1); p10[0] = 1; p9[0] = 1; p7[0] = 1; p5[0] = 1; for (int i=1; i<=M; i++){ p10[i] = p10[i-1] * 10; p10[i] %= P; p9[i] = p9[i-1] * 9; p9[i] %= P; p7[i] = p7[i-1] * 7; p7[i] %= P; p5[i] = p5[i-1] * 5; p5[i] %= P; } vector mp(P); vector A(N+1); for (int i=1; i<=N; i++) cin >> A[i]; sort(A.begin(), A.end()); mp[p10[A[1]]]++; for (int i=2; i<=N; i++){ for (int j=i+1; j<=N; j++){ for (int k=j+1; k<=N; k++){ a = p9[A[i]]; b = p7[A[j]]; c = p5[A[k]]; //(a+b+c+d) % P = Q; // x = Q-(a+b+c) % P d = (Q-(a+b+c)) % P; if (d < 0) d += P; ans += mp[d]; } } mp[p10[A[i]]]++; } cout << ans << endl; return 0; }