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 C++14 (GCC 5.4.1) (judge verdict: Accepted)

#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds ;
#define ll long long
#define ld float
#define rep(i,a,b) for(ll i=a;i<b;i+=1)
#define all(c) (c).begin(),(c).end()
#define pb push_back
#define sz(a) int((a).size())
#define hell (ll)1000000007
#define f first
#define s second
#define sll(x) scanf("%lld",&x)
#define si(x) scanf("%d",&x)
typedef tree< ll , null_type , less<ll> , rb_tree_tag , tree_order_statistics_node_update > ordered_set ;
ll t = 1 ;
const ll N = 1e6 + 3 ;
vector<ll> fact(N,0) , invFac(N,0) ;
ll powMod( ll base , ll expo )
{
    ll ans = 1 ;
    while( expo > 0 ){
        if( expo & 1 ){

            ans = ( ans * base ) % hell ;
        }
        base = ( base * base ) % hell ;
        expo >>= 1 ;
    }
    return ans ;
}
ll add( ll x , ll y ){
    return ( x + y ) % hell ;
}
ll sub( ll x , ll y ){
    ll ans = x ;
    ans = ( x - y + hell ) % hell ;
    ans = ( ans + hell ) % hell ;
    return ans; 
}
ll mult( ll x , ll y ){
    ll ans = ( x * y ) % hell ;
    //ans = ( ans + hell ) % hell ;
    return ans ;
}
ll inv( ll x ){
    return powMod( x , hell -2 ) ;
}
ll C( ll x , ll y )
{
    if( x < y || y < 0 )return 0 ;
    ll ans = mult( fact[x] , mult( invFac[y] , invFac[x-y] ) ) ;
    return ans ;
}
void solve()
{
    ll n , ans = 0 , a , b , c , cur = 0 ;
    cin >> n >> a >> b >> c ;
    a = mult( a , inv(100));
    b = mult( b , inv(100));
    c = mult( c , inv(100));
    a = mult( a , inv(sub(1,c)));
    b = mult( b , inv(sub(1,c)));
    //cout << "a : " << a << " b : " << b << " c : " << c << "\n" ; 
    rep( i , n , 2*n )
    {
        //cout << C(i-1,n-1) << "\n" ;
        cur = mult( C(i-1,n-1) , mult(powMod(a,n),powMod(b,i-n)));
        //cout << C(i-1,n-1) << " " << mult(powMod(a,n),powMod(b,i-n)) << " " ;
        cur = add(cur,mult(C(i-1,n-1),mult(powMod(a,i-n),powMod(b,n))));
        //cout << mult(powMod(a,i-n),powMod(b,n)) << "\n" ;
        ans = add( ans , mult(i,cur) ) ;
    }
    ans = mult( ans ,inv(sub(1,c)));
    cout << ans << "\n" ;
}
signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    fact[0] = 1 ;
    rep( i , 1 , N )
        fact[i] = ( fact[i-1] * i ) % hell ;
    invFac[N-1] = inv(fact[N-1]) ;
    for( ll i = N - 2 ; i >= 0 ; i-- ){
        invFac[i] = ( invFac[i+1] * (i+1) ) % hell ;
    }
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    //cin>>t;
    while(t--)
        solve() ;
    return 0 ;
}