Problem:
Score : 500 points

Problem Statement

Takahashi and Aoki will play a game. They will repeatedly play it until one of them have N wins in total.

When they play the game once, Takahashi wins with probability A %, Aoki wins with probability B %, and the game ends in a draw (that is, nobody wins) with probability C %.
Find the expected number of games that will be played, and print it as follows.

We can represent the expected value as P/Q with coprime integers P and Q.
Print the integer R between 0 and 10^9+6 (inclusive) such that R \times Q \equiv P\pmod {10^9+7}.
(Such an integer R always uniquely exists under the constraints of this problem.)

Constraints

1 \leq N \leq 100000

0 \leq A,B,C \leq 100

1 \leq A+B

A+B+C=100

All values in input are integers.

Input

Input is given from Standard Input in the following format:

N A B C

Output

Print the expected number of games that will be played, in the manner specified in the statement.

Sample Input 1

1 25 25 50

Sample Output 1

2

Since N=1, they will repeat the game until one of them wins.
The expected number of games played is 2.

Sample Input 2

4 50 50 0

Sample Output 2

312500008

C may be 0.

Sample Input 3

1 100 0 0

Sample Output 3

1

B may also be 0.

Sample Input 4

100000 31 41 28

Sample Output 4

104136146

Solution in Rust (1.15.1) (judge verdict: Accepted)

#[allow(unused_macros)]
macro_rules! input {
    ( source = $ s : expr , $ ( $ r : tt ) * ) => { let mut iter = $ s . split_whitespace ( ) ; let mut next = || { iter . next ( ) . unwrap ( ) } ; input_inner ! { next , $ ( $ r ) * } };
    ( $ ( $ r : tt ) * ) => { let stdin = std :: io :: stdin ( ) ; let mut bytes = std :: io :: Read :: bytes ( std :: io :: BufReader :: new ( stdin . lock ( ) ) ) ; let mut next = move || -> String { bytes . by_ref ( ) . map ( | r | r . unwrap ( ) as char ) . skip_while ( | c | c . is_whitespace ( ) ) . take_while ( | c |! c . is_whitespace ( ) ) . collect ( ) } ; input_inner ! { next , $ ( $ r ) * } };
}
#[allow(unused_macros)]
macro_rules! input_inner {
    ( $ next : expr ) => { };
    ( $ next : expr , ) => { };
    ( $ next : expr , $ var : ident : $ t : tt $ ( $ r : tt ) * ) => { let $ var = read_value ! ( $ next , $ t ) ; input_inner ! { $ next $ ( $ r ) * } };
}
#[allow(unused_macros)]
macro_rules! read_value {
    ( $ next : expr , ( $ ( $ t : tt ) ,* ) ) => { ( $ ( read_value ! ( $ next , $ t ) ) ,* ) };
    ( $ next : expr , [ $ t : tt ; $ len : expr ] ) => { ( 0 ..$ len ) . map ( | _ | read_value ! ( $ next , $ t ) ) . collect ::< Vec < _ >> ( ) };
    ( $ next : expr , chars ) => { read_value ! ( $ next , String ) . chars ( ) . collect ::< Vec < char >> ( ) };
    ( $ next : expr , usize1 ) => { read_value ! ( $ next , usize ) - 1 };
    ( $ next : expr , $ t : ty ) => { $ next ( ) . parse ::<$ t > ( ) . expect ( "Parse error" ) };
}

#[allow(unused_macros)]
macro_rules! vec_md {
    ( $ init : expr ; $ ( $ dim : expr ) ;* ) => { vec_md ! ( $ ( $ dim ) ;* => $ init ) };
    ( $ head : expr ; $ ( $ tail : expr ) ;* => $ init : expr ) => { vec ! [ vec_md ! ( $ ( $ tail ) ;* => $ init ) ; $ head ] };
    ( $ head : expr => $ init : expr ) => { vec ! [ $ init ; $ head ] };
}

#[allow(dead_code)]
pub const M: u64 = 1_000_000_007;

