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: Wrong Answer

Solution code:
mod = 10**9+7
rng = 200100
fctr = [1]
finv = [1]
for i in range(1,rng):
  fctr.append(fctr[-1]*i%mod)
for i in range(1,rng):
  finv.append(pow(fctr[i],mod-2,mod))
def cmb(n,k):
  if n<0 or k<0:
    return 0
  else:
    return fctr[n]*finv[n-k]*finv[k]%mod
def inv(x):
  return pow(x,mod-2,mod)

n,a,b,c = map(int,input().split())
num = 0
for i in range(n):
  num = (num+(i+n)*cmb(n-1+i,i)*pow(a+b,n-i,mod)*(inv(pow(a,n-i,mod))+inv(pow(b,n-i,mod))))%mod
ans = num*inv(pow(a+b,2*n,mod))*pow(a,n,mod)*pow(b,n,mod)*100*inv(100-c)%mod
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
mod=10**9+7
n_max=2*10**5
F,FI=[0]*(n_max+1),[0]*(n_max+1)
F[0],FI[0]=1,1
for i in range(n_max):
  F[i+1]=(F[i]*(i+1))%mod
  FI[i+1]=pow(F[i+1],mod-2,mod)
def comb(x,y):
  return (F[x]*FI[x-y]*FI[y])%mod
n,a,b,c=map(int,input().split())
ans=0
aa,bb=a*pow(100,mod-2,mod),b*pow(100,mod-2,mod)
an,bn=pow(aa,n,mod),pow(bb,n,mod)
for i in range(n):
  ans+=(n+i)*(an*pow(bb,i,mod)+pow(aa,i,mod)*bn)*comb(n+i-1,i)
  ans%=mod
print((ans*100*pow(100-c,mod-2,mod))%mod)

Submission status: Wrong Answer

Solution code:
s = input()

if s.count('x') < 8:
    print('YES')
else:
    print('NO')

Submission status: Wrong Answer

Solution code:
def inpl(): return list(map(int, input().split()))
N, A, B, C = inpl()

MOD = 10**9 + 7
def cmb(n, r, mod):
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % mod

size = 2*100000 + 1
g1, g2, inverse = [0]*size, [0]*size, [0]*size

g1[:2] = [1, 1] # 元テーブル
g2[:2] = [1, 1] #逆元テーブル
inverse[:2] = [0, 1] #逆元テーブル計算用テーブル
 
