#include <bits/stdc++.h>
using namespace std;
const double esp = 1e-8;
const int mod = 1e9 + 7;
const double pi = acos(-1);
const int inf = 0x3f3f3f3f;
const int maxn = 3e5 + 5;
const int maxm = 1e6 + 5;
map<long long, long long> cnt;
long long n, p, k;
long long a[maxn];
long long pre(long long x) {
  long long t = x;
  x = (x * x) % p;
  x = (x * x) % p;
  x = (x + p - (k * t) % p) % p;
  return x;
}
long long solve() {
  long long ans = 0;
  for (long long i = 1; i <= n; i++) {
    long long t = pre(a[i]);
    ans = (ans + cnt[t]);
    cnt[pre(a[i])]++;
  }
  return ans;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> p >> k;
  for (long long i = 1; i <= n; i++) cin >> a[i];
  long long res = solve();
  cout << res << endl;
  return 0;
}
