#include using namespace std; long long f(long long x, long long n, long long MOD) { long long ret = 1; while(n) { if(n&1) { ret *= x; ret %= MOD; } x *= x; x %= MOD; n >>= 1; } return ret; } int main() { long long 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()); vector cnt(N+1, unordered_map()); for(int i = N-1; i >= 0; i--) { cnt[i] = cnt[i+1]; cnt[i][f(5, A[i], P)]++; } long long 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) { long long s = f(10, A[i], P)+f(9, A[j], P)+f(7, A[k], P); s %= P; long long t = (P+Q-s)%P; // cout << A[i] << " " << A[j] << " " << A[k] << ": " << f(10, A[i], P) << " " << f(9, A[j], P) << " " << f(7, A[k], P) << " " << t << endl; ans += cnt[k+1][t]; } } } cout << ans << endl; }