#include <bits/stdc++.h>
using namespace std;
const int maxn = 3e5 + 10;
long long a[maxn];
int main() {
  int n, p, k;
  cin >> n >> p >> k;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  map<int, int> occur;
  occur.clear();
  for (int i = 0; i < n; i++) {
    int mod =
        (int)(((a[i] * a[i] % p * a[i] % p * a[i] % p) - k * a[i] % p + p) % p);
    occur[mod]++;
  }
  long long ans = 0;
  for (map<int, int>::iterator it = occur.begin(); it != occur.end(); ++it) {
    ans += 1ll * it->second * (it->second - 1) / 2;
  }
  cout << ans;
  return 0;
}
