#include <bits/stdc++.h>
using namespace std;
long long n, m, k;
map<long long, long long> mp;
int main() {
  cin >> n >> m >> k;
  long long sum = 0;
  for (int i = 0; i < n; i++) {
    long long x;
    cin >> x;
    sum += mp[((1LL * x * x % m * x % m * x % m - 1LL * x * k % m) + m) % m]++;
  }
  cout << sum << endl;
  return 0;
}
