// ---------- begin ModInt ---------- //https://github.com/kenkoooo/competitive-programming-rs/blob/master/src/math/mod_int.rs //を参考にしています #[allow(dead_code)] mod modint { pub const MOD: u32 = 1_000_000_007; use std::ops::{Add, AddAssign, Div, DivAssign, Mul, MulAssign, Neg, Sub, SubAssign}; #[derive(Clone, Copy)] pub struct ModInt(pub T); type Num = u32; impl Add> for ModInt { type Output = ModInt; fn add(self, other: ModInt) -> ModInt { let mut d = self.0 + other.0; if d >= MOD { d -= MOD; } ModInt(d) } } impl AddAssign> for ModInt { fn add_assign(&mut self, other: ModInt) { *self = *self + other; } } impl Sub> for ModInt { type Output = ModInt; fn sub(self, other: ModInt) -> ModInt { let mut d = self.0 + MOD - other.0; if d >= MOD { d -= MOD; } ModInt(d) } } impl SubAssign> for ModInt { fn sub_assign(&mut self, other: ModInt) { *self = *self - other; } } impl Mul> for ModInt { type Output = ModInt; fn mul(self, other: ModInt) -> ModInt { ModInt(((self.0 as u64) * (other.0 as u64) % (MOD as u64)) as u32) } } impl MulAssign> for ModInt { fn mul_assign(&mut self, other: ModInt) { *self = *self * other; } } impl Div> for ModInt { type Output = ModInt; fn div(self, other: ModInt) -> ModInt { self * other.pow(MOD - 2) } } impl DivAssign> for ModInt { fn div_assign(&mut self, other: ModInt) { *self = *self / other; } } impl Neg for ModInt { type Output = ModInt; fn neg(self) -> ModInt { ModInt(if self.0 == 0 { 0 } else { MOD - self.0 }) } } impl ModInt { pub fn new(v: u32) -> ModInt { ModInt(v % MOD) } pub fn pow(self, mut n: u32) -> ModInt { let mut t = ModInt::new(1); let mut s = self; while n > 0 { if (n & 1) == 1 { t *= s; } s *= s; n >>= 1; } t } } pub struct Precalc { n: usize, inv: Vec>, fact: Vec>, ifact: Vec>, } impl Precalc { pub fn new(n: usize) -> Precalc { let mut inv = vec![ModInt(1); n + 1]; let mut fact = vec![ModInt(1); n + 1]; let mut ifact = vec![ModInt(1); n + 1]; for i in 1..(n + 1) { if i >= 2 { inv[i] = -inv[(MOD as usize) % i] * ModInt(MOD / (i as u32)); } fact[i] = ModInt(i as u32) * fact[i - 1]; ifact[i] = inv[i] * ifact[i - 1]; } Precalc { n: n, inv: inv, fact: fact, ifact: ifact, } } pub fn fact(&self, n: usize) -> ModInt { self.fact[n] } pub fn inv(&self, x: usize) -> ModInt { self.inv[x] } pub fn ifact(&self, x: usize) -> ModInt { self.ifact[x] } pub fn comb(&self, n: usize, k: usize) -> ModInt { if !(k <= n) { return ModInt(0); } self.fact[n] * self.ifact[k] * self.ifact[n - k] } } use std; impl std::fmt::Display for ModInt { fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { write!(f, "{}", self.0) } } } // ---------- end ModInt ---------- use modint::*; fn run() { let mut s = String::new(); std::io::stdin().read_line(&mut s).unwrap(); let mut it = s.trim().split_whitespace(); let n: usize = it.next().unwrap().parse().unwrap(); let m: usize = it.next().unwrap().parse().unwrap(); let d1: usize = it.next().unwrap().parse().unwrap(); let d2: usize = it.next().unwrap().parse().unwrap(); if 1 + d1 * (n - 1) > m { println!("0"); return; } let d = d2 - d1; let m = m - 1 - d1 * (n - 1); let pc = Precalc::new(n + m + 1); let mut ans = pc.comb(m + n, n); let mut sign = -ModInt(1); let mut i = 1; while i <= n - 1 && i * (d + 1) <= m { ans += sign * pc.comb(n - 1, i) * pc.comb(m + n - i * (d + 1), n); sign = -sign; i += 1; } println!("{}", ans); } fn main() { run(); }