#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e6 + 7;
const int inf = INT_MAX;
const long long inff = 1e18;
const long long mod = 1e9 + 7;
long long n, p, k;
long long a[maxn];
set<long long> s;
int32_t main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> p >> k;
  for (long long i = 1; i <= n; i++) {
    cin >> a[i];
    long long now = a[i];
    a[i] = a[i] * a[i] % p * a[i] % p * a[i] % p;
    a[i] = (a[i] + p - k * now % p) % p;
    s.insert(a[i]);
  }
  sort(a + 1, a + n + 1);
  long long ans = 0;
  for (long long i : s) {
    long long now =
        upper_bound(a + 1, a + n + 1, i) - lower_bound(a + 1, a + n + 1, i);
    ans = (ans + now * (now - 1) / 2);
  }
  cout << ans << endl;
}
