#include using namespace std; using ll = long long; using ld = long double; #ifdef LOCAL #include #else #define debug(...) void(0) #endif #include using namespace atcoder; ll modpow(ll a, ll b, ll m) { ll ret = 1; while(b) { if(b & 1) (ret *= a) % m; (a *= a) % m; b >>= 1; } return ret; } int main() { ios::sync_with_stdio(false); cin.tie(nullptr); ll N, P, Q; cin >> N >> P >> Q; vector A(N); for(int i = 0; i < N; i++) cin >> A[i]; sort(A.begin(), A.end()); const ll n = 2 * 1'000'000; vector> rec(11, vector(n + 1, 1)); for(int i : {5, 7, 9, 10}) { for(int j = 0; j < n; j++) { rec[i][j + 1] = (rec[i][j] * 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 t = rec[10][A[i]] + rec[9][A[j]] + rec[7][A[k]] + rec[5][A[l]]; t %= P; if(t == Q) ans++; } } } } cout << ans << endl; }