#include <bits/stdc++.h>
using namespace std;
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
long long n, m, a[303030], p, k, ans;
map<long long, long long> cnt;
void solve() {
  cin >> n >> p >> k;
  for (long long i = 1; i <= n; i++) {
    cin >> a[i];
    long long cur =
        (a[i] * a[i] % p * a[i] % p * a[i] % p - a[i] * k % p + p) % p;
    cnt[cur]++;
  }
  for (auto t : cnt) {
    ans = (ans + t.second * (t.second - 1) / 2);
  }
  cout << ans << endl;
}
signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.precision(8);
  long long t = 1;
  while (t--) solve();
  cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
  return 0;
}
