#include <bits/stdc++.h>
using namespace std;
const int inf = 0x3f3f3f3f;
const long long INF = 0x3f3f3f3f3f3f3f3fLL;
const double PI = acos(-1.0);
const long double eps = 1e-6;
const int mod = 20180718;
const int maxn = 200 + 10;
const int M = 2e6 + 10;
const int N = 1e5 + 10;
const long long mm = (1LL << 32);
map<long long, long long> mp;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  long long n, p, k, res = 0;
  cin >> n >> p >> k;
  for (int i = 1; i <= n; ++i) {
    int x;
    cin >> x;
    res += mp[(x % p * x % p * x % p * x % p - k % p * x % p + p) % p]++;
  }
  cout << res;
  return 0;
}
