#include <bits/stdc++.h>
using namespace std;
template <typename T1, typename T2>
inline void chmin(T1& a, T2 b) {
  if (a > b) a = b;
}
template <typename T1, typename T2>
inline void chmax(T1& a, T2 b) {
  if (a < b) a = b;
}
long long MOD = 998244353;
const long long MAX = 200060;
const long double pi = acos(-1);
const long double EPS = 1e-12;
long long fac[MAX], finv[MAX], inv[MAX];
void COMinit() {
  fac[0] = fac[1] = 1;
  finv[0] = finv[1] = 1;
  inv[1] = 1;
  for (long long i = 2; i < MAX; i++) {
    fac[i] = fac[i - 1] * i % MOD;
    inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
    finv[i] = finv[i - 1] * inv[i] % MOD;
  }
}
long long COM(long long n, long long k) {
  if (n < k) return 0;
  if (n < 0 || k < 0) return 0;
  return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
long long add(long long x, long long y) {
  x += y;
  if (x >= MOD) return x - MOD;
  return x;
}
long long sub(long long x, long long y) {
  x -= y;
  if (x < 0) return x + MOD;
  return x;
}
long long mult(long long x, long long y) { return (x * y) % MOD; }
long long bin_pow(long long x, long long p) {
  if (p == 0) return 1;
  if (p & 1) return mult(x, bin_pow(x, p - 1));
  return bin_pow(mult(x, x), p / 2);
}
void solve() {
  long long N, p, k;
  cin >> N >> p >> k;
  map<long long, long long> mp;
  MOD = p;
  for (long long i = 0; i < N; i++) {
    long long x;
    cin >> x;
    long long tmp = k * x % p;
    long long po = (((x * x % p) * x % p) * x % p) % p;
    tmp = tmp - po + p * 1e9;
    tmp %= p;
    mp[tmp]++;
  }
  long long ans = 0;
  for (auto x : mp) {
    long long m = x.second;
    ans += m * (m - 1) / 2;
  }
  cout << ans << '\n';
}
signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  solve();
}
