#include <bits/stdc++.h>
const int N = 300010;
using namespace std;
int n;
long long x, ans = 0, MOD, K, a[N];
int main() {
  scanf("%d%lld%lld", &n, &MOD, &K);
  for (int i = 1; i <= n; i++)
    scanf("%lld", &x),
        a[i] = (x * x % MOD * x % MOD * x % MOD - K * x % MOD + MOD) % MOD;
  sort(a + 1, a + n + 1);
  int l = 1, r = 0;
  while (l <= n) {
    while (r < n && a[r + 1] == a[l]) r++;
    int len = r - l + 1;
    ans += 1LL * (len - 1) * len / 2 % MOD;
    l = r + 1;
  }
  printf("%lld\n", ans);
  return 0;
}
