#include <bits/stdc++.h>
using namespace std;
const int N = 3e5 + 10;
int n, mod, k;
long long a[N];
int main() {
  scanf("%d%d%d", &n, &mod, &k);
  map<long long, long long> tmp;
  for (int i = 1; i <= n; ++i) {
    scanf("%lld", &a[i]);
    long long x = a[i] % mod;
    long long y =
        (x * x % mod * x % mod * x % mod - (long long)k * x % mod) % mod;
    y = (y % mod + mod) % mod;
    tmp[y]++;
  }
  long long res = 0;
  for (auto t : tmp) {
    res += (long long)t.second * (t.second - 1) / 2;
  }
  printf("%lld\n", res);
}
