#include <bits/stdc++.h>
using namespace std;
long long power(long long a, long long b, long long p) {
  long long x = a % p;
  long long r = 1;
  while (b) {
    if (b % 2 == 1) {
      r = (r * x) % p;
    }
    x = (x * x) % p;
    b /= 2;
  }
  return r;
}
int32_t main() {
  long long n, p, k;
  cin >> n >> p >> k;
  long long a[n];
  for (long long i = 0; i < n; i++) {
    cin >> a[i];
  }
  map<long long, long long> mp;
  long long b[n];
  for (long long i = 0; i < n; i++) {
    b[i] = power(a[i], 4, p) - (k * a[i]) % p;
    b[i] = (b[i] + p) % p;
    mp[b[i]]++;
  }
  long long count = 0;
  cout << endl;
  for (auto u : mp) {
    count += (u.second * (u.second - 1)) / 2;
  }
  cout << count << endl;
  return 0;
}
