#include #include using namespace std; constexpr unsigned int pow_mod(const unsigned long long a, const unsigned long long b, const unsigned int mod) { return (b == 0 ? (mod == 1 ? 0 : 1) : (b & 1 ? a % mod : 1) * pow_mod((a % mod) * (a % mod) % mod, b >> 1, mod) % mod); } int main() { cin.tie(nullptr); ios::sync_with_stdio(false); int N, P, Q, A[200], i, a, b, c, d, ans = 0; cin >> N >> P >> Q; for (i = 0; i != N; ++i) cin >> A[i]; for (a = 0; a != N; ++a) for (b = a + 1; b != N; ++b) for (c = b + 1; c != N; ++c) for (d = c + 1; d != N; ++d) if ((pow_mod(10, A[a], P) + pow_mod(9, A[b], P) + pow_mod(7, A[c], P) + pow_mod(5, A[d], P)) % P == Q) ++ans; cout << ans << '\n'; return 0; }