#include <bits/stdc++.h>
using namespace std;
long long n, m, k, l, i, j, a, b, res, p;
map<long long, long long> mp;
int main() {
  cin >> n >> p >> k;
  for (long long i = 0; i < n; i++) {
    cin >> a;
    long long nsh =
        ((((a * a) % p) * ((a * a) % p) % p) - ((k * a) % p) + p) % p;
    res += mp[nsh];
    mp[nsh]++;
  }
  cout << res;
}