fn main() {
    input! {
        n: u64,
        a: u64, b: u64, _c: u64
    }

    let comb = Comb::new(2*n as usize);
    let mut win_a = Co(0);
    let mut win_b = Co(0);
    for k in 0..n {
        let mut tmp = Co(comb.of((n+k-1) as usize, k as usize));
        tmp *= (Co(a) / Co(a+b)).pow(n-1);
        tmp *= (Co(b) / Co(a+b)).pow(k);
        tmp *= Co(a)/Co(a+b);
        tmp *= Co(n+k);
        win_a += tmp;
    }
    for k in 0..n {
        let mut tmp = Co(comb.of((n+k-1) as usize, k as usize));
        tmp *= (Co(b) / Co(a+b)).pow(n-1);
        tmp *= (Co(a) / Co(a+b)).pow(k);
        tmp *= Co(b)/Co(a+b);
        tmp *= Co(n+k);
        win_b += tmp;
    }
    println!("{}", (win_a + win_b) * Co(100) / Co(a + b));
}

#[allow(dead_code)]
struct Comb {
    fac: Vec<u64>,
    finv: Vec<u64>,
    inv: Vec<u64>,
}
#[allow(dead_code)]
impl Comb {
    fn new(n: usize) -> Self {
        let mut fac = vec![0; n];
        let mut finv = vec![0; n];
        let mut inv = vec![0; n];
        fac[0] = 1;
        fac[1] = 1;
        finv[0] = 1;
        finv[1] = 1;
        inv[1] = 1;
        for i in 2..n {
            let iu64 = i as u64;
            fac[i] = fac[i - 1] * iu64 % M;
            inv[i] = M - inv[(M % iu64) as usize] * (M / iu64) % M;
            finv[i] = finv[i - 1] * inv[i] % M;
        }
        Comb {
            fac: fac,
            finv: finv,
            inv: inv,
        }
    }
    fn of(&self, n: usize, k: usize) -> u64 {
        if n < k {
            0
        } else {
            self.fac[n] * (self.finv[k] * self.finv[n - k] % M) % M
        }
    }
    #[doc = " combination with repetition"]
    fn rep(&self, n: usize, k: usize) -> u64 {
        self.of(n + k - 1, k)
    }
}

#[allow(dead_code)]
use std::ops::*;
#[allow(dead_code)]
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct Co(pub u64);
#[allow(dead_code)]
impl Co {
    pub fn pow(self, mut n: u64) -> Self {
        let mut a = self;
        let mut res = Co(1);
        while n > 0 {
            if n & 1 == 1 {
                res *= a;
            }
            a = a * a;
            n >>= 1;
        }
        res
    }
}
#[allow(dead_code)]
impl std::fmt::Display for Co {
    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
        write!(f, "{}", self.0)
    }
}
#[allow(dead_code)]
impl Add for Co {
    type Output = Self;
    fn add(self, rhs: Self) -> Self {
        Co((self.0 + rhs.0) % M)
    }
}
#[allow(dead_code)]
impl AddAssign for Co {
    fn add_assign(&mut self, rhs: Self) {
        *self = *self + rhs;
    }
}
#[allow(dead_code)]
impl Div for Co {
    type Output = Self;
    fn div(self, rhs: Self) -> Self {
        Co(self.0 * modinv(rhs.0) % M)
    }
}
#[allow(dead_code)]
impl DivAssign for Co {
    fn div_assign(&mut self, rhs: Self) {
        *self = *self / rhs;
    }
}
#[allow(dead_code)]
impl Mul for Co {
    type Output = Self;
    fn mul(self, rhs: Self) -> Self {
        Co(self.0 * rhs.0 % M)
    }
}
#[allow(dead_code)]
impl MulAssign for Co {
    fn mul_assign(&mut self, rhs: Self) {
        *self = *self * rhs;
    }
}
#[allow(dead_code)]
impl Sub for Co {
    type Output = Self;
    fn sub(self, rhs: Self) -> Self {
        Co(sub_mod(self.0, rhs.0))
    }
}
#[allow(dead_code)]
impl SubAssign for Co {
    fn sub_assign(&mut self, rhs: Self) {
        *self = *self - rhs;
    }
}
#[allow(dead_code)]
fn sub_mod(a: u64, b: u64) -> u64 {
    let mut tmp = (a as i64 - b as i64) % M as i64;
    if tmp < 0 {
        tmp += M as i64;
    }
    tmp as u64
}
#[allow(dead_code)]
fn modinv(a_: u64) -> u64 {
    let m = M as i64;
    let mut a = a_ as i64;
    let mut b = m as i64;
    let mut u = 1;
    let mut v = 0;
    while b != 0 {
        let t = a / b;
        a -= t * b;
        std::mem::swap(&mut a, &mut b);
        u -= t * v;
        std::mem::swap(&mut u, &mut v);
    }
    u %= m;
    if u < 0 {
        u += m
    };
    u as u64
}