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)

#[derive(Debug)]
#[allow(dead_code)]
struct BiCoef{
    size: usize,
    modv: u64,
    inv: Vec<u64>,
    fact: Vec<u64>,
    invfact: Vec<u64>,
}

#[allow(dead_code)]
impl BiCoef{
    fn new(n: usize, modv : u64) -> Self {
        let mut inv = vec![0; n + 1];
        let mut fact =  vec![0; n + 1];
        let mut invfact =  vec![0; n + 1];
        inv[0] = 0 as u64;
        inv[1] = 1 as u64;
        for i in 2..(n+1) {
            inv[i] = inv[modv as usize % (i as usize)] * (modv - modv / i as u64)  as u64 % modv;
        }
        fact[0] =  1 as u64;
        invfact[0] = 1 as u64;
        for i in 1..(n+1) {
            fact[i] = i as u64 * fact[i - 1] % modv;
            invfact[i] = invfact[i - 1] * inv[i] % modv;
        }

        return BiCoef {size:n, modv:modv, inv:inv , fact:fact, invfact:invfact};
    }
    fn comb(&self, n : usize, r : usize) -> u64{
        if r > n{
            return 0;
        }
        return self.fact[n] * self.invfact[n - r] % self.modv * self.invfact[r] % self.modv;
    }
}

#[allow(dead_code)]
fn pow_mod(x:u64, y:u64, modv : u64) -> u64{
    let mut ret :u64 = 1;
    let mut xx = x;
    let mut yy = y;
    while yy > 0{
        if (yy&1) != 0 {
            ret = ret * xx % modv;
        }
        yy >>= 1;
        xx = xx * xx % modv;
    }
    return ret;
}

fn getline() -> String{
	let mut __ret=String::new();
	std::io::stdin().read_line(&mut __ret).ok();
	return __ret;
}

fn main() {
    let modv : u64 = 1000000007;
    let line = getline();

    let vec: Vec<&str> = line.split_whitespace().collect();
    let n:i32  = vec[0].parse().unwrap_or(0);
    let a:i32  = vec[1].parse().unwrap_or(0);
    let b:i32  = vec[2].parse().unwrap_or(0);
    let c:i32  = vec[3].parse().unwrap_or(0);
    
    let comb = BiCoef::new(std::cmp::max(100, 2 * n) as usize , modv);

    let ab = a+b;
    let mut ans : u64 = 0;

    let wt = a as u64 * comb.inv[ab as usize] % modv;
    let wa = b as u64 * comb.inv[ab as usize] % modv;

    // takahashi
    let wint = pow_mod(wt, n as u64, modv);
    let mut w_a : u64 = 1;

    for i in 0..n{
        ans += w_a * wint % modv * comb.comb((n + i - 1) as usize, i as usize) % modv * (n + i) as u64 % modv;
        w_a *= wa;
        w_a %= modv;
    }

    //aoki
    let wina = pow_mod(wa, n as u64, modv);
    let mut w_t : u64 = 1;    
    for i in 0..n{
        ans += w_t * wina % modv * comb.comb((n + i - 1) as usize, i as usize) % modv * (n + i) as u64 % modv;
        w_t *= wt;
        w_t %= modv;
    }

    ans %= modv;
    ans *= 100;
    ans %= modv;
    ans *= comb.inv[(100 - c) as usize ];
    ans %= modv;

    println!("{}", ans);
}