#include <bits/stdc++.h>
using namespace std;
void vin(std::vector<long long> &a) {
  for (auto &x : a) cin >> x;
}
void vout(std::vector<int> &a) {
  for (int x : a) cout << x << " ";
  cout << endl;
}
long long binom(int k, int n) {
  if (k > n) return 0;
  if (k == n) return 1;
  if (k > n / 2) return binom(n - k, n);
  if (k == 1) return n;
  return binom(k, n - 1) + binom(k - 1, n - 1);
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int n, p, k;
  cin >> n >> p >> k;
  std::vector<long long> a(n);
  vin(a);
  std::vector<int> ain(n);
  for (int i = 0; i < n; i++)
    ain[i] =
        ((((a[i] * a[i]) % p * a[i]) % p * a[i]) % p - k * a[i] % p + p) % p;
  sort(ain.begin(), ain.end());
  long long cc = 0;
  int li = 0;
  for (int i = 1; i < n; i++) {
    if (ain[li] != ain[i]) {
      cc += binom(2, i - li);
      li = i;
    }
  }
  cc += binom(2, n - li);
  cout << cc << "\n";
}
