#include <bits/stdc++.h>
using namespace std;
int n, p, k, ans, a[300010], t;
unordered_map<int, int> hp;
unordered_map<int, pair<int, int> > ph;
int cal(int x) {
  long long t = (((1LL * x * x) % p) * ((1LL * x * x) % p)) % p;
  t = (t - 1LL * x * k) % p;
  t = (t % p + p) % p;
  return t;
}
void readf() { cin >> n >> p >> k; }
void solve() {
  for (int i = (1); i <= (n); ++i) cin >> a[i];
  for (int i = (1); i <= (n); ++i) {
    ans += hp[cal(a[i])];
    hp[cal(a[i])]++;
  }
  for (int i = (1); i <= (n); ++i) {
    if (ph[a[i]].second == 1)
      t += ph[cal(a[i])].first;
    else
      ph[a[i]].second = 1;
    ph[cal(a[i])].first++;
  }
  cout << ans - t;
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  readf();
  solve();
}
