Problem:
Score : 700 points

Problem Statement

Takahashi has a tower which is divided into N layers.
Initially, all the layers are uncolored. Takahashi is going to paint some of the layers in red, green or blue to make a beautiful tower.
He defines the beauty of the tower as follows:

The beauty of the tower is the sum of the scores of the N layers, where the score of a layer is A if the layer is painted red, A+B if the layer is painted green, B if the layer is painted blue, and 0 if the layer is uncolored.

Here, A and B are positive integer constants given beforehand. Also note that a layer may not be painted in two or more colors.

Takahashi is planning to paint the tower so that the beauty of the tower becomes exactly K.
How many such ways are there to paint the tower? Find the count modulo 998244353.
Two ways to paint the tower are considered different when there exists a layer that is painted in different colors, or a layer that is painted in some color in one of the ways and not in the other.

Constraints

1 ≤ N ≤ 3×10^5

1 ≤ A,B ≤ 3×10^5

0 ≤ K ≤ 18×10^{10}

All values in the input are integers.

Input

Input is given from Standard Input in the following format:

N A B K

Output

Print the number of the ways to paint tiles, modulo 998244353.

Sample Input 1

4 1 2 5

Sample Output 1

40

In this case, a red layer worth 1 points, a green layer worth 3 points and the blue layer worth 2 points. The beauty of the tower is 5 when we have one of the following sets of painted layers:

1 green, 1 blue

1 red, 2 blues

2 reds, 1 green

3 reds, 1 blue

The total number of the ways to produce them is 40.

Sample Input 2

2 5 6 0

Sample Output 2

1

The beauty of the tower is 0 only when all the layers are uncolored. Thus, the answer is 1.

Sample Input 3

90081 33447 90629 6391049189

Sample Output 3

577742975

Solution in C++14 (GCC 5.4.1) (judge verdict: Wrong Answer)

#include <bits/stdc++.h>
#include <stdlib.h>
using namespace std;
#define vi vector<int>
#define pii pair<int,int>
#define x first
#define y second
#define all(x) x.begin(),x.end()
#define pb push_back
#define mp make_pair
#define SZ(x) x.size()
#define rep(i,a,b) for(int i=a;i<b;i++)
#define per(i,a,b) for(int i=b-1;i>=a;i--)
#define pi acos(-1)
#define mod 998244353//1000000007
#define inf 1000000007
#define ll long long
#define DBG(x) cerr<<(#x)<<"="<<x<<"\n";
#define N 300010
#define _DEBUG
template <class U,class T> void Max(U &x, T y){if(x<y)x=y;}
template <class U,class T> void Min(U &x, T y){if(x>y)x=y;}
template <class T> void add(int &a,T b){a=(a+b)%mod;}

int pow(int a,int b){
	int ans=1;
	while(b){
		if(b&1)ans=1LL*ans*a%mod;
		a=1LL*a*a%mod;b>>=1;
	}
	return ans;
}

ll ex_gcd(ll a,ll b,ll &x,ll &y){
	if(b==0){
		x=1,y=0;
		return a;
	}
	ll x1,y1,d=ex_gcd(b,a%b,x1,y1);
	x=y1;
	y=x1-a/b*x;
	return d;
}
int f[N],inv[N];
ll C(int a,int b){
	return 1LL*f[a]*inv[a-b]%mod*inv[b]%mod;
}
int main(){
	//cout<<setprecision(6)<<fixed;
	clock_t start=clock();
	int ca=0,T,k,i,j,n,m=0;
	ll K, a,b;
	scanf("%d%lld%lld%lld",&n,&a,&b,&K);
	if(K==0){
		puts("1");return 0;
	}
	f[0]=1;
	rep(i,1,n+1)f[i]=f[i-1]*(ll)i%mod;
	inv[n]=pow(f[n],mod-2);
	per(i,0,n)inv[i]=inv[i+1]*(ll)(i+1)%mod;
	ll ans=0;
	if(a<b)swap(a,b);
	if(a==b){
		if(K%a){
			puts("0");return 0;
		}
		K/=a;
		rep(z,0,n/2+1){
			ll x=K-2*z;
			if(x<0||x>n-z)continue;
			ans+=1LL*pow(2,(int)x)*C(n,z)%mod*C(n-z,x)%mod;
		}
	}
	else{
		ll x,y;
		ll d=ex_gcd(a,b,x,y);
		if(K%d){
			puts("0");return 0;
		}
		ll b1=b/d,a1=a/d;
		x*=(K/d);
		x=x%b1;
		if(x<0)x+=b1;
		if(x>n){
			puts("0");return 0;
		}
		ll t=(K-b*n+a-1)/a;
		if(t>x){
			ll l=(t-x+b1-1)/b1;
			x+=b1*l;
		}
		t=min(K/a,(ll)n);
		if(x<=t){
			y=(K-a*x)/b;
			while(x<=t){
				ll r=min(x,y),l=max(0LL,x+y-n);
				rep(z,l,r+1){
					ans+=C(n,x+y-z)*C(x+y-z,x)%mod*C(x,z)%mod;
				}
				x+=b1;y-=a1;
			}
		}
	}
	ans%=mod;
	if(ans<0)ans+=mod;
	printf("%d\n",ans);
}