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