#include <bits/stdc++.h>
using namespace std;
const int N = 3e5 + 5;
long long n, p, k, x, ans;
unordered_map<int, int> cnt;
int main() {
  scanf("%lld%lld%lld", &n, &p, &k);
  for (int i = 0; i < n; ++i) {
    scanf("%lld", &x);
    int key = ((k * x % p - x * x % p * x % p * x % p) % p + p) % p;
    ans += cnt[key]++;
  }
  printf("%lld\n", ans);
  return 0;
}
