#include using namespace std; vector v = {10LL, 9LL, 7LL, 5LL}; int siz = 2000010; long long modpow(long long a, long long b, long long mod) { long long cur = a, ans = 1; for (int i = 0; i < 60; i++) { if (b & (1LL << i)) { ans = (ans * cur) % mod; } cur = (cur * cur) % mod; } return ans; } int main() { int n; long long p, q; cin >> n >> p >> q; vector a(n); for (int i = 0; i < n; i++) { cin >> a[i]; } vector> mods(4, vector(siz, 1LL)); for (int i = 0; i < 4; i++) { for (int j = 1; j < siz; j++) { mods[i][j] = mods[i][j - 1] * v[i] % p; } } vector c; for (int i = 0; i < 4; i++) { c.push_back('o'); } for (int i = 0; i < n - 4; i++) { c.push_back('x'); } sort(a.begin(), a.end()); int ans = 0; do { long long res = 0LL; int w = -1, x = -1, y = -1, z = -1; for (int i = 0; i < n; i++) { if (c[i] == 'o') { if (w == -1) { w = i; } else if (x == -1) { x = i; } else if (y == -1) { y = i; } else { z = i; } } } res += (((mods[0][a[w]] + mods[1][a[x]]) % p + mods[2][a[y]]) % p + mods[3][a[z]]) % p; if (res == q) { ans++; } } while (next_permutation(c.begin(), c.end())); cout << ans << endl; }