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 LuaJIT (2.0.4) (judge verdict: Accepted)

local mce, mfl, msq, mmi, mma = math.ceil, math.floor, math.sqrt, math.min, math.max
local mod = 1000000007
local function bmul(x, y)
  local x1, y1 = x % 10000, y % 10000
  local x2, y2 = mfl(x / 10000) % 10000, mfl(y / 10000) % 10000
  local x3, y3 = mfl(x / 100000000), mfl(y / 100000000)
  local ret = (x1 * y1 + (x1 * y2 + x2 * y1) * 10000) % mod
  ret = (ret + (x1 * y3 + x2 * y2 + x3 * y1) * 10000 % mod * 10000 % mod) % mod
  ret = (ret + (x2 * y3 + x3 * y2) * 10000 % mod * 10000 % mod * 10000) % mod
  ret = (ret + x3 * y3 * 930000007) % mod
  return ret
end

local function modpow(src, pow)
  local res = 1
  while (0 < pow) do
    if (pow % 2 == 1) then
      res = bmul(res, src)
      pow = pow - 1
    end
    src = bmul(src, src)
    pow = mfl(pow / 2)
  end
  return res;
end

local function modinv(src)
  return modpow(src, mod - 2)
end

local cmb = 1
local n, a, b, c = io.read("*n", "*n", "*n", "*n")
local e = 0
local ta = bmul(a, modinv(a + b))
local tb = bmul(b, modinv(a + b))
for x = n, 2 * n - 1 do
  if x == n then cmb = 1
  else
    cmb = bmul(cmb, x - 1)
    cmb = bmul(cmb, modinv(x - 2 - (n - 1) + 1))
  end
  -- local cmb = getComb(x - 1, n - 1)
  local p1 = cmb
  local q = modpow(ta, n)
  local r = modpow(tb, x - n)
  p1 = bmul(p1, bmul(q, r))
  p1 = bmul(p1, x)

  local p2 = cmb
  q = modpow(tb, n)
  r = modpow(ta, x - n)
  p2 = bmul(p2, bmul(q, r))
  p2 = bmul(p2, x)

  local p = p1 + p2
  -- print(p1, p2)
  p = bmul(p, modinv(a + b))
  p = bmul(p, 100)
  e = (e + p) % mod
end
print(e)