#include #include int main() { using namespace std; unsigned N, P, Q; cin >> N >> P >> Q; unordered_map dp_0, dp_1, dp_2, dp_3; for (unsigned i{}; i < N; i++) { unsigned a; cin >> a; const auto v5{atcoder::pow_mod(5, a, P)}; for (const auto &[k, v] : dp_2) dp_3[(k + v5) % P] += v; const auto v7{atcoder::pow_mod(7, a, P)}; for (const auto &[k, v] : dp_1) dp_2[(k + v7) % P] += v; const auto v9{atcoder::pow_mod(9, a, P)}; for (const auto &[k, v] : dp_0) dp_1[(k + v9) % P] += v; const auto v10{atcoder::pow_mod(10, a, P)}; dp_0[v10]++; } cout << dp_3[Q] << endl; return 0; }