#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, i;
  long long mod, k, tmp, aux, ans = 0LL;
  map<long long, long long> mapa;
  scanf("%d%lld%lld", &n, &mod, &k);
  for (i = 0; i < n; i++) {
    scanf("%lld", &tmp);
    aux = tmp * tmp, aux %= mod;
    aux *= tmp, aux %= mod;
    aux *= tmp, aux %= mod;
    aux -= ((tmp * k) % mod);
    if (aux < 0) aux += mod;
    ans += mapa[aux];
    mapa[aux]++;
  }
  printf("%lld\n", ans);
}
