#include <bits/stdc++.h>
using namespace std;
const long long Sz = 3e5 + 5;
map<long long, long long> f;
long long a[Sz];
long long n, p, k;
long long power4(long long x) { return x * x % p * x % p * x % p; }
signed main() {
  cin >> n >> p >> k;
  long long res = 0;
  for (long long i = 1; i <= n; ++i) {
    cin >> a[i];
    long long d = (power4(a[i]) - k * a[i] % p + p * p) % p;
    res += f[d]++;
  }
  cout << res << "\n";
  return 0;
}
