#include <bits/stdc++.h>
using namespace std;
long long expo(long long base, long long exponent, long long mod) {
  long long ans = 1;
  while (exponent != 0) {
    if ((exponent & 1) == 1) {
      ans = ans * base;
      ans = ans % mod;
    }
    base = base * base;
    base %= mod;
    exponent >>= 1;
  }
  return ans % mod;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int TESTS = 1;
  while (TESTS--) {
    long long n, p, k;
    cin >> n >> p >> k;
    map<long long, long long> lol;
    for (long long int i = 0; i < n; i++) {
      long long x;
      cin >> x;
      long long temp = (expo(x, 4, p) - (k * x) % p + p) % p;
      lol[temp]++;
    }
    long long ans = 0;
    for (auto u : lol) ans += (u.second * (u.second - 1) / 2);
    cout << ans;
  }
  return 0;
}
