#include <bits/stdc++.h>
using namespace std;
template <typename T>
istream &operator>>(istream &is, vector<T> &vec) {
  for (auto &v : vec) is >> v;
  return is;
}
const int MOD = 1000000007;
const int N = 100005;
long long int M;
long long int power(long long int x, long long int n) {
  long long int res = 1;
  for (long long int i = 1; i <= n; i++) res = (res * x) % M;
  return res;
}
void solve() {
  long long int n, k;
  cin >> n >> M >> k;
  map<long long int, long long int> mp;
  long long int ans = 0;
  for (int i = 0; i < n; i++) {
    long long int x;
    cin >> x;
    long long int nw = power(x, (long long int)4);
    nw = (nw - (k * x) % M + M) % M;
    if (mp.find(nw) != mp.end()) {
      ans += mp[nw];
    }
    mp[nw]++;
  }
  cout << ans << "\n";
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long int t = 1;
  for (long int tt = 1; tt <= t; tt++) {
    solve();
  }
  return 0;
}
