#include <bits/stdc++.h>
using namespace std;
inline long long mod(long long a, long long m) {
  long long r = a % m;
  if (r < 0) r += m;
  return r;
}
map<long long, long long> mapa;
signed main() {
  long long n, p, k;
  cin >> n >> p >> k;
  long long r = 0;
  for (long long i = 0; i < n; i++) {
    long long x;
    cin >> x;
    long long y = mod(x * x, p);
    y = mod(y * y, p);
    r += mapa[mod(y - x * k, p)];
    mapa[mod(y - k * x, p)]++;
  }
  cout << r << endl;
}
