int diofantic(int n, int s[], int a, int b, int c) {
int nr = 0;
for(int i=1; i<=n; ++i){
long long x = 1LL * a * s[i] * s[i];
long long y = c - x;
if ( y % b == 0 && y >= 0 ) {
y = y / b;
int z = sqrt(y);
if (z*z == y) {
int st = 1, dr = n, ok = 0;
while (st <= dr && !ok){
int m = (st + dr) / 2;
if (s[m] == z) ok = 1;
else if (z < s[m]) dr = m - 1;
else st = m + 1;
}
if (ok) ++nr;
}
}
}
return nr;
}