#include <bits/stdc++.h>
using namespace std;
const int nsz = 3e5;
int n;
long long k, mod, a[nsz + 5], b[nsz + 5], ans;
map<long long, int> mp;
long long inline qpow(long long a, int p) {
  long long res = 1;
  for (; p; p >>= 1) {
    if (p & 1) {
      res *= a;
      res %= mod;
    }
    a *= a;
    a %= mod;
  }
  return res % mod;
}
long long inline modify(long long a) {
  a %= mod;
  return a < 0 ? a + mod : a;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin >> n >> mod >> k;
  for (int i = 1; i <= n; ++i) {
    cin >> a[i];
    ++mp[modify(qpow(a[i], 4) - k * a[i] % mod)];
  }
  for (__typeof(mp.begin()) it = mp.begin(); it != mp.end(); ++it) {
    ans += it->second * (it->second - 1) / 2;
  }
  cout << ans << endl;
}
