#include <bits/stdc++.h>
using namespace std;
char buf[1 << 21], *p1 = buf, *p2 = buf;
namespace wode {
template <typename T>
inline void read(T &x) {
  static char ch;
  bool f = 1;
  for (x = 0,
      ch = (p1 == p2 &&
                    (p2 = (p1 = buf) + fread(buf, 1, 1 << 21, stdin), p1 == p2)
                ? EOF
                : *p1++);
       !isdigit(ch);
       ch = (p1 == p2 &&
                     (p2 = (p1 = buf) + fread(buf, 1, 1 << 21, stdin), p1 == p2)
                 ? EOF
                 : *p1++))
    if (ch == '-') f = 0;
  for (; isdigit(ch);
       x = (x << 1) + (x << 3) + (ch ^ 48),
       ch = (p1 == p2 &&
                     (p2 = (p1 = buf) + fread(buf, 1, 1 << 21, stdin), p1 == p2)
                 ? EOF
                 : *p1++))
    ;
  x = f ? x : -x;
}
template <typename T>
inline void print(T x, char ch = 0) {
  if (!x) {
    putchar(48);
    if (ch) putchar(ch);
    return;
  }
  if (x < 0) putchar('-'), x = -x;
  static int Stack[sizeof(T) * 3], top = -1;
  for (; x; Stack[++top] = x % 10, x /= 10)
    ;
  for (; ~top; putchar(Stack[top--] + 48))
    ;
  if (ch) putchar(ch);
}
template <typename T>
inline T max(T x, T y) {
  return x < y ? y : x;
}
template <typename T>
inline T min(T x, T y) {
  return x < y ? x : y;
}
template <typename T>
inline void chkmax(T &x, T y) {
  x = x < y ? y : x;
}
template <typename T>
inline void chkmin(T &x, T y) {
  x = x < y ? x : y;
}
}  // namespace wode
using wode::chkmax;
using wode::chkmin;
using wode::print;
using wode::read;
unordered_map<int, int> f1, f2;
int a[300001], k, mod, n, b[300001];
long long tot;
inline long long kuai(long long p, long long q) {
  long long tot = 1;
  for (; q; p = p * p % mod, q >>= 1)
    if (q & 1) tot = tot * p % mod;
  return tot;
}
int main() {
  read(n), read(mod), read(k);
  for (register int i = 1; i <= n; ++i)
    read(a[i]), ++f1[a[i]],
        ++f2[b[i] = ((kuai(a[i], 4) - (long long)k * a[i] % mod) % mod + mod) %
                    mod];
  for (register int i = 1; i <= n; ++i) tot += f2[b[i]] - f1[a[i]];
  print(tot >> 1, '\n');
  return 0;
}
