#include #include #include #include #include #include #include #include #include #include using namespace std; typedef long long int ll; typedef pair Pii; const ll mod = 998244353; ll modpow(ll a, ll b, ll m = mod) { ll r = 1; while (b > 0) { if (b & 1) r = (r * a) % m; a = (a * a) % m; b >>= 1; } return r; } int main() { cin.tie(0); ios::sync_with_stdio(false); ll n, p, q; cin >> n >> p >> q; vector a(n); for (auto &x: a) cin >> x; sort(a.begin(), a.end()); vector pow10mod(n), pow9mod(n), pow7mod(n), pow5mod(n); for (int i = 0; i < n; i++) { pow10mod[i] = modpow(10, a[i], p); pow9mod[i] = modpow(9, a[i], p); pow7mod[i] = modpow(7, a[i], p); pow5mod[i] = modpow(5, a[i], p); } ll ans = 0; for (int i = 0; i < n; i++) { for (int j = i + 1; j < n; j++) { for (int k = j + 1; k < n; k++) { for (int l = k + 1; l < n; l++) { ll val = (pow10mod[i] + pow9mod[j] + pow7mod[k] + pow5mod[l]) % p; if (val == q) ans++; } } } } cout << ans << endl; return 0; }