#include <bits/stdc++.h>
using namespace std;
const int inf = 1000000000;
const long long Inf = 1000000000000000000ll;
int n;
long long p, k, ans, x;
map<int, int> mp;
int main() {
  scanf("%d%lld%lld", &n, &p, &k);
  for (int i = 1; i <= n; ++i) {
    scanf("%lld", &x);
    x = (x * x % p * x % p * x % p - k * x % p + p) % p;
    mp[(int)x]++;
  }
  for (map<int, int>::iterator it = mp.begin(); it != mp.end(); ++it) {
    int v = it->second;
    ans = (ans + 1ll * v * (v - 1) / 2ll);
  }
  printf("%lld\n", ans);
  return 0;
}
