#include <bits/stdc++.h>
using namespace std;
int gi() {
  int x = 0, o = 1;
  char ch = getchar();
  while ((ch < '0' || ch > '9') && ch != '-') ch = getchar();
  if (ch == '-') o = -1, ch = getchar();
  while (ch >= '0' && ch <= '9') x = x * 10 + ch - '0', ch = getchar();
  return x * o;
}
int n, p, k;
long long ans = 0;
map<int, int> cnt;
int main() {
  cin >> n >> p >> k;
  for (int i = 1; i <= n; i++) {
    int x = gi(), v = (1ll * x * x % p * x % p * x - 1ll * k * x) % p;
    if (v < 0) v += p;
    ans += cnt[v], ++cnt[v];
  }
  cout << ans;
  return 0;
}
