#include <bits/stdc++.h>
using namespace std;
map<int, int> mp;
int main(void) {
  int N, P, K;
  while (cin >> N >> P >> K) {
    mp.clear();
    for (int i = 1; i <= N; i++) {
      int t;
      scanf("%d", &t);
      int tmp =
          (((long long)t * t % P * t % P * t % P) - (long long)t * K % P + P) %
          P;
      mp[tmp] += 1;
    }
    long long ans = 0;
    for (map<int, int>::iterator it = mp.begin(); it != mp.end(); it++) {
      ans += (long long)(it->second) * (it->second - 1) / 2;
    }
    cout << ans << endl;
  }
  return 0;
}
