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