#include <bits/stdc++.h>
using namespace std;
long long mod_pow(long long a, long long n, long long p) {
  long long res = 1;
  while (n > 0) {
    if (n & 1) res = res * a % p;
    a = a * a % p;
    n >>= 1;
  }
  return res;
}
long long n, p, k;
vector<long long> a;
map<long long, long long> cnt;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> n >> p >> k;
  a.resize(n);
  for (long long i = (long long)(0); i < (long long)(n); i++) cin >> a[i];
  long long res = 0;
  for (long long i = (long long)(0); i < (long long)(n); i++) {
    res += cnt[(mod_pow(a[i], 4, p) - (k * a[i] % p) + p) % p];
    cnt[(mod_pow(a[i], 4, p) - (k * a[i] % p) + p) % p]++;
  }
  cout << res << endl;
  return 0;
}
