#include <bits/stdc++.h>
#pragma GCC optimize(3, "Ofast", "inline")
using namespace std;
mt19937 rng_32(chrono::steady_clock::now().time_since_epoch().count());
const int seed = 233;
const double PI = acos(-1.0);
const double eps = 1e-7;
const int inf = 0x3f3f3f3f;
const int max_n = 300005;
int mod;
namespace {
inline int Add(int x, int y) { return (x += y) >= mod ? x - mod : x; }
inline int Sub(int x, int y) { return (x -= y) < 0 ? x + mod : x; }
inline int Mul(int x, int y) { return 1ll * x * y % mod; }
inline int Pow(int x, int y = mod - 2) {
  if (x == 0) return 0;
  int res = 1;
  while (y) {
    if (y & 1) res = 1ll * res * x % mod;
    x = 1ll * x * x % mod;
    y >>= 1;
  }
  return res;
}
}  // namespace
int n, k;
int a[max_n];
map<int, int> mp;
int main() {
  scanf("%d%d%d", &n, &mod, &k);
  for (int i = 1; i <= n; i++) scanf("%d", a + i);
  long long ans = 0;
  for (int i = 1; i <= n; i++) {
    int x = Pow(a[i], 4);
    x = Sub(x, Mul(k, a[i]));
    mp[x]++;
  }
  for (auto x : mp) {
    int y = x.second;
    ans += 1ll * y * (y - 1) / 2;
  }
  mp.clear();
  for (int i = 1; i <= n; i++) mp[a[i]]++;
  for (auto x : mp) {
    int y = x.second;
    int r = x.first;
    if (Mul(Pow(r, 3), 4) != k) ans -= 1ll * y * (y - 1) / 2;
  }
  printf("%lld\n", ans);
  return 0;
}
