#include <bits/stdc++.h>
using namespace std;
template <typename T1, typename T2>
inline void chkmin(T1 &x, T2 y) {
  if (x > y) x = y;
}
template <typename T1, typename T2>
inline void chkmax(T1 &x, T2 y) {
  if (x < y) x = y;
}
const string FILENAME = "input";
const int MAXN = 300027;
int n, p, k;
int a[MAXN];
map<int, int> cnt;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> p >> k;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  long long ans = 0;
  for (int i = 0; i < n; i++) {
    a[i] = (1LL * a[i] * a[i] % p * a[i] % p * a[i] % p) - (1LL * a[i] * k) % p;
    if (a[i] < 0) {
      a[i] += p;
    }
    ans += cnt[a[i]];
    cnt[a[i]]++;
  }
  cout << ans << '\n';
  return 0;
}
