#include <bits/stdc++.h>
using namespace std;
signed main() {
  long long n, p, k;
  cin >> n >> p >> k;
  vector<long long> v(n);
  for (long long i = 0; i < n; i++) cin >> v[i];
  map<long long, long long> mp;
  for (long long i = 0; i < n; i++) {
    long long t = (v[i] * v[i]) % p;
    t = (t * t) % p;
    t = (t - k * v[i]) % p;
    t = (t + p) % p;
    mp[t]++;
  }
  long long ans = 0;
  for (auto i : mp) ans += (i.second * (i.second - 1)) / 2;
  cout << ans << endl;
}
