#include <bits/stdc++.h>
using namespace std;
int MOD;
struct mint {
  int n;
  mint(int n = 0) : n(n) {}
};
mint operator+(mint a, mint b) { return (a.n += b.n) >= MOD ? a.n - MOD : a.n; }
mint operator-(mint a, mint b) { return (a.n -= b.n) < 0 ? a.n + MOD : a.n; }
mint operator*(mint a, mint b) { return 1LL * a.n * b.n % MOD; }
mint &operator+=(mint &a, mint b) { return a = a + b; }
mint &operator-=(mint &a, mint b) { return a = a - b; }
mint &operator*=(mint &a, mint b) { return a = a * b; }
ostream &operator<<(ostream &os, mint a) { return os << a.n; }
istream &operator>>(istream &is, mint &a) { return is >> a.n; }
mint operator^(mint a, long long n) {
  mint r = 1;
  while (n) {
    if (n & 1) r *= a;
    a *= a;
    n >>= 1;
  }
  return r;
}
mint inv(mint x) {
  long long a = x.n, b = MOD, u = 1, v = 0;
  while (b) {
    long long t = a / b;
    swap((a -= t * b), b);
    swap((u -= t * v), v);
  }
  return mint(u);
}
bool operator<(const mint &a, const mint &b) { return a.n < b.n; }
int main() {
  int n;
  mint k;
  cin >> n >> MOD >> k;
  long long ans = 0;
  map<mint, int> cnt;
  while (n--) {
    mint a;
    cin >> a;
    mint val = (a ^ 4) - k * a;
    ans += cnt[val]++;
  }
  cout << ans << endl;
  return 0;
}
