#include <bits/stdc++.h>
using namespace std;
const long long INF = 0x3f3f3f3f;
const long long MAXN = 3e5 + 5;
long long n, MOD, k, ans;
map<long long, long long> mp;
signed main() {
  scanf("%lld%lld%lld", &n, &MOD, &k);
  for (long long i = 1; i <= n; i++) {
    long long x;
    scanf("%lld", &x);
    x = (x * x % MOD * x % MOD * x % MOD + MOD - x * k % MOD) % MOD;
    mp[x]++;
  }
  for (map<long long, long long>::iterator it = mp.begin(); it != mp.end();
       it++) {
    long long x = it->second;
    ans += (x - 1) * x / 2;
  }
  printf("%lld\n", ans);
  return 0;
}
