#include <bits/stdc++.h>
using namespace std;
template <class T>
void read(T& x) {
  T res = 0, f = 1;
  char c = getchar();
  while (!isdigit(c)) {
    if (c == '-') f = -1;
    c = getchar();
  }
  while (isdigit(c)) {
    res = (res << 3) + (res << 1) + c - '0';
    c = getchar();
  }
  x = res * f;
}
const long long N = 2000000 + 10;
long long mod, k, a[N], n, ans;
map<long long, long long> num;
long long calc(long long x) {
  return ((x * x % mod * x % mod * x % mod - k * x % mod) % mod + mod) % mod;
}
int main() {
  read(n);
  read(mod);
  read(k);
  for (int i = 1; i <= n; i++) read(a[i]);
  for (int i = 1; i <= n; i++) {
    long long tot = calc(a[i]);
    ans += num[tot];
    num[tot]++;
  }
  printf("%lld\n", ans);
  return 0;
}
