#include <bits/stdc++.h>
using namespace std;
int get() {
  int x = 0;
  char s = getchar();
  while (s < '0' || s > '9') s = getchar();
  while (s >= '0' && s <= '9')
    x = (x << 3) + (x << 1) + (s ^ 48), s = getchar();
  return x;
}
int n, p, k, x, t;
long long ans;
map<int, int> m;
int main() {
  n = get(), p = get(), k = get();
  while (n--) {
    x = get();
    t = ((1ll * x * x % p * x % p - k) * x % p + p) % p;
    ans += m[t]++;
  }
  printf("%lld", ans);
  return 0;
}
