#include <bits/stdc++.h>
const long long INF = 3e9;
const double E = 1e-10;
const long long P = 1e9 + 7;
const long long Q = 31;
using namespace std;
void hello() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
}
void show(vector<long long>& arr) {
  for (auto i : arr) cout << i << " ";
  cout << "\n";
}
void show(vector<vector<long long>>& arr) {
  for (auto i : arr) show(i);
  cout << "\n";
}
signed main() {
  hello();
  long long n, p, k;
  cin >> n >> p >> k;
  vector<long long> seq(n);
  for (long long i = 0; i < n; ++i) {
    long long x;
    cin >> x;
    x = (x * x % p * x % p * x % p - k * x % p + 2 * p) % p;
    seq[i] = x;
  }
  sort(seq.begin(), seq.end());
  long long cnt = 1;
  long long res = 0;
  for (long long i = 1; i < n; ++i) {
    if (seq[i] == seq[i - 1])
      ++cnt;
    else {
      res += cnt * (cnt - 1) / 2;
      cnt = 1;
    }
  }
  res += cnt * (cnt - 1) / 2;
  cout << res << "\n";
}
