#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vb = vector<bool>;
using vd = vector<double>;
using vs = vector<string>;
template <typename T>
void ckmin(T& a, const T& b) {
  a = min(a, b);
}
template <typename T>
void ckmax(T& a, const T& b) {
  a = max(a, b);
}
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
namespace __input {
template <typename T1, typename T2>
istream& operator>>(istream& i, pair<T1, T2>& p) {
  i >> p.first >> p.second;
  return i;
}
template <typename T, size_t N>
istream& operator>>(istream& i, array<T, N>& v) {
  for (auto& e : v) {
    i >> e;
  }
  return i;
}
template <typename T>
istream& operator>>(istream& i, vector<T>& v) {
  for (auto& e : v) {
    i >> e;
  }
  return i;
}
}  // namespace __input
using namespace __input;
namespace __output {
template <typename T1, typename T2>
ostream& operator<<(ostream& o, const pair<T1, T2>& t) {
  return o << "(" << t.first << ", " << t.second << ")";
}
template <typename T, size_t N>
ostream& operator<<(ostream& o, const array<T, N>& a) {
  o << "[";
  for (int i = 0; i < N; i++) {
    if (i) o << ", ";
    o << a[i];
  }
  return o << "]";
}
template <typename T>
ostream& operator<<(ostream& o, const vector<T>& v) {
  o << "[";
  for (int i = 0; i < int((v).size()); i++) {
    if (i) o << ", ";
    o << v[i];
  }
  return o << "]";
}
}  // namespace __output
using namespace __output;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0), cout.tie(0);
  int N, P, K;
  cin >> N >> P >> K;
  vi a(N);
  cin >> a;
  ll ans = 0;
  map<int, int> ct;
  for (auto& v : a) {
    ll r = v;
    r = r * r % P;
    r = r * r % P;
    r = (r - ll(K) * v) % P;
    if (r < 0) r += P;
    ans += ct[r]++;
  }
  cout << ans << endl;
  return 0;
}
