#include <bits/stdc++.h>
using namespace std;
void no(int ex);
const int N = 2e5 + 11;
const int mod = 1e9 + 7;
map<long long, long long> mt;
long long n, m, k, T;
long long p, q, ans = 0;
long long binpow(long long zx, long long step) {
  long long extent = 1;
  while (step) {
    if (step & 1) extent *= zx;
    zx *= zx;
    step >>= 1;
  }
  return extent;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> p >> k;
  for (int i = 0; i < int(n); i++) {
    cin >> q;
    long long bp = binpow(q, 2);
    long long w = ((bp % p) * (bp % p) % p) - (q * k) % p;
    w += p;
    w %= p;
    ans += mt[w];
    mt[w]++;
  }
  cout << ans << "\n";
  return 0;
}
void no(int ex = -1) {
  cout << ex << "\n";
  cout << "NO"
       << "\n";
  exit(0);
}
