#include <bits/stdc++.h>
using namespace std;
long long power(long long x, unsigned long long y, unsigned long long m) {
  if (y == 0) return 1;
  long long p = power(x, y / 2, m) % m;
  p = (p * p) % m;
  return (y % 2 == 0) ? p : (x * p) % m;
}
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long n, pi, k;
  cin >> n >> pi >> k;
  long long arr[n], x, ans = 0;
  map<long long, long long> m;
  for (long long i = 0; i < n; i++) {
    cin >> x;
    arr[i] = (power(x, 4, pi) - k * x) % pi;
    arr[i] += pi, arr[i] %= pi;
  }
  for (long long i = n - 1; i >= 0; i--) {
    ans += m[arr[i]];
    m[arr[i]]++;
  }
  cout << ans;
  return 0;
}
