#include <bits/stdc++.h>
using namespace std;
inline int add(int a, int b, int mod) {
  a += b;
  if (a >= mod) a -= mod;
  if (a < 0) a += mod;
  return a;
}
inline int mul(int a, int b, int mod) { return (long long)a * b % mod; }
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int n;
  cin >> n;
  int p;
  cin >> p;
  int k;
  cin >> k;
  long long ans = 0;
  map<int, int> yes;
  for (int i = 0; i < n; ++i) {
    int a;
    cin >> a;
    int b = add(mul(a, mul(a, mul(a, a, p), p), p), -mul(a, k, p), p);
    ans += yes[b];
    ++yes[b];
  }
  cout << ans << '\n';
}
