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# (Mono 4.6.2.0) (judge verdict: Accepted)

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace Competitive
{
    internal class Solution
    {
        public int N, A, B, C, H;
        public long MOD = 1000000007;
        private FermatCombination comb;
        public long[] MA, MB, MH;

        public void Run()
        {
            comb = new FermatCombination(250000);
            {
                var line = Input.ReadIntArray();
                N = line[0];
                A = line[1];
                B = line[2];
                C = line[3];
            }

            H = A + B;

            MH = new long[250000];
            MA = new long[250000];
            MB = new long[250000];
            MH[0] = 1;
            MA[0] = 1;
            MB[0] = 1;

            for (int i = 1; i < 250000; i++)
            {
                MH[i] = MH[i - 1] * H;
                MH[i] %= MOD;
                MA[i] = MA[i - 1] * A;
                MA[i] %= MOD;
                MB[i] = MB[i - 1] * B;
                MB[i] %= MOD;
            }

            long P1 = Calc();
            long P2 = 100;
            long P = (P1 * P2) % MOD;
            long Q1 = MH[2 * N];
            long Q2 = 100 - C;
            long Q = (Q1 * Q2) % MOD;
            long ret = P;
            ret *= FermatCombination.Div(Q, MOD);
            ret %= MOD;
            Console.WriteLine(ret);
        }

        public long Calc()
        {
            long ret = 0;
            for (int M = N; M <= 2 * N - 1; M++)
            {
                long r = comb.Combination(M - 1, N - 1);
                r *= MA[N];
                r %= MOD;
                r *= MB[M - N];
                r %= MOD;
                r *= MH[2 * N - M];
                r %= MOD;
                r *= M;
                r %= MOD;
                ret += r;
            }

            for (int M = N; M <= 2 * N - 1; M++)
            {
                long r = comb.Combination(M - 1, N - 1);
                r *= MB[N];
                r %= MOD;
                r *= MA[M - N];
                r %= MOD;
                r *= MH[2 * N - M];
                r %= MOD;
                r *= M;
                r %= MOD;
                ret += r;
            }

            return ret;
        }

    }

    // libs ----------
    // フェルマーの定理、逆元を使う場合
    class FermatCombination
    {
        public long[] Factrial; // 階乗
        public long[] Inverse; // 逆元
        public long MOD = 1000000007;

        public FermatCombination(int n)
        {

            Factrial = new long[n + 1];
            Inverse = new long[n + 1];
            Factrial[0] = 1;
            Inverse[0] = 1;

            for (int i = 1; i <= n; i++)
            {
                Factrial[i] = (Factrial[i - 1] * i) % MOD;
            }

            for (int i = 1; i <= n; i++)
            {
                // フェルマーの小定理で逆元を求める
                Inverse[i] = Power(Factrial[i], (int)MOD - 2, MOD) % MOD;
            }
        }

        public long Permutation(int n, int k)
        {
            return Factrial[n] * Inverse[n - k] % MOD;
        }

        public long Combination(int n, int k)
        {
            return Factrial[n] * Inverse[k] % MOD * Inverse[n - k] % MOD;
        }

        public static long Power(long x, long n, long M)
        {
            long tmp = 1;

            if (n > 0)
            {
                tmp = Power(x, n / 2, M);
                if (n % 2 == 0) tmp = (tmp * tmp) % M;
                else tmp = (((tmp * tmp) % M) * x) % M;
            }

            return tmp;
        }

        public static long Div(long x, long M)
        {
            return Power(x, (int)M - 2, M) % M;
        }
    }

    // common ----------

    internal static class Input
    {
        public static string ReadString()
        {
            string line = Console.ReadLine();
            return line;
        }

        public static int ReadInt()
        {
            string line = Console.ReadLine();
            return int.Parse(line);
        }

        public static int[] ReadIntArray()
        {
            string line = Console.ReadLine();
            return line.Split(' ').Select(int.Parse).ToArray();            
        }

        public static long ReadLong()
        {
            string line = Console.ReadLine();
            return long.Parse(line);
        }

        public static long[] ReadLongArray()
        {
            string line = Console.ReadLine();
            return line.Split(' ').Select(long.Parse).ToArray();
        }

        public static double[] ReadDoubleArray()
        {
            string line = Console.ReadLine();
            return line.Split(' ').Select(double.Parse).ToArray();
        }
    }
    
    internal class Program
    {
        public static void Main(string[] args)
        {
            var s = new Solution();
            s.Run();
        }
    }
}