#include <bits/stdc++.h>
using namespace std;
map<int, int> mp;
int main() {
  int n, p, k;
  scanf("%d%d%d", &n, &p, &k);
  long long ans = 0;
  for (int u = 1; u <= n; u++) {
    int x;
    scanf("%d", &x);
    x = (long long)x * x % p * x % p * x % p - (long long)k * x % p;
    x = (x % p + p) % p;
    ans = ans + mp[x];
    mp[x]++;
  }
  printf("%lld\n", ans);
  return 0;
}
