#include <bits/stdc++.h>
using namespace std;
const long long maxN = 1e18;
const long long minN = -1e18;
const long long MOD = 1e9 + 7;
const long long MOD1 = 998244353;
const int baseHash = 331;
const int bigNumLength = 5000;
const long double PI = acos(-1);
const long long limit = 3e5 + 5;
const long long limit1 = 1e6 + 5;
const long long limit2 = 1e3 + 5;
pair<int, int> dir[] = {{0, 1}, {1, 0},  {0, -1}, {-1, 0},
                        {1, 1}, {1, -1}, {-1, 1}, {-1, -1}};
pair<int, int> NON = {-1, -1};
long long n, p, k;
long long a[limit];
map<long long, long long> cnt;
set<long long> s;
long long power(long long n, long long k, long long m) {
  if (k == 0) return 1;
  long long t = power(n, k >> 1, m);
  return (k & 1) ? t * t % m * n % m : t * t % m;
}
void solveProblem() {
  long long ans = 0;
  for (int i = (1); i <= (n); ++i) {
    long long tmp = (power(a[i], 4, p) - ((k * a[i]) % p) + p * p) % p;
    s.insert(tmp);
    ++cnt[tmp];
  }
  for (auto it : s) {
    long long tmp = cnt[it];
    ans += tmp * (tmp - 1) / 2;
  }
  cout << ans << '\n';
}
void fastInput() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
}
void readInput() {
  cin >> n >> p >> k;
  for (int i = (1); i <= (n); ++i) cin >> a[i];
}
int main() {
  fastInput();
  readInput();
  solveProblem();
}
