#include <bits/stdc++.h>
#pragma GCC optimize(2)
using namespace std;
inline long long read() {
  char c = getchar();
  long long x = 0;
  bool f = 0;
  for (; !isdigit(c); c = getchar()) f ^= !(c ^ 45);
  for (; isdigit(c); c = getchar()) x = (x << 1) + (x << 3) + (c ^ 48);
  if (f) x = -x;
  return x;
}
long long n, k, mod;
inline long long qpow(long long a, long long b) {
  long long res = 1;
  for (register long long i = (1); i <= (b); ++i) res = res * a % mod;
  return res;
}
map<long long, long long> mp;
signed main() {
  n = read(), mod = read(), k = read();
  for (register long long i = (1); i <= (n); ++i) {
    long long x = read();
    long long a = (qpow(x, 4) - k * x % mod + mod) % mod;
    mp[a]++;
  }
  long long res = 0;
  for (map<long long, long long>::iterator it = mp.begin(); it != mp.end();
       ++it) {
    long long x = (*it).second;
    res += x * (x - 1) / 2;
  }
  cout << res;
  return 0;
}
