#include <bits/stdc++.h>
using namespace std;
int a[301010];
int main() {
  int n, p, k;
  scanf("%d%d%d", &n, &p, &k);
  for (int i = 0; i < n; i++) {
    int x;
    scanf("%d", &x);
    int t = ((long long)(x) * (x) % p);
    t = ((long long)(t) * (t) % p);
    a[i] = t - ((long long)(k) * (x) % p);
    if (a[i] < 0) a[i] += p;
  }
  sort(a, a + n);
  long long ans = 0;
  for (int i = 0, j = 0; i < n; i = j) {
    while (j < n && a[i] == a[j]) j++;
    int D = j - i;
    ans += 1LL * D * (D - 1) / 2;
  }
  printf("%lld\n", ans);
}
