#include <bits/stdc++.h>
using namespace std;
unsigned long long int power(unsigned long long int a, unsigned long long int b,
                             unsigned long long int p) {
  unsigned long long int res = 1;
  a = a % p;
  while (b > 0) {
    if (b & 1) {
      res = (res * a) % p;
      b--;
    }
    a = (a * a) % p;
    b >>= 1;
  }
  return res;
}
unsigned long long int gcd(unsigned long long int a, unsigned long long int b) {
  return (b == 0) ? a : gcd(b, a % b);
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  unsigned long long int n, p, k;
  cin >> n >> p >> k;
  vector<unsigned long long int> v(n);
  for (auto &i : v) cin >> i;
  map<unsigned long long int, unsigned long long int> cnt;
  for (unsigned long long int i = 0; i < n; i++) {
    unsigned long long int cur = (power(v[i], 4, p) - (k * v[i]) % p + p) % p;
    cnt[cur]++;
  }
  unsigned long long int ans = 0;
  for (auto i : cnt) ans += (i.second * (i.second - 1)) / 2;
  cout << ans << "\n";
}
