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_imports)]
#![allow(non_snake_case)]
use std::cmp::*;
use std::collections::*;
use std::io::Write;

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

fn pow_m(n: i64, mut p: i64, m: i64) -> i64 {
    let mut r = n;
    let mut ret = 1;
    while p > 0 {
        if p % 2 == 0 {
            r = r * r % m;
            p /= 2;
        } else {
            ret = ret * r % m;
            p -= 1;
        }
    }
    ret
}

fn main() {
    // TODO n = 1
    let v = read_vec::<i64>();
    let (n, a, b, c) = (v[0], v[1], v[2], v[3]);
    let big_int = 1000_000_000 + 7;

    let mut numerator = 0;

    for &(a, b) in &[(a, b), (b, a)] {
        let mut coef = pow_m(a, n, big_int);
        let mut denom = pow_m(a + b, n, big_int);

        for i in n..2 * n {
            let mut temp = i * coef;
            // debug!(i, temp, coef);
            temp %= big_int;
            let denom_denom = mod_inverse(denom, big_int);
            temp *= denom_denom;
            temp %= big_int;
            // debug!(temp);
            numerator += temp;
            numerator %= big_int;
            // debug!(mod_inverse(numerator, big_int));

            // update
            coef *= i;
            coef %= big_int;
            coef *= mod_inverse(i - n + 1, big_int);
            coef %= big_int;
            coef *= b;
            coef %= big_int;
            denom *= a + b;
            denom %= big_int;
        }
    }
    // println!("{:?}", mod_inverse(numerator, big_int));
    let mut hikiwake = (100 * mod_inverse(100 - c, big_int)) % big_int;
    if c > 0 {
        numerator *= hikiwake;
        numerator %= big_int;
    }
    println!("{:?}", numerator);
}

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}

fn extgcd(a: i64, b: i64, x: &mut i64, y: &mut i64) -> i64 {
    let mut d = a;
    if b == 0 {
        *x = 1;
        *y = 0;
    } else {
        d = extgcd(b, a % b, y, x);
        *y -= (a / b) * (*x);
    }
    return d;
}

fn mod_inverse(a: i64, m: i64) -> i64 {
    let mut x: i64 = 0;
    let mut y: i64 = 0;
    extgcd(a, m, &mut x, &mut y);
    (m + x % m) % m
}