#include <bits/stdc++.h>
using namespace std;
map<long long, long long> mp;
long long n, p, k, x, ans;
long long mul(long long a, long long b) { return 1LL * a * b % p; }
template <typename Head, typename... Tail>
long long mul(Head H, Tail... T) {
  return mul(H, mul(T...));
}
long long sum(long long a, long long b) { return (a + b + p) % p; }
int32_t main() {
  ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  cin >> n >> p >> k;
  while (n--) {
    long long x;
    cin >> x;
    ans += mp[sum(mul(x, x, x, x), -mul(x, k))]++;
  }
  return cout << ans, 0;
}
