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