#include <bits/stdc++.h>
using namespace std;
long long int ncr(long long int n) { return (n * (n - 1)) / 2; }
int main() {
  long long int n, p, k;
  cin >> n >> p >> k;
  map<long long int, long long int> hash;
  vector<long long int> num(n);
  for (long long int i = 0; i < n; i++) {
    cin >> num[i];
    hash[num[i]] = i;
  }
  long long int ans = 0;
  map<long long int, long long int> corresponding;
  map<pair<long long int, long long int>, long long int> count;
  for (long long int i = 0; i < n; i++) {
    long long int x1 = (num[i] * num[i]) % p;
    long long int x = ((x1 * x1) % p - (k * num[i]) % p) % p;
    if (x < 0) {
      x = x + p * (x / p + 1);
    }
    corresponding[x] += 1;
  }
  ans = 0;
  for (auto it = corresponding.begin(); it != corresponding.end(); it++) {
    ans += ncr(it->second);
  }
  cout << ans;
  return 0;
}
