#include <bits/stdc++.h>
using namespace std;
int main(int argc, char const *argv[]) {
  long long n, p, k;
  cin >> n >> p >> k;
  vector<long long> A(n);
  map<long long, long long> mp;
  for (long long i = 0; i < n; i++) {
    cin >> A[i];
    long long x = (((A[i] * A[i]) % p) * ((A[i] * A[i]) % p));
    x = x - (k % p * A[i] % p);
    if (x < 0) x += p;
    x = x % p;
    mp[x]++;
  }
  long long ans = 0;
  for (auto it : mp) {
    ans += (it.second * (it.second - 1)) / 2;
  }
  cout << ans << endl;
  return 0;
}
