#include <bits/stdc++.h>
using namespace std;
const int N = 3e5 + 10;
const int mod = 1e9 + 7;
map<int, int> mp, rm;
int main() {
  int n, p, k;
  cin >> n >> p >> k;
  long long ans = 0;
  for (int i = 1; i <= n; ++i) {
    int x;
    cin >> x;
    rm[x]++;
    int y = (1LL * x * x % p * x % p * x % p - 1LL * k * x % p + p) % p;
    ans += mp[y];
    mp[y]++;
  }
  cout << ans << endl;
  return 0;
}
