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 Ruby (2.3.3) (judge verdict: Wrong Answer)

require 'pp'
# IS_DEBUG = true
IS_DEBUG = false
def dputs str
	if(IS_DEBUG)
		puts str
	end
end
def dpp str
	if(IS_DEBUG)
		pp str
	end
end

# TODO use constraint @n
class LinearEq
	attr_accessor :a, :b, :gcd, :lcm, :sol
	# ax+by=k where 1<=x,y<=n
	def initialize(a,b,k,n)
		@n = n
		@k = k
		# adjust as a >= b
		# must be here cause find_solution also uses these fields
		if(a < b)
			@a = b
			@b = a
		else
			@a = a
			@b = b
		end
		@gcd = nil
		@sol = nil
		self.set
		@sol = self.find_solution
	end
	def set
		# a * x0 + b * y0 = k
		# set gcd
		@x0, @y0, @gcd = calc_gcd(@a,@b,@k)
		# start with smallest positive x0, and positive y0
		# TODO
		@lcm = @a * @b / @gcd
		@x = @x0
		@y = @y0
		[@x, @y, @gcd]
	end
	def find_solution
		if(@x >= 0)
			da = @lcm/@a
			db = @lcm/@b
			d = @x/da
			@x -= d*da
			@y += d*db
		end
		if(@x <= 0)
			da = @lcm/@a
			db = @lcm/@b
			d = (-@x)/da+1
			@x += d*da
			@y -= d*db
		end
		if(@y <= 0)
			return nil
		end
		@x -= @lcm/@a
		@y += @lcm/@b
		{:x=>@x,:y=>@y}
	end
	def next_solution
		@x += @lcm/@a
		@y -= @lcm/@b
		if(@y <= 0)
			return nil
		end
		@sol = {:x=>@x,:y=>@y}
		return @sol
	end
	# returns [x0, y0, gcd]
	def calc_gcd(a,b,k)
		dputs "calc_gcd:(a,b)=(#{a},#{b})"
		if(a % b == 0)
			if(k % b != 0)
				return nil
			else
				return [0,k/b,b]
			end
		else
			sol = calc_gcd(b,a%b,k)
			if(sol.nil?)
				return nil
			else
				# a x + b y = k
				# y' = a/b x + y
				# sol : b y' + a%b x = k
				return [sol[1], sol[0]-a/b*sol[1], sol[2]]
			end
		end
	end
end

M=998244353

def bin_exp(n)
	exp = []
	while(n>0)
		exp.unshift(n%2)
		n >>= 1
	end
	exp
end

def add(a,b)
	(a+b)%M
end
def div(a,b)
	(a/b)%M
end
def mul(a,b)
	(a*b)%M
end
def pow(a,n)
	po = a
	prd = 1
	while(n > 0)
		if(n%2==1)
			prd = mul(prd,po)
		end
		po = mul(po,po)
		n >>= 1
	end
	prd
end
def mul_of_exp(a,b)
	(a*b) % (M-1)
end

def inv_over_998244353(a)
	m = 998244353
	def mul_over_998244353(a,b)
		m = 998244353
		a*b%m
	end
	def pow_over_998244353(a,n)
		po = a
		prd = 1
		while(n > 0)
			if(n%2==1)
				prd = mul_over_998244353(prd,po)
			end
			po = mul_over_998244353(po,po)
			n >>= 1
		end
		prd
	end
	prod = a
	com = [3,3,3,13,29,281,349]
	com.each{|n|
		prod = pow_over_998244353(prod,n)
	}
	return prod
end

N,A,B,K=gets.chomp.split(' ').map{|n| n.to_i}


# precomputation of factorial and combination
fact = Array.new(N+1)
finv = Array.new(N+1)
comb = Array.new(N+1)
fact[0] = 1
comb[0] = 1
tmp = 1
1.upto(N){|i|
	tmp = mul(tmp,i)
	fact[i] = tmp
}
finv[0]=finv[N]=0
1.upto(N){|i|
	finv[i] = inv_over_998244353(fact[i])
}
1.upto(N){|i|
	comb[i] = mul(mul(fact[N],finv[N-i]),finv[i])
}

sum = 0
leq = LinearEq.new(A,B,K,N)
dputs "#{leq.lcm}"
dputs "#{leq.gcd}"
while(!(sol = leq.next_solution).nil?)
	dputs "sol #{sol}"
	x = sol[:x]
	y = sol[:y]
	if(x > N || y > N)
		next
	end
	tmp = mul(comb[x],comb[y])
	dputs "plus #{tmp}"
	sum = add(sum, tmp)
end

if(K==0)
	sum = 1
end

puts sum