#include <bits/stdc++.h>
using namespace std;
const int maxn = 300007;
long long n, p, k;
long long a[maxn], ans[maxn];
bool fg[maxn];
long long mult(long long a, long long b) { return (a * b) % p; }
int main() {
  memset(fg, 0, sizeof(fg));
  scanf("%lld%lld%lld", &n, &p, &k);
  for (int i = 1; i <= n; ++i) {
    scanf("%lld", &a[i]);
  }
  sort(a + 1, a + 1 + n);
  int i = 1;
  while (i <= n) {
    int u = a[i], j = i;
    while (j < n && a[j] == a[j + 1]) {
      j++;
    }
    if (mult(mult(4 * a[j], a[j]), a[j]) != k) {
      for (int k = i; k < j; ++k) {
        fg[k] = 1;
      }
    }
    i = j + 1;
  }
  int j = 0;
  for (int i = 1; i <= n; ++i) {
    if (!fg[i]) {
      ans[++j] =
          ((mult(mult(a[i], a[i]), mult(a[i], a[i])) - mult(k, a[i])) % p + p) %
          p;
    }
  }
  long long ret = 0;
  sort(ans + 1, ans + 1 + j);
  i = 1;
  while (i <= j) {
    int u = ans[i], k = i;
    while (k < j && ans[k] == ans[k + 1]) {
      k++;
    }
    ret += (k - i + 1) * (k - i) / 2;
    k++;
    i = k;
  }
  printf("%lld\n", ret);
  return 0;
}
