#include <bits/stdc++.h>
using namespace std;
long long int k, p;
long long int expo(long long int base, long long int exponent,
                   long long int mod) {
  long long int ans = 1;
  while (exponent != 0) {
    if (exponent & 1) ans = (1LL * ans * base) % mod;
    base = (1LL * base * base) % mod;
    exponent >>= 1;
  }
  return ans % mod;
}
long long int fun(long long int a) {
  long long int ret = expo(a, 4, p);
  long long int tmp = (k * a) % p;
  ret = (ret + p - tmp) % p;
  return ret;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int TESTS = 1;
  while (TESTS--) {
    long long int n;
    cin >> n >> p >> k;
    long long int arr[n + 1];
    for (long long int i = 1; i <= n; i++) cin >> arr[i];
    long long int brr[n + 1];
    for (long long int i = 1; i <= n; i++) brr[i] = fun(arr[i]);
    map<long long int, long long int> ma;
    for (long long int i = 1; i <= n; i++) ma[brr[i]]++;
    long long int ans = 0;
    for (auto i : ma) ans += i.second * (i.second - 1) / 2;
    cout << ans;
  }
  return 0;
}
