#include <bits/stdc++.h>
using namespace std;
const long long MX = 300005;
long long a[MX], b[MX];
int32_t main() {
  long long n, p, k;
  cin >> n >> p >> k;
  for (long long i = 0; i < n; i++) {
    cin >> a[i];
    b[i] =
        (((a[i] * a[i]) % p) * ((a[i] * a[i]) % p) - (k * a[i]) + (k * p)) % p;
  }
  cout << endl;
  sort(b, b + n);
  long long j = 0, sum = 0;
  for (long long i = 0; i < n; i = j) {
    while (b[i] == b[j] && j < n) {
      j++;
    }
    long long num = j - i;
    sum += (num * (num - 1)) / 2;
  }
  cout << sum;
  return 0;
}
