#include <bits/stdc++.h>
using namespace std;
long long ans = 0;
map<long long, long long> cnt;
int main() {
  long long N, p, K;
  long long A[300001];
  cin >> N >> p >> K;
  for (int i = 0; i < N; i++) {
    cin >> A[i];
    long long a = A[i];
    cnt[((((a * a) % p * ((a * a) % p)) % p - ((K % p) * (a % p)) % p) % p +
         p) %
        p]++;
  }
  for (auto it : cnt) {
    ans += (it.second * (it.second - 1)) / 2;
  }
  cout << ans << endl;
  return 0;
}
