#include <bits/stdc++.h>
using namespace std;
long long read() {
  long long a = 0, b = getchar(), c = 1;
  while (!isdigit(b)) c = b == '-' ? -1 : 1, b = getchar();
  while (isdigit(b)) a = a * 10 + b - '0', b = getchar();
  return a * c;
}
void print(int x) {
  char y = x % 10 + '0';
  if (x >= 10) print(x / 10);
  putchar(y);
}
long long n, k, p, x, ans;
map<int, int> m;
int main() {
  n = read(), p = read(), k = read();
  for (int i = 1; i <= n; i++) {
    x = read();
    long long y = (x * x % p * x % p * x % p - x * k % p + p) % p;
    ans += m[y]++;
  }
  print(ans);
  return 0;
}
