#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long n, p, k;
  cin >> n >> p >> k;
  map<long long, long long> m;
  for (long long i = 1; i <= n; i++) {
    long long a;
    cin >> a;
    long long val = (a * a) % p;
    val = (val * val) % p;
    val -= (k * a) % p;
    val = (val + p) % p;
    m[val]++;
  }
  long long ans = 0;
  for (auto i : m) {
    ans += ((i.second) * (i.second - 1)) / 2;
  }
  cout << ans;
}
