#include <bits/stdc++.h>
using namespace std;
template <typename T>
static ostream& operator<<(ostream& stream, const vector<T>& t);
template <typename T>
static istream& read(T, T, istream& = cin);
template <typename T>
static istream& operator>>(istream& stream, vector<T>& t) {
  return read((t).begin(), (t).end(), stream);
}
template <typename T>
static istream& read(T b, T e, istream& stream) {
  for (T it = b; it != e; ++it) stream >> *it;
  return stream;
}
long long _() {
  int n, p, k;
  cin >> n >> p >> k;
  vector<long long> arr(n);
  cin >> arr;
  map<long long, long long> s;
  long long ans = 0;
  for (auto x : arr) {
    long long y = ((x * x % p * x % p * x - k * x) % p + p) % p;
    ans += s[y];
    s[y]++;
  }
  return ans;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout << fixed << setprecision(15);
  cout << _() << '\n';
}
