#include <bits/stdc++.h>
using ll = long long;
int p;
std::map<int, int> count;
int mult(int a, int b) { return (ll)a * b % p; }
int sub(int a, int b) {
  a -= b;
  if (a < 0) {
    a += p;
  }
  return a;
}
int main() {
  int n, k;
  scanf("%d%d%d", &n, &p, &k);
  for (int i = 0; i < n; i++) {
    int ai;
    scanf("%d", &ai);
    ai = sub(mult(k, ai), mult(mult(ai, ai), mult(ai, ai)));
    count[ai]++;
  }
  long long answer = 0;
  for (auto p : count) {
    answer += (ll)p.second * (p.second - 1) / 2;
  }
  printf("%lld\n", answer);
  return 0;
}
