#include <bits/stdc++.h>
using namespace std;
map<long long, long long> m;
long long n, p, k;
long long f(long long x) {
  long long ans = 0;
  ans = (x * x) % p;
  ans = (ans * x) % p;
  ans = (ans * x) % p;
  ans = (ans - k * x + k * p) % p;
  return ans % p;
}
signed main() {
  cin >> n >> p >> k;
  long long ans = 0;
  for (long long i = 0; i < n; i++) {
    long long x;
    cin >> x;
    ans += m[f(x)];
    m[f(x)]++;
  }
  cout << ans << endl;
}
