#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n, p, k;
  long long x;
  cin >> n >> p >> k;
  vector<long long> X;
  for (int i = 0; i < n; i++) {
    cin >> x;
    X.push_back(x);
  }
  map<long long, int> m;
  for (int i = 0; i < X.size(); i++) {
    long long val = (X[i] * X[i]) % p;
    val = (val * val) % p;
    val = val - (X[i] * k) % p;
    if (val < 0) {
      val = p + val;
    }
    if (m.find(val) == m.end()) {
      m[val] = 1;
    } else {
      m[val]++;
    }
  }
  long long sum = 0;
  map<long long, int>::iterator it;
  for (it = m.begin(); it != m.end(); it++) {
    int count = it->second;
    if (count != 1) {
      sum += count * (count - 1) / 2;
    }
  }
  cout << sum;
}
