#include <bits/stdc++.h>
using namespace std;
const int N = 1000005;
int n, p, k;
map<int, int> m;
int modp(int t) {
  long long q = p;
  long long r = t % q;
  long long z = (r * r) % q;
  r = (z * z) % q - (((long long)t * (long long)k) % q);
  if (r < 0) r += q;
  return (int)r;
}
int main() {
  cin >> n >> p >> k;
  for (int i = 0; i < n; i++) {
    int t;
    cin >> t;
    t = modp(t);
    auto it = m.find(t);
    if (it == m.end()) {
      m.insert(make_pair(t, 1));
    } else {
      it->second++;
    }
  }
  long long sum = 0;
  for (auto it = m.begin(); it != m.end(); it++) {
    int z = it->second;
    sum += z * (z - 1) / 2;
  }
  cout << sum;
}
