#include <bits/stdc++.h>
using namespace std;
template <typename T>
T gcd(T a, T b) {
  if (a == 0) return b;
  return gcd(b % a, a);
}
vector<long long> b_v;
void bin(unsigned long long n) {
  if (n > 1) bin(n >> 1);
  b_v.emplace_back(n & 1);
}
long long isPowerof2(long long x) { return (x && !(x & x - 1)); }
int32_t main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ostream_iterator<long long> output(cout, " ");
  long long n, p, k;
  cin >> n >> p >> k;
  long long a[n], b[n];
  for (long long(i) = (0); i < (n); i++) {
    cin >> a[i];
    long long tmp = (a[i] * a[i]) % p;
    tmp = (tmp * tmp) % p;
    long long var = (k * a[i]) % p;
    b[i] = ((tmp - var) % p + p) % p;
  }
  map<long long, long long> make_pair;
  long long ans = 0;
  for (long long(i) = (0); i < (n); i++) {
    ans += make_pair[b[i]];
    make_pair[b[i]]++;
  }
  cout << ans;
  return 0;
}
