#pragma GCC target("avx2") #pragma GCC optimize("O3") #pragma GCC optimize("unroll-loops") #include #include #include typedef atcoder::modint mint; int main() { std::cin.tie(nullptr) -> sync_with_stdio(false); int n, p, q, cnt = 0; std::cin >> n >> p >> q; mint::set_mod(p); std::vector a(n); for(auto &el: a) { std::cin >> el; } const auto calc = [](const int a, const int b, const int c, const int d) -> mint { return mint(10).pow(a) + mint(9).pow(b) + mint(7).pow(c) + mint(5).pow(d); }; for(int i = 0; i < n; ++i) { for(int j = i; ++j < n;) { for(int k = j; ++k < n;) { for(int l = k; ++l < n;) { if(calc(a[i], a[j], a[k], a[l]).val() == q) { cnt++; } } } } } std::cout << cnt << '\n'; }