for i in range(2, size):
    g1[i] =  ( g1[i-1] * i ) % MOD 
    inverse[i] = (-inverse[MOD % i] * (MOD//i) ) % MOD 
    g2[i] =  (g2[i-1] * inverse[i]) % MOD

P = 0
Q = pow(100-C, 2*N, MOD)*(100-C)%MOD

for x in range(N):
    P = (P + cmb(N+x-1, x, MOD) * (N+x) * pow(100-C, N-x, MOD) * (pow(inverse[A], N-x, MOD) + pow(inverse[B], N-x, MOD)))%MOD
P = P*100*pow(A, N, MOD)*pow(B, N, MOD)%MOD

print(P*pow(Q, MOD-2, MOD)%MOD)

Submission status: Wrong Answer

Solution code:
m = 10**9+7
def inv(x):
  m = 10**9+7
  t = x
  y = 1
  while True:
    if t == 1:
      break
    y *= m // t
    t = m % t
    y *= -1
    y %= m
  return y
import math
def cc(x,y):
  return math.factorial(x) // math.factorial(y) // math.factorial(x-y) % m
n,a,b,c = map(int,input().split())
d = 100 - c
awin = a * inv(d)
bwin = b * inv(d)
asc = 0
bsc = 0
for i in range(n):
  p = cc(n-1+i,i) * awin**(n-1) * bwin**i * (n+i)
  asc += p
  asc %= m
for i in range(n):
  p = cc(n-1+i,i) * awin**i * bwin**(n-1) * (n+i)
  bsc += p
  bsc %= m
sc = asc * awin + bsc * bwin
sc %= m
scn = sc * 100 * inv(d)
scn %= m
print(asc,bsc,scn)

Submission status: Wrong Answer

Solution code:
import math

N, A, B, C = map(int,input().split())
mod = 10**9+7

def cmb(n, r, mod):
    if (r < 0 or r > n):
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % mod

g1 = [1, 1]
g2 = [1, 1]
inv = [0, 1] 
for i in range(2, 2*10**5+1):
    g1.append((g1[-1] * i) % mod)
    inv.append((-inv[mod % i] * (mod//i)) % mod)
    g2.append((g2[-1] * inv[-1]) % mod)

def g(a):
    b, u, v = mod, 1,0
    while b:
        t = a//b
        a -= t * b
        u -= t * v
        a,b,u,v = b,a,v,u
        u %= mod
    return u if u > 0 else u + mod

p1,p2 = A * g(A + B) % mod, B * g(A + B) % mod
p3 = (100 - C) * g(100) % mod

ans = 0
for i in range(N):
    ans += (N+i)*cmb(N+i-1,i,mod)*(pow(p1,N,mod) * pow(p2,i,mod) + pow(p2,i,mod) * pow(p2,N,mod))
    ans %= mod
ans = ans * g(p3) % mod
print(ans)

Submission status: Wrong Answer

Solution code:
import math

N, A, B, C = map(int,input().split())
mod = 10**9+7

def cmb(n, r, mod):
    if (r < 0 or r > n):
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % mod

g1 = [1, 1]
g2 = [1, 1]
inv = [0, 1] 
for i in range(2, 2*10**5+1):
    g1.append((g1[-1] * i) % mod)
    inv.append((-inv[mod % i] * (mod//i)) % mod)
    g2.append((g2[-1] * inv[-1]) % mod)

def g(a):
    b, u, v = mod, 1,0
    while b:
        t = a//b
        a -= t * b
        u -= t * v
        a,b,u,v = b,a,v,u
        u %= mod
    return u if u > 0 else u + mod

p1,p2 = A * g(A + B) % mod, B * g(A + B) % mod
p3 = (100 - C) * g(100) % mod

ans = 0
for i in range(N):
    ans += (N+i)*cmb(N+i-1,i,mod)% mod*(pow(p1,N,mod) * pow(p2,i,mod) % mod + pow(p2,i,mod) * pow(p2,N,mod) % mod)% mod
    ans %= mod
ans = ans * g(p3) % mod
print(ans)

Submission status: Wrong Answer

Solution code:
# WARN: Require mod number m is prime number
class ModComb:
    # For nCr mod m
    def __init__(self, n_max, m):
        self._n_max = n_max
        self._m = m
        self._mod_facts = [1] * (n_max+1)       # list of n! mod m
        self._mod_inv_facts = [1] * (n_max+1)   # list of inverse r! mod m

        if not m >= 3:
            raise ValueError('Require mod number m >= 3')

        # Calc n_max! mod m
        for i in range(2, n_max+1):
            self._mod_facts[i] = self._mod_facts[i-1] * i % m

        # Calc inverse r! mod m
        self._mod_inv_facts[n_max] = pow(self._mod_facts[n_max], m-2, m)
        for i in range(n_max-1, 1, -1):
            self._mod_inv_facts[i] = self._mod_inv_facts[i+1] * (i+1) % m

    def calc(self, n, r):
        # Return nCr mod m
        if n > self._n_max:
            raise Exception('n is larger than n_max')

        if r == 0:
            return 1

        m = self._m
        return self._mod_facts[n] * self._mod_inv_facts[r] * self._mod_inv_facts[n-r] % m


# n^p % mod
def modPower(mod, n, p):
    ret = 1
    for i in range(p):
        ret = ret*n % mod
    return ret


# Expected value of the number of all games when M-th non-even game occurs
def expectedGameNum(mod, C, M):
    return M*100*pow(100-C, mod-2, mod) % mod


# Probability of ending game when M-th non-even game occurs
def probEndGame(mod, modcomb, A, B, M, N):
    winA = modcomb.calc(M-1, N-1) * \
            (modPower(mod, A, N) * pow(modPower(mod, 100, N), mod-2, mod) % mod) * \
            (modPower(mod, B, M-N) * pow(modPower(mod, 100, M-N), mod-2, mod) % mod) % mod
    winB = modcomb.calc(M-1, N-1) * \
            (modPower(mod, B, N) * pow(modPower(mod, 100, N), mod-2, mod) % mod) * \
            (modPower(mod, A, M-N) * pow(modPower(mod, 100, M-N), mod-2, mod) % mod) % mod
    return (winA + winB) % mod

def main():
    MOD = 10**9+7
    N, A, B, C = map(int, input().split())
    N_MAX = 100000
    modcomb = ModComb(N_MAX*2, MOD)
    denomi100minusC = pow(100-C, MOD-2, MOD)
    modpowerA = [1] * (N+1)
    for i in range(1, N+1):
        modpowerA[i] = modpowerA[i-1] * A % MOD
    modpowerB = [1] * (N+1)
    for i in range(1, N+1):
        modpowerB[i] = modpowerB[i-1] * B % MOD
    modpower100 = [1] * (N+1)
    for i in range(1, N+1):
        modpower100[i] = modpower100[i-1] * 100 % MOD
    ans = 0
    for i in range(N, 2*N):
        prob_winA = modcomb.calc(i-1, N-1) * \
                (modpowerA[N] * pow(modpower100[N], MOD-2, MOD) % MOD) * \
                (modpowerB[i-N] * pow(modpower100[i-N], MOD-2, MOD) % MOD) % MOD
        prob_winB = modcomb.calc(i-1, N-1) * \
                (modpowerB[N] * pow(modpower100[N], MOD-2, MOD) % MOD) * \
                (modpowerA[i-N] * pow(modpower100[i-N], MOD-2, MOD) % MOD) % MOD
        prob_end_game = (prob_winA + prob_winB) % MOD
        ans += i*100*denomi100minusC % MOD * prob_end_game
        ans %= MOD
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
# WARN: Require mod number m is prime number
class ModComb:
    # For nCr mod m
    def __init__(self, n_max, m):
        self._n_max = n_max
        self._m = m
        self._mod_facts = [1] * (n_max+1)       # list of n! mod m
        self._mod_inv_facts = [1] * (n_max+1)   # list of inverse r! mod m

        if not m >= 3:
            raise ValueError('Require mod number m >= 3')

        # Calc n_max! mod m
        for i in range(2, n_max+1):
            self._mod_facts[i] = self._mod_facts[i-1] * i % m

        # Calc inverse r! mod m
        self._mod_inv_facts[n_max] = pow(self._mod_facts[n_max], m-2, m)
        for i in range(n_max-1, 1, -1):
            self._mod_inv_facts[i] = self._mod_inv_facts[i+1] * (i+1) % m

    def calc(self, n, r):
        # Return nCr mod m
        if n > self._n_max:
            raise Exception('n is larger than n_max')

        if r == 0:
            return 1

        m = self._m
        return self._mod_facts[n] * self._mod_inv_facts[r] * self._mod_inv_facts[n-r] % m


# n^p % mod
def modPower(mod, n, p):
    ret = 1
    for i in range(p):
        ret = ret*n % mod
    return ret


# Expected value of the number of all games when M-th non-even game occurs
def expectedGameNum(mod, C, M):
    return M*100*pow(100-C, mod-2, mod) % mod


# Probability of ending game when M-th non-even game occurs
def probEndGame(mod, modcomb, A, B, M, N):
    winA = modcomb.calc(M-1, N-1) * \
            (modPower(mod, A, N) * pow(modPower(mod, 100, N), mod-2, mod) % mod) * \
            (modPower(mod, B, M-N) * pow(modPower(mod, 100, M-N), mod-2, mod) % mod) % mod
    winB = modcomb.calc(M-1, N-1) * \
            (modPower(mod, B, N) * pow(modPower(mod, 100, N), mod-2, mod) % mod) * \
            (modPower(mod, A, M-N) * pow(modPower(mod, 100, M-N), mod-2, mod) % mod) % mod
    return (winA + winB) % mod

def main():
    MOD = 10**9+7
    N, A, B, C = map(int, input().split())
    N_MAX = 100000
    modcomb = ModComb(N_MAX*2, MOD)
    denomi100minusC = pow(100-C, MOD-2, MOD)
    ans = 0
    for i in range(N, 2*N):
        ans += i*100*denomi100minusC % MOD * probEndGame(MOD, modcomb, A, B, i, N) % MOD
        ans %= MOD
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
# WARN: Require mod number m is prime number
class ModComb:
    # For nCr mod m
    def __init__(self, n_max, m):
        self._n_max = n_max
        self._m = m
        self._mod_facts = [1] * (n_max+1)       # list of n! mod m
        self._mod_inv_facts = [1] * (n_max+1)   # list of inverse r! mod m

        if not m >= 3:
            raise ValueError('Require mod number m >= 3')

        # Calc n_max! mod m
        for i in range(2, n_max+1):
            self._mod_facts[i] = self._mod_facts[i-1] * i % m

        # Calc inverse r! mod m
        self._mod_inv_facts[n_max] = pow(self._mod_facts[n_max], m-2, m)
        for i in range(n_max-1, 1, -1):
            self._mod_inv_facts[i] = self._mod_inv_facts[i+1] * (i+1) % m

    def calc(self, n, r):
        # Return nCr mod m
        if n > self._n_max:
            raise Exception('n is larger than n_max')

        if r == 0:
            return 1

        m = self._m
        return self._mod_facts[n] * self._mod_inv_facts[r] * self._mod_inv_facts[n-r] % m


# n^p % mod
def modPower(mod, n, p):
    ret = 1
    for i in range(p):
        ret = ret*n % mod
    return ret


# Expected value of the number of all games when M-th non-even game occurs
def expectedGameNum(mod, C, M):
    return M*100*pow(100-C, mod-2, mod) % mod


# Probability of ending game when M-th non-even game occurs
def probEndGame(mod, modcomb, A, B, M, N):
    winA = modcomb.calc(M-1, N-1) * \
            (modPower(mod, A, N) * pow(modPower(mod, 100, N), mod-2, mod) % mod) * \
            (modPower(mod, B, M-N) * pow(modPower(mod, 100, M-N), mod-2, mod) % mod) % mod
    winB = modcomb.calc(M-1, N-1) * \
            (modPower(mod, B, N) * pow(modPower(mod, 100, N), mod-2, mod) % mod) * \
            (modPower(mod, A, M-N) * pow(modPower(mod, 100, M-N), mod-2, mod) % mod) % mod
    return (winA + winB) % mod

def main():
    MOD = 10**9+7
    N, A, B, C = map(int, input().split())
    N_MAX = 100000
    modcomb = ModComb(N_MAX*2, MOD)
    ans = 0
    for i in range(N, 2*N):
        ans += expectedGameNum(MOD, C, i) * probEndGame(MOD, modcomb, A, B, i, N) % MOD
        ans %= MOD
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
###template###
import sys
def input(): return sys.stdin.readline().rstrip()
def mi(): return map(int, input().split())
###template###
import time

# 拡張ユークリッド互除法
# ax + by = gcd(a,b)の最小整数解を返す
def egcd(a, b):
    if a == 0:
        return (b, 0, 1)
    else:
        g, y, x = egcd(b % a, a)
        return (g, x - (b // a) * y, y)

# mを法とするaの乗法的逆元
def modinv(a, m):
    g, x, y = egcd(a, m)
    if g != 1:
        raise Exception('modular inverse does not exist')
    else:
        return x % m

N, A, B, C = mi()

MOD = 10**9+7
a = (A * modinv(A+B, MOD)) % MOD
b = (B * modinv(A+B, MOD)) % MOD
gyakugenofAB = (100 * modinv(A+B, MOD)) % MOD

# 累乗を返すリスト
#[0]行にはaの階乗を、[1]行にはbの階乗を入れる
powlist = [[-1] * (N+1) for _ in range(2)]
preA = 1
preB = 1
powlist[0][0] = 1
powlist[1][0] = 1
for i in range(1,N+1):
  preA = (preA * a) % MOD
  preB = (preB * b) % MOD
  powlist[0][i] = preA
  powlist[1][i] = preB


#cmb(m)でmCn-1を計算
import math
Nmin1fct = modinv(math.factorial(N-1),MOD) % MOD

#一度でも計算したらflagがオン
flag = 0
preans = 1
def cmb(k):
  global flag
  global preans
  ans = 1
  if flag == 0:
    flag = 1
    for i in range(max(1,k-1),k-N,-1):
      ans = (ans * i) % MOD
    preans = (ans * Nmin1fct) % MOD
    return preans
  else:
    preans = round(preans * (k-1) / max(1, k-N)) % MOD
  return preans
#cmbの計算終わり


#期待値（確率×回数）を足し上げていく。
#N回目～2N-1回目についてループを回す
#m-1Cn-1なことに注意
e = 0
cnt = 0
for m in range(N, 2*N):
#  cnt += 1
#  if cnt % 1000 == 0: print(cnt)
#  start_time = time.perf_counter()
  e += (m * gyakugenofAB * (cmb(m) % MOD) * ((powlist[0][N] * powlist[1][m-N]) + (powlist[0][m-N] * powlist[1][N])))
  e %= MOD
#  print(time.perf_counter() - start_time)


print(e)

Submission status: Wrong Answer

Solution code:
###template###
import sys
def input(): return sys.stdin.readline().rstrip()
def mi(): return map(int, input().split())
###template###
import time

# 拡張ユークリッド互除法
# ax + by = gcd(a,b)の最小整数解を返す
def egcd(a, b):
    if a == 0:
        return (b, 0, 1)
    else:
        g, y, x = egcd(b % a, a)
        return (g, x - (b // a) * y, y)

# mを法とするaの乗法的逆元
def modinv(a, m):
    g, x, y = egcd(a, m)
    if g != 1:
        raise Exception('modular inverse does not exist')
    else:
        return x % m

N, A, B, C = mi()

MOD = 10**9+7
a = (A * modinv(A+B, MOD)) % MOD
b = (B * modinv(A+B, MOD)) % MOD
gyakugenofAB = 100 * modinv(A+B, MOD)

# 累乗を返すリスト
#[0]行にはaの階乗を、[1]行にはbの階乗を入れる
powlist = [[-1] * (N+1) for _ in range(2)]
preA = 1
preB = 1
powlist[0][0] = 1
powlist[1][0] = 1
for i in range(1,N+1):
  preA = (preA * a) % MOD
  preB = (preB * b) % MOD
  powlist[0][i] = preA
  powlist[1][i] = preB


#cmb(m)でmCn-1を計算
import math
Nmin1fct = math.factorial(N-1) % MOD
#一度でも計算したらflagがオン
flag = 0
preans = 0
def cmb(k):
  global flag
  global preans
  ans = 1
  if flag == 0:
    flag = 1
    for i in range(max(1,k-1),k-N,-1):
      ans = (ans * i) % MOD
    preans = round(ans / Nmin1fct) % MOD
    return preans
  else:
    preans = round(preans * (k-1) / max(1, k-N)) % MOD
  return preans
#cmbの計算終わり

#期待値（確率×回数）を足し上げていく。
#N回目～2N-1回目についてループを回す
#m-1Cn-1なことに注意
e = 0
cnt = 0
for m in range(N, 2*N):
#  cnt += 1
#  if cnt % 1000 == 0: print(cnt)
#  start_time = time.perf_counter()
  e += (m * gyakugenofAB * (cmb(m) % MOD) * ((powlist[0][N] * powlist[1][m-N]) + (powlist[0][m-N] * powlist[1][N])))
  e %= MOD
#  print(time.perf_counter() - start_time)


print(e)

Submission status: Wrong Answer

Solution code:
m = 10**9+7
def inv(x):
  m = 10**9+7
  t = x
  y = 1
  while True:
    if t == 1:
      break
    y *= m // t
    t = m % t
    y *= -1
    y %= m
  return y
import math
def cc(x,y):
  return math.factorial(x) // math.factorial(y) // math.factorial(x-y)
n,a,b,c = map(int,input().split())
d = 100 - c
awin = a * inv(d)
bwin = b * inv(d)
asc = 0
bsc = 0
for i in range(n):
  p = cc(n-1,i) * awin**(n-1) * bwin**i
  asc += p
  asc %= m
for i in range(n):
  p = cc(n-1,i) * awin**i * bwin**(n-1)
  bsc += p
  bsc %= m
sc = asc * awin + bsc * bwin
sc %= m
scn = sc * 100 * inv(d)
scn %= m
print(scn)

Submission status: Wrong Answer

Solution code:
N,A,B,C=map(int, raw_input().split())

mod=10**9+7
fact, inv_fact = [1], [1]
fact_tmp = 1
for i in range(1, 2*N):
	fact_tmp *= i
	fact_tmp %= mod
	fact.append(fact_tmp)
	inv_fact.append(pow(fact_tmp, mod-2, mod))
 
def ncr(n,r):
	if n < 0 or r < 0 or n < r:	return 0
	else:	return (fact[n] * inv_fact[r] * inv_fact[n-r]) %mod


P=0
for g in range(N, 2*N):
	P+= pow(100, (2*N-1-g) , mod) * g*pow(A,N,mod)* pow(B,g-N,mod) *ncr(g-1,(N-1))
	P+=pow(100, (2*N-1-g) ,mod) * g*pow(A,g-N,mod) * pow(B,N,mod) *ncr(g-1,(N-1))

Q=pow( 100 , 2*N-1 ,mod)

if C>0: P,Q=Q,P
print ( P*pow(Q, mod-2 , mod) ) % mod

Submission status: Wrong Answer

Solution code:
n, a, b, c = [int(i) for i in input().split()]
p = 10 ** 9 + 7

ans = 0

def fact(n, p=10**9 + 7):
    f = [1]
    for i in range(1, n+1):
        f.append(f[-1]*i%p)
    return f

def invfact(n, f, p=10**9 + 7):
    inv = [pow(f[n], p-2, p)]
    for i in range(n, 0, -1):
        inv.append(inv[-1]*i%p)
    return inv[::-1]

f = fact(2 * n)
invf = invfact(2 * n, f)

def comb(a, b):
    if a < b:
        return 0
    if a < 0 or b < 0:
        return 0
    return f[a] * invf[b] * invf[a-b] % p

pow_a = [1]
pow_b = [1]
inv_100 = pow(100, p - 2, p)
a = a * inv_100 % p
b = b * inv_100 % p
c = c * inv_100 % p

for i in range(n):
    pow_a.append(pow_a[-1] * a % p)
    pow_b.append(pow_b[-1] * b % p)

for m in range(n, 2 * n):
    ans += comb(m - 1, n - 1) * (pow_a[n] * pow_b[m - n] + pow_a[m - n] * pow_b[n]) * m
    ans %= p

ans *= pow(1 - c, p - 2, p)

print(ans % p)

Submission status: Wrong Answer

Solution code:
###template###
import sys
def input(): return sys.stdin.readline().rstrip()
def mi(): return map(int, input().split())
###template###

#cmb(n, r)でnCrを計算
def cmb(n, r):
    if n - r < r: r = n - r
    if r == 0: return 1
    if r == 1: return n

    numerator = [n - r + k + 1 for k in range(r)]
    denominator = [k + 1 for k in range(r)]

    for p in range(2,r+1):
        pivot = denominator[p - 1]
        if pivot > 1:
            offset = (n - r) % p
            for k in range(p-1,r,p):
                numerator[k - offset] /= pivot
                denominator[k] /= pivot

    result = 1
    for k in range(r):
        if numerator[k] > 1:
            result *= int(numerator[k])

    return result
#cmbの計算終わり

# 拡張ユークリッド互除法
# ax + by = gcd(a,b)の最小整数解を返す
def egcd(a, b):
    if a == 0:
        return (b, 0, 1)
    else:
        g, y, x = egcd(b % a, a)
        return (g, x - (b // a) * y, y)


# mを法とするaの乗法的逆元
def modinv(a, m):
    g, x, y = egcd(a, m)
    if g != 1:
        raise Exception('modular inverse does not exist')
    else:
        return x % m

N, A, B, C = mi()

MOD = 10**9+7
a = A * modinv(A+B, MOD)
b = B * modinv(A+B, MOD)
gyakugenofAB = 100 * modinv(A+B, MOD)

# 累乗を返す sは'a'or'b'(文字列)
#[0]行にはaの階乗を、[1]行にはbの階乗を入れる
powlist = [[0 for _ in range(N+1)] for _ in range(2)]
def calcpow(s, r):
  if s == 'a':
    i = 0
    num = a
  else:
    i = 1
    num = b
  tmp = powlist[i][r]
  if tmp == 0:
    tmp = (num**r)
    powlist[i][r] = tmp
    return tmp
  else:
    return tmp


#期待値（確率×回数）を足し上げていく。
#N回目～2N-1回目についてループを回す
#m-1Cn-1なことに注意
e = 0
for m in range(N, 2*N):
  e += (m * gyakugenofAB * (cmb(m-1, N-1) % MOD) * (((calcpow(a,N) % MOD) * (calcpow(b,m-N) % MOD)) + ((calcpow(a,m-N) % MOD) * (calcpow(b,N) % MOD)))) % MOD
  e %= MOD

print(e)

Submission status: Wrong Answer

Solution code:
def gcd(a, b):
    if b == 0:
        return a
    else:
        return gcd(b, a % b)

def opt(a, b):
    c = gcd(a, b)
    return a//c, b//c

def dot(A, B):
    a = A[0] * B[0]
    b = A[1] * B[1]
    return opt(a, b)

def add(A, B):
    return opt(A[0]*B[1] + B[0]*A[1], A[1] * B[1])

N, A, B, C = map(int, input().split())

A = opt(A, 100)
B = opt(B, 100)
C = opt(C, 100)

g = 1000000007

c = [((1, 1), 0, 0, 0)]
ans = (0, 1)
e = (0, 1)
pi = 0
while pi < len(c):

    PQ, cnt, acnt, bcnt = c[pi]
    pi += 1

    if e[1] > (e[1] - e[0]) * g * 1000:
        continue
    if acnt >= N or bcnt >= N:
        e = add(e, PQ)
        ans = add(ans, opt(cnt * PQ[0], PQ[1]))
        continue

    cnt += 1
    c.append((dot(PQ, A), cnt, acnt+1, bcnt))
    c.append((dot(PQ, B), cnt, acnt, bcnt+1))
    c.append((dot(PQ, C), cnt, acnt, bcnt))


print(ans[0] * pow(ans[1], g-2,g)%g)

Submission status: Wrong Answer

Solution code:
def gcd(a, b):
    if b == 0:
        return a
    else:
        return gcd(b, a % b)

def opt(a, b):
    c = gcd(a, b)
    return a//c, b//c

def dot(A, B):
    a = A[0] * B[0]
    b = A[1] * B[1]
    return opt(a, b)

def add(A, B):
    return opt(A[0]*B[1] + B[0]*A[1], A[1] * B[1])

N, A, B, C = map(int, input().split())

A = opt(A, 100)
B = opt(B, 100)
C = opt(C, 100)

g = 1000000007

c = [((1, 1), 0, 0, 0)]
ans = (0, 1)
e = (0, 1)
pi = 0
while pi < len(c):

    PQ, cnt, acnt, bcnt = c[pi]
    pi += 1

    if e[1] > (e[1] - e[0]) * g * 10:
        continue
    if acnt >= N or bcnt >= N:
        e = add(e, PQ)
        ans = add(ans, opt(cnt * PQ[0], PQ[1]))
        continue

    cnt += 1
    c.append((dot(PQ, A), cnt, acnt+1, bcnt))
    c.append((dot(PQ, B), cnt, acnt, bcnt+1))
    c.append((dot(PQ, C), cnt, acnt, bcnt))


print(ans[0] * pow(ans[1], g-2,g)%g)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

from fractions import Fraction

N, A, B, C = list(map(int, input().split()))

PRIME = 10**9 + 7
MAX = 2 * N

fac = [0]*MAX
finv = [0]*MAX

def invMod(a, m):
    b, x, y = m, 1, 0
    while b:
        t = a // b
        a -= t * b
        a, b = b, a
        x -= t * y
        x, y = y, x
    return x % m

def binomInit():
    fac[0] = fac[1] = 1
    finv[0] = finv[1] = 1
    for i in range(2, MAX):
        fac[i] = (fac[i-1]*i) % PRIME
        finv[i] = (finv[i-1]*invMod(i, PRIME)) % PRIME

def binom(n, k):
    if n < 0 or k < 0 or n < k:
        return 0
    return (fac[n] * finv[k] * finv[n - k]) % PRIME

binomInit()

powerA = [A**i % PRIME for i in range(N+1)]
powerB = [B**i % PRIME for i in range(N+1)]

p = 0
q = 100**MAX * (100-C)

for M in range(N, MAX):
    p += ((100**(MAX-M+1))*(M*binom(M-1, N-1)*(powerA[N]*powerB[M-N] + powerA[M-N]*powerB[N]))) % PRIME

print((p * invMod(q, PRIME)) % PRIME)

Submission status: Wrong Answer

Solution code:
n,a,b,c=(int(i) for i in input().split())
a=a/100
b=b/100
def bitsu(n):
  r=1
  for i in range(n):
    r=r*(i+1)
  return r
def comb(n,k):
  return bitsu(n)/(bitsu(k)*bitsu(n-k))
def pos(a,b,k): #k回目で終わる確率
  return (a**n)*(b**(k-n))*comb(n,k)+(a**(k-n))*(b**n)*comb(n,k)
r=0
for i in(n,2*n-1):
  r=r+i*pos(a,b,i)
print(r)

Submission status: Wrong Answer

Solution code:
def getInv(N):#Qはmod
    inv = [0] * (N + 1)
    inv[0] = 1
    inv[1] = 1
    for i in range(2, N + 1):
        inv[i] = (-(Q // i) * inv[Q%i]) % Q
    return inv

Q = 10**9+7
N, A, B, C = map( int, input().split())
modinv = getInv( max(2*N-1, 100))
a = A*modinv[100]%Q
b = B*modinv[100]%Q
Powa = [1]*(N+1)
Powb = [1]*(N+1)
for i in range(N):
    Powa[i+1] = (Powa[i]*a)%Q
    Powb[i+1] = (Powb[i]*b)%Q
t = 100*modinv[100-C]%Q
ans = 0
nowc = 1
ans = Powa[N]*N + Powb[N]*N
ans %= Q
for k in range(N+1, N*2):
    nowc *= (k-1)*modinv[k-N]
    nowc %= Q
    ans += nowc*( Powa[N]*Powb[k-N] + Powb[N]*Powa[k-N])%Q*k%Q
    ans %= Q
print(ans*t%Q)

Submission status: Wrong Answer

Solution code:
import numpy as np
from collections import defaultdict
from functools import reduce

import numpy as np
MOD = 1000000007

def mod_add(a, b):
  return (a+b)%MOD

def mod_sub(a, b):
  return (a+MOD-b)%MOD

def mod_mul(a, b):
  return (a*b)%MOD

#互いに素なa,bについて、a*x+b*y=1の一つの解
def extgcd(a,b):
    r = (1,0,a)
    w = (0,1,b)
    while w[2]!=1:
        q = r[2]//w[2]
        r2 = w
        w2 = [r[0]-q*w[0],r[1]-q*w[1],r[2]-q*w[2]]
        r = r2
        w = w2
    return w[0], w[1]

def mod_inv(a):
    x, _  = extgcd(a, MOD)
    return (MOD+x%MOD)%MOD

def mod_div(a, b):
    return a*mod_inv(b)%MOD

def mod_pow(a, b):
    res = 1
    while b > 0:
        if b & 1:
            res = res * a * MOD
        a = a * a % MOD
        b >>= 1
    return res

MAX = 200010

fac  = [1,1]
finv = [1,1]
inv  = [1,1]

def COMinit():
    # fac[0] = fac[1] = 1
    # finv[0] = finv[1] = 1
    # inv[1] = 1
    for i in range(2, MAX):
        fac.append(fac[i - 1] * i % MOD)
        inv.append(MOD - inv[MOD%i] * (MOD / i) % MOD)
        finv.append(finv[i - 1] * inv[i] % MOD)

def mod_COM(n, k):
    if n < k:
        return 0
    if n < 0 or k < 0:
        return 0
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;


# s = input()
# n = int(input())
COMinit()
N, A, B, C = list(map(int, input().split()))

a = mod_div(A, 100)
b = mod_div(B, 100)
c = mod_div(C, 100)

k_factor_memo = {}
def k_factor(M):
    if M in k_factor_memo:
        return k_factor_memo[M]
    if C == 100-C:
        res = fac[M+1]

        res = mod_div(res, mod_sub(1,c))
        k_factor_memo[M] = res
        return res
    res = mod_mul(fac[M], mod_div(c, mod_sub(1, mod_mul(2,c))))
    c2 = mod_div(c, mod_sub(1, c))
    c2 = pow(c2, M, MOD)
    c2 = mod_sub(c2, 1)
    res = mod_mul(res, c2)
    res = mod_div(res, mod_sub(1,c))
    k_factor_memo[M] = res
    return res

res = 0
an = pow(a, N, MOD)

for j in range(N):
    tmp = mod_mul(mod_mul(N, finv[N]), finv[j])
    # print(tmp)
    tmp = mod_mul(tmp, an)
    # print(tmp)
    tmp = mod_mul(tmp, pow(b, j, MOD))
    # print(tmp)
    tmp = mod_mul(tmp, k_factor(N+j))
    # print(tmp)
    res = mod_add(res, tmp)
# print(res)

bn = pow(b, N, MOD)
for j in range(N):
    tmp = mod_mul(mod_mul(N, finv[N]), finv[j])
    tmp = mod_mul(tmp, bn)
    tmp = mod_mul(tmp, pow(a, j, MOD))
    tmp = mod_mul(tmp, k_factor(N+j))
    res = mod_add(res, tmp)

print(res)

Submission status: Wrong Answer

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

W = [1] * (2 * N + 1)
for w in range(2 * N):
    W[w + 1] = ((w + 1) * W[w]) % mod


def rev(a, mod):
    return pow(a, mod - 2, mod)


def comb(a, b):
    return (W[a] * rev(W[b], mod) * rev(W[a - b], mod)) % mod


def f(a, b, c):
    res = 0
    for i in range(N):
        res += ((i + N) * com[i] * pow(b, i, mod)) % mod
        res %= mod
    return (pow(a, N, mod) * res * pow(100 * rev(100 - C, mod), 2, mod)) % mod


a = A * rev(100, mod)
b = B * rev(100, mod)
c = C * rev(100, mod)
com = [comb(i + N - 1, i) for i in range(N)]

w_a = f(a, b, c)
w_b = f(b, a, c)
ans = (w_a + w_b) % mod
print(ans)

Submission status: Wrong Answer

Solution code:
N,A,B,C = map(int, input().split())

mod = 10**9+7
n = 100*N
d = A+B


def modinv(a,p):
    b = p
    u = 1
    v = 0
    while b:
        t = a//b
        a -= t*b
        a,b = b,a
        u -= t*v
        t,v=v,u
    u %= p
    if u < 0:
        u += p
    return u

n %= mod
print(n*modinv(d,mod)%mod)

Submission status: Wrong Answer

Solution code:
mod=10**9+7
n,a,b,c=map(int,input().split())
import math
def com(x,y):
  return math.factorial(x)/math.factorial(y)/math.factorial(x-y)
aa=a/(a+b)
bb=b/(a+b)
ex=0
for i in range(n):
  ex+=(n+i)*com(n+i,n)*pow(aa,n)*pow(bb,i)
  ex+=(n+i)*com(n+i,n)*pow(bb,n)*pow(aa,i)
if c!=0:
  ex*=(100/c)
print(int(ex)%mod)

Submission status: Wrong Answer

Solution code:
n, a, b, c = map(int,input().split())
def gcd(a, b):
  a1 = a
  b1 = b
  while a>0 and b>0:
    a, b = b, a%b
  return a1//a, b1//a
p, q = gcd(100*n, a+b)
for r in range(1000000007):
  if (r*q)%1000000007 == p%1000000007:
    print(r)
    break

Submission status: Wrong Answer

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

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

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

ans += math.ceil(C/N)

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

Submission status: Wrong Answer

Solution code:
from fractions import Fraction
n, a, b, c = list(map(int, input().split()))

a = a * 0.01
b = b * 0.01
c = c * 0.01

e = 0
for k in range(1, 2*n + 1):
    for i in range(k - n):
        e += (a * (n-1) + b * i + c *(k-n-i)) * k * 2

frac = Fraction(e).limit_denominator(1000)
p = frac.numerator
q = frac.denominator
if p % q == 0:
    print(p // q)

Submission status: Wrong Answer

Solution code:
import math

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

def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))


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

print(ans)