#include <bits/stdc++.h>
using namespace std;
const long long N = 3e6 + 7, M = 1000000007, inf = INT_MAX;
const long long INF = LLONG_MAX;
long long pwrmod(long long a, long long b, long long mod) {
  long long res = 1;
  a %= mod;
  while (b) {
    if (b & 1) res = (1LL * res * a) % mod;
    a = (1LL * a * a) % mod;
    b >>= 1;
  }
  return res;
}
void solve() {
  long long n, p, k;
  cin >> n >> p >> k;
  long long arr[n];
  unordered_map<long long, long long> mp;
  long long ans = 0;
  for (long long i = 0; i < (long long)n; i++) {
    long long x;
    cin >> x;
    long long val = pwrmod(x, 4, p);
    val -= (k * x) % p;
    if (val < 0) val += p;
    ans += mp[val];
    mp[val]++;
  }
  cout << ans << '\n';
}
int32_t main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long test = 1;
  while (test--) solve();
}
