#include <bits/stdc++.h>
using namespace std;
long long a[300005];
long long s[300005];
int main() {
  ios::sync_with_stdio(0);
  cin.tie(NULL);
  int n, p, k;
  cin >> n >> p >> k;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    a[i] %= p;
  }
  map<long long, long long> cnt;
  for (int i = 1; i <= n; i++) {
    s[i] = a[i] * a[i] % p;
    s[i] = s[i] * a[i] % p;
    s[i] -= k;
    s[i] = (s[i] % p + p) % p;
    s[i] = s[i] * a[i] % p;
    cnt[s[i]]++;
  }
  long long res = 0;
  for (auto i : cnt) {
    long long val = i.second * (i.second - 1) / 2;
    res += val;
  }
  cout << res;
  return 0;
}
