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 Rust (1.15.1) (judge verdict: Time Limit Exceeded)

#[allow(unused_imports)]
use std::cmp::{Ordering};

#[allow(unused_imports)]
use std::collections::{BTreeMap, BTreeSet, BinaryHeap, HashMap, HashSet, VecDeque};

#[allow(unused_imports)]
use std::io::{stdin, stdout, BufWriter, Write};

#[allow(unused_imports)]
use std::iter::FromIterator;

#[allow(unused_macros)]
macro_rules! min {
    ($x: expr) => ($x);
    ($x: expr, $($z: expr),+) => {{
        std::cmp::min($x, min!($($z),*))
    }}
}

#[allow(unused_macros)]
macro_rules! max {
    ($x: expr) => ($x);
    ($x: expr, $($z: expr),+) => {{
        std::cmp::max($x, max!($($z),*))
    }}
}

#[allow(unused_macros)]
macro_rules! get { 
    ([$t: ty]) => { 
        { 
            let mut line = String::new(); 
            stdin().read_line(&mut line).unwrap(); 
            line.split_whitespace().map(|t|t.parse::<$t>().unwrap()).collect::<Vec<_>>()
        }
    };
    ([$t: ty];$n: expr) => {
        (0..$n).map(|_|get!([$t])).collect::<Vec<_>>()
    };
    ($t: ty) => {
        {
            let mut line = String::new();
            stdin().read_line(&mut line).unwrap();
            line.trim().parse::<$t>().unwrap()
        }
    };
    ($($t: ty),*) => {
        { 
            let mut line = String::new();
            stdin().read_line(&mut line).unwrap();
            let mut iter = line.split_whitespace();
            ($(iter.next().unwrap().parse::<$t>().unwrap(),)*)
        }
    };
    ($t: ty; $n: expr) => {
        (0..$n).map(|_|get!($t)).collect::<Vec<_>>()
    };
    ($($t: ty),*; $n: expr) => {
        (0..$n).map(|_|get!($($t),*)).collect::<Vec<_>>()
    };
}

#[allow(unused_macros)]
macro_rules! debug {
    ($($a:expr),*) => {
        #[cfg(debug_assertions)]
        writeln!(&mut std::io::stderr(), concat!("[DEBUG] ", $(stringify!($a), "={:?} "),*), $($a),*).unwrap();
    }
}

const BIG_STACK_SIZE: bool = true;

#[allow(dead_code)]
fn main() {
    use std::thread;
    if BIG_STACK_SIZE {
        thread::Builder::new()
            .stack_size(32 * 1024 * 1024)
            .name("solve".into())
            .spawn(solve)
            .unwrap()
            .join()
            .unwrap();
    } else {
        solve();
    }
}

const MOD: usize = 998244353;

