#include <bits/stdc++.h>
using namespace std;
template <typename S, typename T>
ostream& operator<<(ostream& out, pair<S, T> const& p) {
  out << '(' << p.first << ", " << p.second << ')';
  return out;
}
template <typename T>
ostream& operator<<(ostream& out, vector<T> const& v) {
  long long l = v.size();
  for (long long i = 0; i < l - 1; i++) out << v[i] << ' ';
  if (l > 0) out << v[l - 1];
  return out;
}
template <typename T>
void trace(const char* name, T&& arg1) {
  cout << name << " : " << arg1 << "\n";
}
template <typename T, typename... Args>
void trace(const char* names, T&& arg1, Args&&... args) {
  const char* comma = strchr(names + 1, ',');
  cout.write(names, comma - names) << " : " << arg1 << " | ";
  trace(comma + 1, args...);
}
const long long N = 3e5 + 100;
long long MOD;
long long power(long long x, long long t) {
  long long ans = 1;
  while (t > 0) {
    if (t & 1) ans = 1LL * ans * x % MOD;
    x = 1LL * x * x % MOD;
    t >>= 1;
  }
  return ans;
}
inline long long sub(long long a, long long b) {
  a %= MOD;
  b %= MOD;
  a = ((a - b) % MOD + MOD) % MOD;
  return a;
}
inline long long add(long long a, long long b) {
  a %= MOD;
  b %= MOD;
  a = (a + b) % MOD;
  return a;
}
inline long long mul(long long a, long long b) {
  a %= MOD;
  b %= MOD;
  a = (a * b) % MOD;
  return a;
}
inline long long inv(long long a) {
  a = a % MOD;
  a = power(a, MOD - 2);
  return a;
}
long long a[N], n, k;
map<long long, long long> cnt;
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  cin >> n >> MOD >> k;
  for (long long i = 1; i <= n; i++) {
    long long temp;
    cin >> temp;
    long long kk = power(temp, 4);
    long long k2 = mul(k, temp);
    kk = sub(kk, k2);
    cnt[kk]++;
  }
  long long ans = 0;
  auto c2 = [](long long a) -> long long { return ((a * (a - 1)) / 2); };
  for (auto i : cnt) {
    ans += c2(i.second);
  }
  cout << ans << "\n";
}
