#include #include #include #include #include #include #include #include #include using namespace atcoder; using namespace std; using ll = long long; #define Sort(a) sort((a).begin(), (a).end()) #define Rev(a) reverse((a).begin(), (a).end()) #define cfs(a) cout << fixed << setprecision(a) ll modpow(ll a, ll n, ll mod){ ll ans = 1; while (n > 0){ if (n & 1) ans = ans * a % mod; a = a * a % mod; n /= 2; } return ans; } int main() { ll N, P, Q; cin >> N >> P >> Q; vector A(N); for (ll i = 0; i < N; i++) { cin >> A[i]; } vector num_vec = { 10, 9, 7, 5 }; vector> modA(num_vec.size(), vector(N)); for (ll i = 0; i < num_vec.size(); i++) { for (ll j = 0; j < N; j++) { modA[i][j] = modpow(num_vec[i], A[j], P); } } map mp; for (ll i = 0; i < N; i++) { mp[modA[3][i]]++; } ll ans = 0; for (ll i = 0; i < N; i++) { for (ll j = 0; j < N; j++) { for (ll k = 0; k < N; k++) { if (i == j || j == k || k == i) { break; } ll Sum = modA[0][i] + modA[1][j] + modA[2][k]; Sum %= P; ll check_num = 0; if (Sum <= Q) { check_num += Q - Sum; } else { check_num += (P + Q) - Sum; } ll temp_cnt = 0; if (modA[3][i] == check_num) { temp_cnt++; } if (modA[3][j] == check_num) { temp_cnt++; } if (modA[3][k] == check_num) { temp_cnt++; } // if (mp[check_num] - temp_cnt < 0) // { // break; // } ans += mp[check_num] - temp_cnt; } } } cout << ans << endl; }