#include <bits/stdc++.h>
using namespace std;
const int MAXN = 300005;
int n;
long long K, P;
long long s[MAXN];
map<long long, long long> c;
int main() {
  long long x, xx, ans = 0, cnt = 0;
  ;
  scanf("%d%lld%lld", &n, &P, &K);
  for (int i = 1; i <= n; i++) {
    scanf("%lld", &x);
    x %= P;
    xx = x * x % P * x % P * x % P - K * x % P;
    xx = (xx % P + P) % P;
    if (!c.count(xx)) {
      c[xx] = 0;
      s[++cnt] = xx;
    }
    c[xx]++;
  }
  for (int i = 1; i <= cnt; i++) {
    x = s[i];
    ans += c[x] * (c[x] - 1) / 2;
  }
  printf("%lld\n", ans);
  return 0;
}
