#include <bits/stdc++.h>
using namespace std;
long long n, k, mod;
map<long long, long long> mp;
long long v(long long a) {
  long long r = a * a % mod;
  (r *= r) %= mod;
  return (r - k * a % mod + mod) % mod;
}
int main() {
  cin >> n >> mod >> k;
  for (int i = 0; i < n; i++) {
    long long a;
    cin >> a;
    mp[v(a)]++;
  }
  long long ans = 0;
  for (auto x : mp) {
    ans += x.second * (x.second - 1) / 2;
  }
  cout << ans << endl;
}
