#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n, p, k;
  cin >> n >> p >> k;
  long long a[n];
  for (int i = 0; i < n; i++) cin >> a[i];
  long long b[n];
  for (int i = 0; i < n; i++)
    b[i] = ((((((a[i] * a[i]) % p) * a[i]) % p) * a[i]) % p);
  map<long long, int> m;
  for (int i = 0; i < n; i++) m[(b[i] - k * a[i] + k * p) % p]++;
  long long res = 0;
  for (auto x : m) {
    res += (x.second) * (x.second - 1) / 2;
  }
  cout << res << endl;
}
