#include <bits/stdc++.h>
using namespace std;
const double pi = acos(-1.0);
const int N = 0;
map<long long int, int> m;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  ;
  int n, p, k;
  cin >> n >> p >> k;
  long long int res = 0;
  for (int i = 1; i <= n; ++i) {
    int x;
    cin >> x;
    long long int temp = (1LL * x * x) % p;
    temp = (temp * temp) % p;
    temp = (temp - (1LL * k * x % p) + p) % p;
    if (m.find(temp) == m.end()) {
      m[temp] = 1;
    } else {
      m[temp]++;
    }
  }
  for (auto it : m) {
    int x = it.second;
    res += x * (x - 1) / 2;
  }
  cout << res;
  return 0;
}
