#include <bits/stdc++.h>
using namespace std;
long long int n, arr[300004], p, k, ans;
map<long long int, long long int> mp;
int main() {
  cin >> n >> p >> k;
  for (long long int i = 0; i < n; i++) {
    cin >> arr[i];
    long long int u = (arr[i] % p * arr[i] % p * arr[i] % p * arr[i] % p) % p;
    long long int v = (k * arr[i]) % p;
    long long int eff = (u - v + p) % p;
    ans += mp[eff];
    mp[eff]++;
  }
  cout << ans << endl;
  return 0;
}
