#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3f;
const int MOD = (int)1e9 + 7;
const int N = (int)3e5 + 7;
int n, p, k, a[N];
map<int, int> cnt;
inline int add(int a, int b) { return (a += b) >= p ? a - p : a; }
inline int mul(int a, int b) { return 1ll * a * b % p; }
void Init() {
  cnt.clear();
  for (int i = (1); i < (n + 1); ++i) scanf("%d", a + i);
}
int Solve() {
  long long ans = 0;
  for (int i = (1); i < (n + 1); ++i) {
    int tmp = mul(mul(a[i], a[i]), mul(a[i], a[i]));
    tmp = add(tmp, p - mul(k, a[i]));
    ans += cnt[tmp];
    cnt[tmp]++;
  }
  return printf("%lld\n", ans);
}
int main() {
  while (~scanf("%d%d%d", &n, &p, &k)) {
    Init();
    Solve();
  }
  return 0;
}
