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



Sample input:
1 25 25 50


Sample output:
2

Submission status: Runtime Error

Solution code:
from scipy.misc import comb
 
N, A, B, C = map(int,input().split())
a, b, c = A/100, B/100, C/100
if N == 1:
  p = 1
else:
  a_, b_, p_ = a/(a+b), b/(a+b), 0
  p = float(comb(2*N-3,N-2) * ( a**N * b**(N-2) + a**(N-2) * b**N))
n = (a+b+c)/(1-c)
print(int(round(n*p)))

Submission status: Runtime Error

Solution code:
from scipy.misc import comb

N, A, B, C = map(int,input().split())
a, b, c = A/100, B/100, C/100
if N == 1:
  p = 1
else:
  a_, b_, p_ = a/(a+b), b/(a+b), 0
  p = float(comb(2*N-3,N-2) * ( a**N * b**(N-2) + a**(N-2) * b**N))
n = (a+b+c)/(1-c)
print(int(round(n*p*1000000000)))

Submission status: Runtime Error

Solution code:
# coding: utf-8
# Your code here!
import math
N, A, B, C = map(int,input().split())

A/=100
B/=100
C/=100

a = (N/(A/(A+B))+N)/2
b=0
if(b!=0):
    b=(N/(B/(A+B))+N)/2
    ans = math.ceil(a+b)//2
else:
    ans = math.ceil(a)
ans += math.ceil(C/N)

print(ans%(10**9+7))

Submission status: Runtime Error

Solution code:
n, a, b, c = map(int, input().split(' '))
import math
def permutations_count(n, r):
  return math.factorial(n) // math.factorial(n - r)

def reduce(p, q):
  p, q = int(p), int(q)
  common = math.gcd(p, q)
  return (p // common, q // common)

def lcm(x, y):
    return (x * y) // math.gcd(x, y)

if a >= 100 or b >= 100:
  ans = n
elif c <= 0:
  p = n*permutations_count(n, 0)
  q = 2**(n-1)
  p, q = reduce(p,q)
  for i in range(n+1, 2*n):
    perm = permutations_count(n, i-n)
    fr = i*perm
    ac = 2**(i-1)
    fr, ac = reduce(fr, ac)
    l = lcm(q, ac)
    if q <= ac:
      p *= l // q
      q = l
    else:
      fr *= l // ac
      ac = l
    p += fr
    p, q = reduce(p,q)
  p, q = reduce(p, q)
  i = 0
  m = 10**9+7
  while True:
    r = (p + i*m)/q
    print(r)
    if r == int(r):
      ans = int(r)
      break
    i += 1
print(ans)

Submission status: Runtime Error

Solution code:
from scipy.special import comb

N, A, B, C = map(int, input().split())
A /= 100
B /= 100
ans = 0

for i in range(100):
    ans += comb(N + i - 1, i) * (N * i) * (A ** N * (1 - A) ** i + B ** N * (1 - B) ** i)
print(ans)

Submission status: Runtime Error

Solution code:
N, A, B, C = map(int, input().split())
MOD = 10 ** 9 + 7

def dp(a, b):
  if a == N or b == N:
    return (a + b) * 100 ** (2 * N - 1 - (a + b))

  return A * dp(a + 1, b) + B * dp(a, b + 1) 

if C == 0 and (A == 0 or B == 0):
  print(N)
else:
  P = dp(0, 0)
  Q = 100 ** (2 * N - 1)
  if C != 0:
    P *= 100
    Q *= C
  
  print(int(P / Q) % MOD + 1)

Submission status: Runtime Error

Solution code:
N, A, B, C = map(int, input().split())
MOD = 10 ** 9 + 7

def dp(a, b):
  if a == N or b == N:
    return (a + b) * 100 ** (2 * N - 1 - (a + b))

  return A * dp(a + 1, b) + B * dp(a, b + 1) 

if C == 0 and (A == 0 or B == 0):
  print(N)
else:
  P = dp(0, 0)
  Q = 100 ** (2 * N - 1)
  if C != 0:
    P *= 100
    Q *= C
  
  print(int(P / Q) % MOD)

Submission status: Runtime Error

Solution code:
import math
n, a, b, c = map(int,input().split())
prob=(a+b)/100.0
answer = math.floor(1/(1-prob))

print(n*int(answer))

Submission status: Runtime Error

Solution code:
d

Submission status: Runtime Error

Solution code:
import math
n, a, b, c = map(int,input().split())
prob=(a)/100.0
answer = math.floor(1/(1-prob))

print(n*int(answer))

Submission status: Runtime Error

Solution code:
import math
n, a, b, c = map(int,input().split())
prob=(a)/100.0
answer = math.floor(1/(1-prob))

print(answer)

Submission status: Runtime Error

Solution code:
n, a, b, c = map(int, input().split())
ans = 0
i = 1
k = 1
while:
  ans += (a+b)*k*i
  k = k * c
  if i == 2*n-1:
    break
print(ans)

Submission status: Runtime Error

Solution code:
n, a, b, c = map(int, input().split())

print(100*n*(a+b)/(a*b))