struct Comb {
    div: usize,
    g1: Vec<usize>,
    g2: Vec<usize>,
}
impl Comb {
#[allow(dead_code)]
    fn new(nmax: usize) -> Self {
        let mut g1 = vec![1; nmax + 1];
        let mut g2 = vec![1; nmax + 1];
        let mut inv = vec![0; nmax + 1];
        inv[1] = 1;
        let div = MOD;
        for i in 2..(nmax + 1) {
            g1[i] = g1[i - 1] * i % div;
            inv[i] = div - (inv[div % i] * (div / i)) % div;
            g2[i] = (g2[i - 1] * inv[i]) % div;
        }
        Comb {
            div: div,
            g1: g1,
            g2: g2,
        }
    }
#[allow(dead_code)]
    fn compute(&self, n: usize, k: usize) -> usize {
        (((self.g1[n] * self.g2[k]) % self.div) * self.g2[n - k]) % self.div
    }
#[allow(dead_code)]
    fn compute_dupc(&self, n: usize, k: usize) -> usize {
        self.compute(n + k - 1, n - 1)
    }
#[allow(dead_code)]
    fn compuute_perm(&self, n: usize, k: usize) -> usize {
        (self.g1[n] * self.g2[n - k]) % self.div
    }
}
use self::modint::ModInt;
mod modint {
    use std;
#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord)]
    pub struct ModInt(usize);
    impl ModInt {
        pub fn new(value: usize) -> Self {
            ModInt(value%Self::modulo())
        }
        fn modulo() -> usize {
            super::MOD
        }
    }
    impl std::ops::Add for ModInt {
        type Output = Self;
        fn add(self, other: Self) -> Self {
            let mut value = self.0 + other.0;
            if value > Self::modulo() {
                value -= Self::modulo();
            }
            ModInt::new(value)
        }
    }
    impl std::ops::Add<usize> for ModInt {
        type Output = Self;
        fn add(self, other: usize) -> Self {
            let mut value = self.0 + other;
            if value > Self::modulo() {
                value -= Self::modulo();
            }
            ModInt::new(value)
        }
    }
    impl std::ops::Sub for ModInt {
        type Output = Self;
        fn sub(self, other: Self) -> Self {
            let mut value = self.0;
            if value < other.0 {
                value += Self::modulo();
            }
            value -= other.0;
            ModInt::new(value)
        }
    }
    impl std::ops::Sub<usize> for ModInt {
        type Output = Self;
        fn sub(self, other: usize) -> Self {
            let mut value = self.0;
            if value < other {
                value += Self::modulo();
            }
            value -= other;
            ModInt::new(value)
        }
    }
    impl std::ops::Mul for ModInt {
        type Output = Self;
        fn mul(self, other: Self) -> Self {
            let value = self.0 * other.0 % Self::modulo();
            ModInt::new(value)
        }
    }
    impl std::ops::Mul<usize> for ModInt {
        type Output = Self;
        fn mul(self, other: usize) -> Self {
            let value = self.0 * other % Self::modulo();
            ModInt::new(value)
        }
    }
    impl std::ops::Div for ModInt {
        type Output = Self;
        fn div(self, other: Self) -> Self {
            let mut exp = Self::modulo() - 2;
            let mut value = self.0;
            let mut ovalue = other.0;
            while exp > 0 {
                if exp % 2 == 1 {
                    value = value * ovalue % Self::modulo();
                }
                ovalue = ovalue * ovalue % Self::modulo();
                exp /= 2;
            }
            ModInt::new(value)
        }
    }
    impl std::ops::Div<usize> for ModInt {
        type Output = Self;
        fn div(self, other: usize) -> Self {
            let mut exp = Self::modulo() - 2;
            let mut value = self.0;
            let mut ovalue = other;
            while exp > 0 {
                if exp % 2 == 1 {
                    value = value * ovalue % Self::modulo();
                }
                ovalue = ovalue * ovalue % Self::modulo();
                exp /= 2;
            }
            ModInt::new(value)
        }
    }
    impl std::ops::AddAssign for ModInt {
        fn add_assign(&mut self, other: Self) {
            *self = *self + other;
        }
    }
    impl std::ops::AddAssign<usize> for ModInt {
        fn add_assign(&mut self, other: usize) {
            *self = *self + other;
        }
    }
    impl std::ops::SubAssign for ModInt {
        fn sub_assign(&mut self, other: Self) {
            *self = *self - other;
        }
    }
    impl std::ops::SubAssign<usize> for ModInt {
        fn sub_assign(&mut self, other: usize) {
            *self = *self - other;
        }
    }
    impl std::ops::MulAssign for ModInt {
        fn mul_assign(&mut self, other: Self) {
            *self = *self * other;
        }
    }
    impl std::ops::MulAssign<usize> for ModInt {
        fn mul_assign(&mut self, other: usize) {
            *self = *self * other;
        }
    }
    impl std::ops::DivAssign for ModInt {
        fn div_assign(&mut self, other: Self) {
            *self = *self / other;
        }
    }
    impl std::ops::DivAssign<usize> for ModInt {
        fn div_assign(&mut self, other: usize) {
            *self = *self / other;
        }
    }
    impl std::fmt::Debug for ModInt {
        fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
            write!(f, "{}", self.0)
        }
    }
    impl std::fmt::Display for ModInt {
        fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
            write!(f, "{}", self.0)
        }
    }
}

fn solve() {
    let (n,a,b,k) = get!(usize, usize, usize, usize);

    let mut res = ModInt::new(0);
    let comb = Comb::new(n);
    for i in 0..n+1 {
        if i*a > k {
            break;
        }
        if (k-i*a)%b > 0 {
            continue;
        }
        let j = (k-i*a)/b;
        if i > n || j > n {
            continue;
        }
        let mn = max!(0, i as isize + j as isize - n as isize) as usize;
        for l in mn..min!(i,j)+1 {
            res += ModInt::new(comb.compute(n,i-l))
                * ModInt::new(comb.compute(n+l-i,j-l))
                * ModInt::new(comb.compute(n+2*l-i-j, l));
        }
    }
    println!("{}", res);
}