#include <bits/stdc++.h>
using namespace std;
int cal(int inp, int p, int k) {
  long long int cal = ((long long int)(inp % p) * (long long int)(inp % p)) % p;
  cal = (cal * cal) % p;
  cal -= ((long long int)k * inp) % p;
  if (cal < 0) cal += p;
  return (int)cal;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  ;
  int n, p, k;
  cin >> n >> p >> k;
  int inp;
  map<int, int> out;
  for (int i = 0; i < n; i++) {
    cin >> inp;
    out[cal(inp, p, k)]++;
  }
  long long int ans = 0;
  for (pair<int, int> f : out) {
    ans += ((long long int)f.second * (f.second - 1)) / 2;
  }
  cout << ans << '\n';
}
