#include <bits/stdc++.h>
using namespace std;
long long pow4(long long a, long long p) {
  a = a % p;
  return ((a * a % p) * (a * a % p) % p);
}
int main() {
  long long n, p, k;
  cin >> n >> p >> k;
  map<long long, map<long long, long long>> m;
  for (long long i = 0; i < n; i++) {
    long long a;
    cin >> a;
    long long a4 = (pow4(a, p) - k * a % p + p) % p;
    if (m[a4].count(a % p) != 1)
      m[a4][a % p] = 1;
    else
      m[a4][a % p]++;
  }
  long long s = 0;
  long long s1 = 0;
  for (map<long long, map<long long, long long>>::iterator it = m.begin();
       it != m.end(); ++it) {
    for (map<long long, long long>::iterator it1 = m[it->first].begin();
         it1 != m[it->first].end(); ++it1) {
      long long x = it1->second;
      s = s - x * x;
      s1 = s1 + x;
    }
    s = s1 * s1 + s;
    s1 = 0;
  }
  cout << s / 2;
  return 0;
}
