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 Scala (2.11.7) (judge verdict: Accepted)

import java.util.Scanner


object Main {


  case class GF(representative: Long) extends AnyVal {
    def +(that: GF): GF = GF((this.representative + that.representative) % GF.mod)

    def -(that: GF): GF = GF((this.representative - that.representative + GF.mod) % GF.mod)

    def *(that: GF): GF = GF((this.representative * that.representative) % GF.mod)

    def /(that: GF): GF = this * that.inv

    def unary_- : GF = GF((-this.representative + GF.mod) % GF.mod)

    def inv: GF = GF.powGF(this, GF.mod - 2)
  }


  object GF {
    val mod: Long = (1e9 + 7).toLong

    val _0: GF = GF(0)
    val _1: GF = GF(1)

    def powGF(x: GF, t: Long): GF = {
      if (t == 0) {
        return GF(1)
      }
      val y = powGF(x, t / 2)
      if (t % 2 == 0) {
        y * y
      } else {
        x * y * y
      }
    }
  }

  def read() = {
    val sc = new Scanner(System.in)
    val n, a, b, c = sc.nextInt()
    (n, a, b, c)
  }


  //def combGF(n: Int, r: Int): GF = fracGF(n) / (fracGF(r) * fracGF(n - r))

  def solve2(n: Int, a: Int, b: Int, c: Int): Long = {
    val p = GF(a) / GF(a + b)
    val q = GF(b) / GF(a + b)
    val fracGF = (1 to 2 * n).map(GF(_)).scanLeft(GF(1))(_ * _)

    def combGF(n: Int, r: Int): GF = fracGF(n) / (fracGF(r) * fracGF(n - r))

    //def fracGF(n: Int): GF = (1 to n).map(GF(_)).foldLeft(GF(1))(_ * _)
    val powQ = (0 to n).scanLeft(GF(1))((x, _) => x * q)
    val powP = (0 to n).scanLeft(GF(1))((x, _) => x * p)
    val powPN = GF.powGF(p, n)
    val powQN = GF.powGF(q, n)
    val result0 = (0 until n).map(i =>
      combGF(n + i - 1, i) * (powPN * powQ(i) + powQN * powP(i)) * GF(n + i)
    ).foldLeft(GF(0))(_ + _)
    val result1 = result0 * GF(100) / (GF(100) - GF(c))
    result1.representative
  }


  def solve3(n: Int, a: Int, b: Int, c: Int): Float = {
    val p = a.toFloat / (a + b)
    val q = b.toFloat / (a + b)
    val fracGF = (1 to 2 * n).map(_.toFloat).scanLeft(1F)(_ * _)

    def combGF(n: Int, r: Int): Float = fracGF(n) / (fracGF(r) * fracGF(n - r))

    //def fracGF(n: Int): GF = (1 to n).map(GF(_)).foldLeft(GF(1))(_ * _)
    val powQ = (0 to n).scanLeft(1F)((x, _) => x * q)
    val powP = (0 to n).scanLeft(1F)((x, _) => x * p)
    val powPN = math.pow(p, n).toFloat
    val powQN = math.pow(q, n).toFloat
    val result0 = (0 until n).map { i =>
      combGF(n + i - 1, i) * (powPN * powQ(i) + powQN * powP(i)) * (n + i)
    }.foldLeft(0F)(_ + _)
    val result1 = result0 * 100F / (100F - c)
    result1
  }

  def main(args: Array[String]): Unit = {
    val (n, a, b, c) = read()
    println(solve2(n, a, b, c))
  }
}