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