#include <bits/stdc++.h>
using namespace std;
const long double inf = 2e18;
const int maxn = 100020;
const long long mod = 1e9 + 7;
map<long long, long long> num;
int n, p, k;
int main() {
  scanf("%d %d %d", &n, &p, &k);
  for (int i = 1; i <= n; i++) {
    long long x;
    scanf("%lld", &x);
    num[(x * x % p * x % p * x % p - x * k % p + p) % p]++;
  }
  long long ans = 0;
  for (auto x : num) {
    ans += x.second * (x.second - 1) / 2;
  }
  cout << ans << endl;
}
