#include <bits/stdc++.h>
using namespace std;
template <typename T>
void re(T &x) {
  x = 0;
  int f = 1;
  char c = getchar();
  while (c < '0' || c > '9') {
    if (c == '-') f = -1;
    c = getchar();
  }
  while (c >= '0' && c <= '9') {
    x = (x << 1) + (x << 3) + c - 48;
    c = getchar();
  }
  x *= f;
}
template <typename T>
void pr(T x) {
  if (x < 0) {
    putchar('-');
    x = ~x + 1;
  }
  if (x / 10) pr(x / 10);
  putchar(x % 10 + 48);
}
const int N = 3e5;
int n, p, k, a[N + 5];
long long ans;
map<long long, long long> m;
int main() {
  re(n);
  re(p);
  re(k);
  for (int i = 1; i <= n; i++) {
    re(a[i]);
    int x = ((a[i] * 1ll * a[i] % p * a[i] % p * a[i] % p) + p -
             a[i] * 1ll * k % p) %
            p;
    if (m.find(x) != m.end()) ans = (ans + m[x]) % p;
    m[x] = (m[x] + 1) % p;
  }
  pr(ans);
  putchar(10);
  return 0;
}
