Codeforces 1244 C football season

wrong answer on test case 4
#include<stdio.h>
#include
using namespace std;

int gcd(int a, int b){
return (b == 0) ? a: gcd(b, a%b) ;
}

int modInverse(int a, int m){
if(m == 1)
return 0;
int m0 = m, y = 0, x=1;

while(a>1){
	int q = a/m, t = m;
	m = a%m, a = t;
	t = y;
	y = x - q * y;
	x = t;
}
if(x<0)
x += m0;
return x;
}

void extendedEuclidMethod(int a, int b){
int x, y;
if(b == 0){
int GCD = gcd(a, b);
GCD = a;
x = 1, y = 0;
}
//Recursive call
extendedEuclidMethod(b, a%b);
int cx = y;
int cy = x - (a/b)*y;

x = cx;
y = cy;

return;

}

void solve(){
int n, p, w, d;
cin>>n>>p>>w>>d;
int x, y, z;
int g = gcd(w, d);
if(p%g != 0){
cout<< -1;
return;
}
// if he win all the matches
if(n * w <p){
cout<<-1;
return;
}
p/=g;
w/=g;
d/=g;

y = ((p%w) * modInverse(d,w))%w;
x = (p-y*d)/w;
if(x+y>n){
	cout<<-1;
	return;
}
if(x<0){
	cout<<-1;
	return;
}

z = n - (x+y);
cout<<x << " "<<y<<" "<<z;

}
int main(){
solve();
return 0;

}