#include <bits/stdc++.h>
using namespace std;
void read(long long &x) {
  x = 0;
  long long f = 1;
  char ch = getchar();
  for (; !isdigit(ch); ch = getchar())
    if (ch == '-') f = -f;
  for (; isdigit(ch); ch = getchar()) x = x * 10 + ch - '0';
  x *= f;
}
void print(long long x) {
  if (x < 0) putchar('-'), x = -x;
  if (!x) return;
  print(x / 10), putchar(x % 10 + 48);
}
void write(long long x) {
  if (!x)
    putchar('0');
  else
    print(x);
  putchar('\n');
}
const long long maxn = 1e6 + 10;
const long long inf = 1e9;
const double eps = 1e-8;
const long long mod = 1e9 + 7;
long long n, k, p, a[maxn];
map<long long, long long> s;
signed main() {
  read(n), read(p), read(k);
  for (long long i = 1; i <= n; i++)
    read(a[i]),
        a[i] = (1ll * a[i] * a[i] % p * a[i] % p * a[i] % p -
                1ll * a[i] * k % p + p) %
               p,
        s[a[i]]++;
  long long ans = 0;
  for (long long i = 1; i <= n; i++)
    ans = (ans + 1ll * s[a[i]] * (s[a[i]] - 1) / 2 % p) % p, s[a[i]] = 0;
  write(ans);
  return 0;
}
