#include <bits/stdc++.h>
using namespace std;
signed main() {
  cin.tie(nullptr)->sync_with_stdio(false);
  long long n, p, k;
  cin >> n >> p >> k;
  vector<long long> arr(n + 1);
  map<long long, long long> hm;
  for (long long i = 1; i <= n; i++) {
    cin >> arr[i];
  }
  long long ans = 0;
  for (long long i = 1; i <= n; i++) {
    long long v = arr[i] * arr[i] % p * arr[i] % p * arr[i] % p;
    v -= k * arr[i] % p;
    v += p;
    v %= p;
    ans += hm[v];
    hm[v]++;
  }
  cout << ans << "\n";
  return 0;
}
