#include <bits/stdc++.h>
using namespace std;
long long int xo(long long int x, long long int y) {
  return (x | y) & (~x | ~y);
}
long long int bin_Expo(long long int x, long long int n) {
  if (x == 0) return 0;
  if (n == 0)
    return 1;
  else if (n % 2 == 0)
    return bin_Expo(x * x, n / 2);
  else
    return x * bin_Expo(x * x, (n - 1) / 2);
}
long long int mod_Expo(long long int x, long long int n, long long int M) {
  if (x == 0) return 0;
  if (n == 0)
    return 1;
  else if (n % 2 == 0)
    return mod_Expo((x * x) % M, n / 2, M);
  else
    return (x * mod_Expo((x * x) % M, (n - 1) / 2, M)) % M;
}
bool prime_check(long long int x) {
  bool prime = (x >= 2);
  for (long long int i = 2; i * i <= x; i++) {
    if (x % i == 0) {
      prime = false;
      break;
    }
  }
  return prime;
}
long long int logg(long long int base, long long int x) {
  return (long long int)(log(x) / log(base));
}
long long int a[300005];
long long int mul(long long int a, long long int b, long long int p) {
  return (a * b) % p;
}
long long int add(long long int a, long long int b, long long int p) {
  return (a + b) % p;
}
long long int sub(long long int a, long long int b, long long int p) {
  return (a - b + p) % p;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int TESTS = 1;
  while (TESTS--) {
    long long int i, j, k, W, q, n, m, ans, l, r, p;
    cin >> n >> p >> k;
    for (long long int i = 0; i < n; i++) {
      cin >> a[i];
    }
    map<long long int, long long int> mm;
    ans = 0;
    for (long long int i = 0; i < n; i++) {
      j = a[i];
      mm[sub(mul(mul(j, j, p), mul(j, j, p), p), mul(k, j, p), p)]++;
    }
    for (__typeof(mm.begin()) it = mm.begin(); it != mm.end(); it++) {
      l = it->second;
      ans += (l * (l - 1)) / 2;
    }
    cout << ans;
  }
  return 0;
}
