#include <bits/stdc++.h>
using namespace std;
const int maxn = 3e5 + 5;
int mod;
long long qpow(long long a, long long b) {
  long long ans = 1;
  a %= mod;
  assert(b >= 0);
  for (; b; b >>= 1) {
    if (b & 1) ans = ans * a % mod;
    a = a * a % mod;
  }
  return ans;
}
long long gcd(long long a, long long b) { return b > 0 ? gcd(b, a % b) : a; }
long long a[maxn];
map<long long, int> M;
map<long long, int> mm;
int main() {
  int n, m, T, p, k;
  cin >> n >> p >> k;
  for (int i = 1; i <= n; i++) cin >> a[i];
  mod = p;
  long long ans = 0;
  if (k == 0) {
    for (int i = 1; i <= n; i++) {
      int x = p - qpow(a[i], 2), y = p - a[i];
      ans = (ans + M[y]) % mod;
      ans = (ans + mm[x]) % mod;
      if (2ll * a[i] % mod * a[i] % mod == 0) {
        ans = ((ans - M[y]) % mod + mod) % mod;
      }
      M[a[i]]++;
      mm[a[i] * a[i] % mod]++;
    }
  } else {
    for (int i = 1; i <= n; i++) {
      long long temp =
          ((qpow(a[i], 4) - 1ll * k * a[i] % mod) % mod + mod) % mod;
      ans = (ans + M[temp]) % mod;
      M[temp]++;
    }
  }
  cout << ans << endl;
  return 0;
}
