#include <bits/stdc++.h>
using namespace std;
const long long mk = 100055;
const long long logn = 29;
const long long mod = 1e9 + 7;
long long n, p, k;
vector<int> g[mk];
map<long long, int> cnt;
int ans = 0;
void init() {
  cin >> n >> p >> k;
  for (int i = 1; i <= n; i++) {
    long long x;
    cin >> x;
    long long m = (x * x) % p;
    m = (m * m) % p;
    m = m - k * x;
    if (m < 0) m += p * p;
    m %= p;
    ans += cnt[m];
    cnt[m]++;
  }
}
signed main() {
  init();
  cout << ans;
}
