#include <bits/stdc++.h>
using namespace std;
map<long long, long long> M;
signed main() {
  long long p, n, k;
  cin >> n >> p >> k;
  long long ans = 0;
  for (long long i = 0; i < n; i++) {
    long long tmp;
    cin >> tmp;
    M[(tmp * tmp % p * tmp % p * tmp % p - k * tmp % p + p) % p]++;
  }
  for (map<long long, long long>::iterator it = M.begin(); it != M.end();
       it++) {
    long long x = it->second;
    ans += (x * (x - 1)) / 2;
  }
  cout << ans << endl;
  return 0;
}
