#include <bits/stdc++.h>
using namespace std;
long long a, mod, k, ans;
int n;
map<long long, long long> mm;
long long cac(long long x) {
  x = (x * x) % mod;
  x = (x * x) % mod;
  return x;
}
int main() {
  scanf("%d %lld %lld", &n, &mod, &k);
  while (n--) {
    scanf("%lld", &a);
    mm[(cac(a) - (k * a) % mod + mod * mod) % mod]++;
  }
  for (auto it = mm.begin(); it != mm.end(); it++)
    ans += (it->second) * (it->second - 1);
  printf("%lld", ans >> 1LL);
}
