#include <bits/stdc++.h>
using namespace std;
const double eps = 1e-8;
const int inf = 0x3f3f3f3f;
const int maxn = 3e5 + 5;
long long a[maxn];
long long qmod(long long a, long long b, long long m) {
  if (!b) return 1 % m;
  long long ans = 1;
  while (b) {
    if (b & 1) ans = (ans * a) % m;
    a = (a * a) % m;
    b >>= 1;
  }
  return ans;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  long long p, k;
  cin >> n >> p >> k;
  map<long long, int> b;
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
    long long tmp = (qmod(a[i], 4, p) - k * a[i]);
    tmp += p * (abs(tmp) / p + 1);
    b[tmp % p]++;
  }
  long long sum = 0;
  for (auto it = b.begin(); it != b.end(); ++it) {
    if (it->second > 1) sum += (it->second) * (it->second - 1) / 2;
  }
  cout << sum << endl;
  return 0;
}
