#include <bits/stdc++.h>
using namespace std;
const int inf = INT_MAX >> 1;
inline long long read() {
  long long res(0), f(1);
  register char c;
  while (isspace(c = getchar()))
    ;
  c == '-' ? f = -1, c = getchar() : 0;
  while (res = (res << 1) + (res << 3) + (c & 15), isdigit(c = getchar()))
    ;
  return res * f;
}
long long n, p, k;
long long a[300000 + 5];
long long f[300000 + 5];
map<long long, long long> mp;
inline void Ot() {
  n = read(), p = read(), k = read();
  for (register long long i = 1; i <= n; i++) a[i] = read();
  for (register long long i = 1; i <= n; i++) {
    f[i] = (a[i] * a[i]) % p * a[i] % p * a[i] % p - a[i] * k % p;
    f[i] %= p;
    if (f[i] < 0) f[i] += p;
  }
  long long ans = 0;
  for (register long long i = 1; i <= n; i++) {
    ans += mp[f[i]];
    ++mp[f[i]];
  }
  cout << ans << endl;
  return;
}
signed main() { return Ot(), 0; }
