Problem:


Score : 700 points

Problem Statement

Today, Snuke will eat B pieces of black chocolate and W pieces of white chocolate for an afternoon snack.

He will repeat the following procedure until there is no piece left:

Choose black or white with equal probability, and eat a piece of that color if it exists.

For each integer i from 1 to B+W (inclusive), find the probability that the color of the i-th piece to be eaten is black.
It can be shown that these probabilities are rational, and we ask you to print them modulo 10^9 + 7, as described in Notes.

Notes

When you print a rational number, first write it as a fraction \frac{y}{x}, where x, y are integers and x is not divisible by 10^9 + 7
(under the constraints of the problem, such representation is always possible).
Then, you need to print the only integer z between 0 and 10^9 + 6, inclusive, that satisfies xz \equiv y \pmod{10^9 + 7}.

Constraints

All values in input are integers.

1 \leq B,W \leq 10^{5}

Input

Input is given from Standard Input in the following format:

B W

Output

Print the answers in B+W lines. In the i-th line, print the probability that the color of the i-th piece to be eaten is black, modulo 10^{9}+7.

Sample Input 1

2 1

Sample Output 1

500000004
750000006
750000006

There are three possible orders in which Snuke eats the pieces:

white, black, black

black, white, black

black, black, white

with probabilities \frac{1}{2}, \frac{1}{4}, \frac{1}{4}, respectively. Thus, the probabilities of eating a black piece first, second and third are \frac{1}{2},\frac{3}{4} and \frac{3}{4}, respectively.

Sample Input 2

3 2

Sample Output 2

500000004
500000004
625000005
187500002
187500002

They are \frac{1}{2},\frac{1}{2},\frac{5}{8},\frac{11}{16} and \frac{11}{16}, respectively.

Sample Input 3

6 9

Sample Output 3

500000004
500000004
500000004
500000004
500000004
500000004
929687507
218750002
224609377
303710940
633300786
694091802
172485353
411682132
411682132



Sample input:
2 1


Sample output:
500000004
750000006
750000006

Submission status: Wrong Answer

Solution code:
b,w = map(int,input().split())
flg = 0
if b>w:
  flg = 1
  b,w = w,b
elif b == w:
  for _ in range(b+w):
    print(500000004)
    exit()
mod = 10**9+7
rng = 200100
fctr = [1]
finv = [1]
for i in range(1,rng):
  fctr.append(fctr[-1]*i%mod)
def inv(a):
  return pow(a,mod-2,mod)
def cmb(n,k):
  if n<0 or k<0:
    return 0
  else:
    return fctr[n]*inv(fctr[n-k])*inv(fctr[k])%mod

ans = [500000004]*b
nume = pow(2,b-1,mod)
domi = pow(2,b,mod)
for i in range(b+1,b+w+1):
  domi = domi*2%mod
  nume = nume*2-cmb(i-2,i-b-1)
  if i >= w:
    nume += cmb(i-2,i-w-1)
  nume %= mod
  x = nume*inv(domi)%mod
  if flg:
    ans.append(mod+1-x)
  else:
    ans.append(x)
print(*ans,sep="\n")

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(10**7)
INF = 10 ** 18
MOD = 10 ** 9 + 7
def POW(x, y):
    if y == 0:
        return 1
    elif y == 1:
        return x
    elif y % 2 == 0:
        return POW(x, y // 2) ** 2 % MOD
    else:
        return POW(x, y // 2) ** 2 * x % MOD
        
def mod_factorial(x, y): return x * POW(y, MOD - 2) % MOD
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x) - 1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def II(): return int(sys.stdin.readline())
def SI(): return input()
from fractions import Fraction
import numpy as np




 
 # OPTIMIZE

def main():
    B, W = LI()
    N = B + W
    p, q = 0, 0
    binomial = np.zeros(N, int)
    binomial[0] = 1
    print(mod_factorial(1, 2))
    denomi = 2
    for _ in range(N - 1):
        p = p * 2 + binomial[B - 1]
        q = q * 2 + binomial[W - 1]
        x, y = denomi - p + q, denomi * 2
        ans = mod_factorial(x, y)
        print(ans)
        binomial[1:] += binomial[:-1]
        denomi *= 2
 
    return 0
 
main()

Submission status: Wrong Answer

Solution code:
B, W = list(map(int, input().split()))

MOD = 10**9+7
combB1 = 0
combW1 = 0
y_pi = 0 #i回目までにBを食べ尽くした確率piの分子
y_qi = 0 #i回目までにWを食べ尽くした確率qiの分子
pow2list = [1]
for i in range(B+W):
    pow2list += [pow2list[-1]*2 %MOD]
    y_pi = 0 if i < B else 2*y_pi + combB1
    y_qi = 0 if i < W else 2*y_qi + combW1
    xi = pow2list[i+1]
    yi = (pow2list[i]-y_pi+y_qi) % MOD
    z = yi*pow(xi, MOD-2, MOD) % MOD
    print(z)
    if i < B-1:
        combB1 = 0
    elif i == B-1:
        combB1 = 1
    else:
        combB1 = int(combB1*i/(i-B+1)) % MOD
    if i < W-1:
        combW1 = 0
    elif i == W-1:
        combW1 = 1
    else:
        combW1 = int(combW1*i/(i-W+1)) % MOD

Submission status: Wrong Answer

Solution code:
B=6
W=9

MOD = 10**9+7
def MakeCombList(n,r, MOD): #iCrをi=0...nまで
    ret = []
    for i in range(n):
        if i < r:
            ret = ret+[0]
        elif i == r:
            ret = ret+[1]
        else:
            ret = ret+[ int(ret[-1]*(i)/(i-r)) % MOD]
    return ret
combB1 = MakeCombList(B+W, B-1, MOD)
combW1 = MakeCombList(B+W, W-1, MOD)

y_pi = 0 #i回目までにBを食べ尽くした確率piの分子
y_qi = 0 #i回目までにWを食べ尽くした確率qiの分子
for i in range(B+W):
    y_pi = 0 if i < B else 2*y_pi + combB1[i-1] 
    y_qi = 0 if i < W else 2*y_qi + combW1[i-1]
    xi = pow(2,i+1,MOD)
    yi = (pow(2,i,MOD)-y_pi+y_qi) % MOD
    z = yi*pow(xi, MOD-2, MOD) % MOD
    print(z)

Submission status: Wrong Answer

Solution code:
B, W = map(int, input().split(" "))
MOD = 10 ** 9 + 7

# x * z - MOD * n == y
def calcz(x, y):
    a, b = x, MOD
    syou = []
    while a > 1:
        syou.append(b // a)
        a, b = b % a, a
    syou.reverse()
    dp = [0, 1]
    for i in range(len(syou)):
        dp.append(dp[-1] * (-syou[i]) + dp[-2])
    return (dp[-1] * y) % MOD

p_bl = 0
p_wh = 0
bunbo = 1

btmp = 1
wtmp = 1
print(500000004)
for i in range(1, B + W):
    bunbo = bunbo * 2 % MOD
    if i >= B:
        p_bl = (p_bl * 2 + btmp) % MOD
        if i % 10 == 0:
            btmp = calcz(i - B + 1, btmp * i)
        else:
            btmp = btmp * i // (i - B + 1)
        
    if i >= W:
        p_wh = (p_wh * 2 + wtmp) % MOD
        if i % 10 == 0:
            wtmp = calcz(i - W + 1, wtmp * i)
        else:
            wtmp = wtmp * i // (i - W + 1)
        
    if i < min(B, W):
        print(500000004)
    else:
        bunshi = p_wh + (bunbo - p_bl)
        print(calcz(bunbo * 2, bunshi))

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
import sys

MOD = 1000000007  # type: int

def get_z(y, x): # y / x
    inv_x = pow(x, MOD - 2, MOD)
    return y * inv_x % MOD

def _get_z(y, x): # y / x
    #inv_x = pow(x, MOD - 2, MOD)
    #return y * inv_x % MOD
    while y % x > 0:
        y += MOD
    return y // x

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

def reduce(y, x):
    tmp = gcd(x, y)
    return (y // tmp, x // tmp)

def comb(n, k):
    if n < k:
        return 0
    k = min(k, n - k)
    ret = 1
    for i in range(k):
        ret *= (n - i)
        ret //= (i + 1)
    return ret

def make_comb(n, k):
    ret = [0] * n
    ret[k] = 1
    for i in range(k + 1, n):
        ret[i] = (ret[i - 1] * i) // (i - k)
        ret[i] %= MOD
    return ret

def solve(b: int, w: int):
    n = b + w
    bb = 0
    ww = 0
    b_comb = make_comb(n, b - 1)
    w_comb = make_comb(n, w - 1)
    par = 1
    for i in range(1, n + 1):
        #print(' ======== i: %d ==============' % i)
        other = par - bb - ww
        x = (par * 2) % MOD
        #y = (other + bb * 2) % MOD
        y = other + bb * 2
        #x = (par * 2)
        #print("bb : %d, ww : %d, other : %d" % (bb, ww, other))
        #print(y, ' / ', x)
        #y, x = reduce(y, x)
        ret = get_z(y, x)
        print(ret)
        bb = (bb * 2 + w_comb[i - 1]) % MOD
        ww = (ww * 2 + b_comb[i - 1]) % MOD
        par = (par * 2) % MOD
        #par = (par * 2)
    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    B = int(next(tokens))  # type: int
    W = int(next(tokens))  # type: int
    solve(B, W)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
import sys

MOD = 1000000007  # type: int

def get_z(y, x): # y / x
    inv_x = pow(x, MOD - 2, MOD)
    return y * inv_x % MOD

def _get_z(y, x): # y / x
    #inv_x = pow(x, MOD - 2, MOD)
    #return y * inv_x % MOD
    while y % x > 0:
        y += MOD
    return y // x

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

def reduce(y, x):
    tmp = gcd(x, y)
    return (y // tmp, x // tmp)

def comb(n, k):
    if n < k:
        return 0
    k = min(k, n - k)
    ret = 1
    for i in range(k):
        ret *= (n - i)
        ret //= (i + 1)
    return ret

def make_comb(n, k):
    ret = [0] * n
    ret[k] = 1
    for i in range(k + 1, n):
        ret[i] = (ret[i - 1] * i) // (i - k)
        ret[i] %= MOD
    return ret

def solve(b: int, w: int):
    n = b + w
    bb = 0
    ww = 0
    b_comb = make_comb(n, b - 1)
    w_comb = make_comb(n, w - 1)
    par = 1
    for i in range(1, n + 1):
        #print(' ======== i: %d ==============' % i)
        other = par - bb - ww
        x = (par * 2) % MOD
        y = (other + bb * 2) % MOD
        #y = other + bb * 2
        #x = (par * 2)
        #print("bb : %d, ww : %d, other : %d" % (bb, ww, other))
        #print(y, ' / ', x)
        #y, x = reduce(y, x)
        ret = get_z(y, x)
        print(ret)
        bb = (bb * 2 + w_comb[i - 1]) % MOD
        ww = (ww * 2 + b_comb[i - 1]) % MOD
        par = (par * 2) % MOD
        #par = (par * 2)
    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    B = int(next(tokens))  # type: int
    W = int(next(tokens))  # type: int
    solve(B, W)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
B, W = list(map(int, input().split()))

mod = int(1e9 + 7)

def mulmod(a, b):
  #print(a,b)
  return ((a % mod) * (b % mod)) % mod
  
memo={0:1, 1:2}
def power2mod(y):
  #print(y)
  if y in memo:
    return memo[y]
  else:
    memo[y] = power2mod(y//2)**2 * 2**(y%2) %mod
    return memo[y]

#B列目
B_0 = [0 for _ in range(B)] + [1 for _ in range(W)]
B_1 = 1
for i in range(B, W+B-1):
  B_1 = (B_1*i//(i-B+1)) %mod
  B_0[i+1]=(B_0[i]*2 + B_1) %mod

#W列目
W_0 = [0 for _ in range(W)] + [1 for _ in range(B)]
W_1 = 1
for i in range(W, W+B-1):
  W_1 = (W_1*i//(i-W+1)) %mod
  W_0[i+1]=(W_0[i]*2 + W_1) %mod

#分母 m
#log2m

for i in range(B+W):
  b = B_0[i]
  w = W_0[i]
  if b==0 and w==0:
    print(500000004)
    continue
    
  log2m = i
  
  while not b%2 and not w%2 and log2m:
    b=b//2
    w=w//2
    log2m-=1
  
  p = power2mod((mod-2) * (log2m+1)) # 2^(log2m+1)で割りたい
  a = mulmod(power2mod(log2m)-b+w, p)
  
  print(a)

Submission status: Wrong Answer

Solution code:
B, W = list(map(int, input().split()))

mod = 1000000007

def mulmod(a, b):
  return ((a % mod) * (b % mod)) % mod
  
memo={0:1, 1:2}
def power2mod(y):
  if y in memo:
    return memo[y]
  else:
    memo[y] = power2mod(y//2)**2 * 2**(y%2) %mod
    return memo[y]

#B列目
B_0 = [0 for _ in range(B)] + [1 for _ in range(W)]
B_1 = 1
for i in range(B, W+B-1):
  B_1 = (B_1*i//(i-B+1)) %mod
  B_0[i+1]=(B_0[i]*2 + B_1) %mod

#W列目
W_0 = [0 for _ in range(W)] + [1 for _ in range(B)]
W_1 = 1
for i in range(W, W+B-1):
  W_1 = (W_1*i//(i-W+1)) %mod
  W_0[i+1]=(W_0[i]*2 + W_1) %mod
#print(W_0)


#分母 m
#log2m +1

for i in range(B+W):
  b = B_0[i]
  w = W_0[i]
  log2m = i
  
  while not b%2 and not w%2 and log2m:
    if b==0 and w==0:
      log2m=0
      break
    b=b//2
    w=w//2
    log2m-=1
  
  p = power2mod((mod-2)*(log2m+1)) #フェルマーの小定理
  a = mulmod(power2mod(log2m)-b+w, p)
  
  print(a)

Submission status: Wrong Answer

Solution code:
B, W = map(int, input().split(" "))
MOD = 10 ** 9 + 7

# x * z - MOD * n == y
def calcz(x, y):
    a, b = x, MOD
    syou = []
    while a > 1:
        syou.append(b // a)
        a, b = b % a, a
    syou.reverse()
    dp = [0, 1]
    for i in range(len(syou)):
        dp.append(dp[-1] * (-syou[i]) + dp[-2])
    return (dp[-1] * y) % MOD

p_bl = [0 for i in range(B+W)]
p_wh = [0 for i in range(B+W)]
bunbo = [1]

btmp = 1
wtmp = 1
print(500000004)
for i in range(1, B + W):
    bunbo.append(bunbo[-1] * 2 % MOD)
    if i >= B:
        p_bl[i] = (p_bl[i-1] * 2 + btmp) % MOD
        btmp = btmp * i // (i - B + 1) % MOD
        
    if i >= W:
        p_wh[i] = (p_wh[i-1] * 2 + wtmp) % MOD
        wtmp = wtmp * i // (i - W + 1) % MOD
        
    if i < min(B, W):
        print(500000004)
    else:
        bunshi = p_wh[i] + (bunbo[i] - p_bl[i])
        print(calcz(bunbo[i] * 2, bunshi))

Submission status: Wrong Answer

Solution code:
B, W = map(int, input().split(" "))
MOD = 10 ** 9 + 7

# x * z - MOD * n == y
def calcz(x, y):
    a, b = x, MOD
    syou = []
    while a > 1:
        syou.append(b // a)
        a, b = b % a, a
    syou.reverse()
    dp = [0, 1]
    for i in range(len(syou)):
        dp.append(dp[-1] * (-syou[i]) + dp[-2])
    return (dp[-1] * y) % MOD

p_bl = [0 for i in range(B+W)]
p_wh = [0 for i in range(B+W)]
bunbo = [1]

btmp = 1
wtmp = 1
print(500000004)
for i in range(1, B + W):
    bunbo.append(bunbo[-1] * 2 % MOD)
    if i >= B:
        p_bl[i] = (p_bl[-1] * 2 + btmp) % MOD
        btmp = btmp * i // (i - B + 1) % MOD
        
    if i >= W:
        p_wh[i] = (p_wh[-1] * 2 + wtmp) % MOD
        wtmp = wtmp * i // (i - W + 1) % MOD
        
    if i < min(B, W):
        print(500000004)
    else:
        bunshi = p_wh[i] + (bunbo[i] - p_bl[i])
        print(calcz(bunbo[i] * 2, bunshi))

Submission status: Wrong Answer

Solution code:
B, W = map(int, input().split(" "))
MOD = 10 ** 9 + 7

# x * z - MOD * n == y
def calcz(x, y):
    a, b = x, MOD
    syou = []
    while a > 1:
        syou.append(b // a)
        a, b = b % a, a
    syou.reverse()
    dp = [0, 1]
    for i in range(len(syou)):
        dp.append(dp[-1] * (-syou[i]) + dp[-2])
    return (dp[-1] * y) % MOD

p_bl = [0 for i in range(B+W)]
p_wh = [0 for i in range(B+W)]
bunbo = [1]

btmp = 1
wtmp = 1
for i in range(1, B + W):
    bunbo.append(bunbo[-1] * 2 % MOD)
    if i >= B:
        p_bl[i] = (p_bl[-1] * 2 + btmp) % MOD
        btmp = btmp * i // (i - B + 1) % MOD
        
    if i >= W:
        p_wh[i] = (p_wh[-1] * 2 + wtmp) % MOD
        wtmp = wtmp * i // (i - W + 1) % MOD
        
    if i < min(B, W):
        print(500000004)
    else:
        bunshi = p_wh[i] + (bunbo[i] - p_bl[i])
        print(calcz(bunbo[i] * 2, bunshi))

Submission status: Wrong Answer

Solution code:
B, W = map(int, input().split(" "))
MOD = 10 ** 9 + 7

# x * z - MOD * n == y
def calcz(x, y):
    a, b = x, MOD
    syou = []
    while a > 1:
        syou.append(b // a)
        a, b = b % a, a
    syou.reverse()
    dp = [0, 1]
    for i in range(len(syou)):
        dp.append(dp[-1] * (-syou[i]) + dp[-2])
    return (dp[-1] * y) % MOD

p_bl = [(1, 0)]
p_wh = [(1, 0)]

tmp = 1
for i in range(1, B + W):
    if i < B:
        p_bl.append((p_bl[-1][0] * 2 % MOD, 0))
    else:
        p_bl.append((p_bl[-1][0] * 2 % MOD, p_bl[-1][1] * 2 + tmp))
        tmp = tmp * i // (i - B + 1) % MOD
        
tmp = 1
for i in range(1, B + W):
    if i < W:
        p_wh.append((p_wh[-1][0] * 2 % MOD, 0))
    else:
        p_wh.append((p_wh[-1][0] * 2 % MOD, p_wh[-1][1] * 2 + tmp))
        tmp = tmp * i // (i - W + 1) % MOD

for i in range(B + W):
    bunshi = p_wh[i][1] + (p_bl[i][0] - p_bl[i][1])
    print(calcz(p_bl[i][0] * 2, bunshi))

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(10**7)
INF = 10 ** 18
MOD = 10 ** 9 + 7
def POW(x, y):
    if y == 0:
        return 1
    elif y == 1:
        return x
    elif y % 2 == 0:
        return POW(x, y // 2) ** 2 % MOD
    else:
        return POW(x, y // 2) ** 2 * x % MOD
def mod_factorial(x, y): return x * POW(y, MOD - 2) % MOD
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x) - 1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def II(): return int(sys.stdin.readline())
def SI(): return input()
from fractions import Fraction
import numpy as np

def main():
    B, W = LI()
    N = B + W
    p, q = 0, 0
    binomial = np.zeros(N, int)
    denomi = 1
    for _ in range(N):
        p = p * 2 + binomial[B - 1]
        q = q * 2 + binomial[W - 1]
        x, y = denomi - p + q, denomi * 2
        ans = mod_factorial(x, y)
        print(ans)
        binomial[1:] += binomial[:-1]
        binomial[0] = 1
        denomi *= 2

    return 0

main()

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(10**7)
INF = 10 ** 18
MOD = 10 ** 9 + 7
def POW(x, y):
    if y == 0:
        return 1
    elif y == 1:
        return x
    elif y % 2 == 0:
        return POW(x, y // 2) ** 2 % MOD
    else:
        return POW(x, y // 2) ** 2 * x % MOD
def mod_factorial(x, y): return x * POW(y, MOD - 2) % MOD
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x) - 1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def II(): return int(sys.stdin.readline())
def SI(): return input()
from fractions import Fraction
import numpy as np

def main():
    B, W = LI()
    N = B + W
    p, q = 0, 0
    binomial = np.zeros(N, int)
    binomial[0] = 1
    print(mod_factorial(1, 2))
    denomi = 2
    for _ in range(N - 1):
        p = p * 2 + binomial[B - 1]
        q = q * 2 + binomial[W - 1]
        x, y = denomi - p + q, denomi * 2
        ans = mod_factorial(x, y)
        print(ans)
        binomial[1:] += binomial[:-1]
        denomi *= 2

    return 0

main()

Submission status: Wrong Answer

Solution code:
from math import factorial as f;b,w=map(int,input().split());gcd=lambda a,b:gcd(max(a,b)%min(a,b),min(a,b))if max(a,b)%min(a,b)else min(a,b);p=f(b+w)//f(b)//f(w)
def g(x,y):print((1000000008*x)//y)
q=2
for i in range(min(b,w)):g(1,2);q*=2
x,y=1,2
for i in range(b+w-min(b,w)-1):bunbo=q;bunsi=q//2+1;x,y=bunbo,bunsi;g(y,x);q*=2
g(y,x)

Submission status: Wrong Answer

Solution code:
B,W=map(int,input().split())
mod=10**9+7
two=pow(2,mod-2,mod)
kaijo=[1]
for i in range(1,1+B+W):
    kaijo.append((kaijo[-1])*i%mod)
from collections import deque
gyaku=deque()
gyaku.append(pow(kaijo[B+W],mod-2,mod))
for i in range(B+W,0,-1):
    gyaku.appendleft((gyaku[0]*i)%mod)
for k in range(1,B+W+1):
    if k<=B:
        print(two)
    elif k==B+1:
        x=pow(2,k-1,mod)
        xdiv=pow(x,mod-2,mod)
        y=(x-kaijo[k-1]*gyaku[k-B-1]*gyaku[B])%mod
        print((y*xdiv)%mod)

Submission status: Wrong Answer

Solution code:
B, W = list(map(int, input().split()))

mod = 1000000007

def mul(a, b):
  return ((a % mod) * (b % mod)) % mod

def power(x, y):
  #print(x,y)
  if   y == 0     : return 1
  elif y == 1     : return x % mod
  elif y % 2 == 0 : return power(x, y/2)**2 % mod
  else            : return power(x, y//2)**2 * x % mod

def div(a, b):
  return mul(a, power(b, mod-2))
  

#from fractions import gcd


#B-1列目
B_1 = [0]*(B) + [1]*(W+1)
for i in range(B, W+B):
  #print(i)
  B_1[i+1]=(B_1[i]*(i))//(i-B+1)
  #print(B_1)
  
#print(B_1)
  
#B列目
B_0 = [0]*(B) + [1]*(W+1)
for i in range(B, W+B):
  B_0[i+1]=B_0[i]*2 + B_1[i+1]
#print(B_0)

#W-1列目
W_1 = [0]*(W) + [1]*(B+1)
for i in range(W, W+B):
  W_1[i+1]=W_1[i]*(i)//(i-W+1)
#print(W_1)
  
#W列目
W_0 = [0]*(W) + [1]*(B+1)
for i in range(W, W+B):
  W_0[i+1]=W_0[i]*2 + W_1[i+1]
#print(W_0)

#分母
log2M = [i for i in range(W+B)]
#print(log2M)

for i in range(B+W):
  b = B_0[i]
  w = W_0[i]
  log2m = log2M[i]
  #print(b,w,log2m)
  
  while not b%2 and not w%2 and log2m:
    b=b//2
    w=w//2
    log2m-=1
  
  #print(b,w,log2m)
  #print(2**log2m - b + w)
  #print(2**(log2m+1))
  
  # (2**(log2m+1) -b + w) /2**(log2m+1) = y/x
  # answer = y / x (mod)
  p = power(2, (mod-2)*(log2m+1))
  a = mul(power(2,log2m),p) - mul(b,p) + mul(w,p)
  print(a)

Submission status: Wrong Answer

Solution code:
Q = 10**9+7
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

B, W = map( int, input().split())
I = getInv(B+W)
F = [1]*(B+W+1)
for i in range(1,B+W+1):
    F[i] = F[i]*i%Q
w = 0
b = 0
for i in range(1,B+W+1):
    if i - 1 < B and i - 1 < W:
        print(I[2])
    elif i - 1 == W and i - 1< B:
        w = pow(I[2],i-1,Q)
        print(((1 -  w)%Q*I[2]%Q + w)%Q)
    elif i - 1 >= W and i - 1< B: #i > B
        w += F[i-2]*I[i-1-W]%Q*I[W-1]%Q*pow(I[2],i-1,Q)%Q
        w %= Q
        print(((1 -  w)%Q*I[2]%Q + w)%Q)
    elif i - 1 == B and i - 1 < W:
        b = pow(I[2],i-1,Q)
        print((1-b)%Q*I[2]%Q)
    elif i - 1 >= B and i - 1 < W: #i > W
        b += F[i-2]*I[i-1-B]%Q*I[B-1]%Q*pow(I[2],i-1,Q)%Q
        b %= Q
        print((1-b)%Q*I[2]%Q)
    elif i - 1 == B and i - 1 == W:
        w = pow(I[2],i-1,Q)
        b = pow(I[2],i-1,Q)
        print(((1 -  w - b)%Q*I[2]%Q + w)%Q)
    else:
        w += F[i-2]*I[i-1-W]%Q*I[W-1]%Q*pow(I[2],i-1,Q)%Q
        w %= Q
        b += F[i-2]*I[i-1-B]%Q*I[B-1]%Q*pow(I[2],i-1,Q)%Q
        b %= Q
        print(((1 -  w - b)%Q*I[2]%Q + w)%Q)

Submission status: Wrong Answer

Solution code:
def comb(n,k,p):
  """power_funcを用いて(nCk) mod p を求める"""
  from math import factorial
  if n<0 or k<0 or n<k: return 0
  if n==0 or k==0: return 1
  a=factorial(n) %p
  b=factorial(k) %p
  c=factorial(n-k) %p
  return (a*power_func(b,p-2,p)*power_func(c,p-2,p))%p

def power_func(a,b,p):
  """a^b mod p を求める"""
  if b==0: return 1
  if b%2==0:
    d=power_func(a,b//2,p)
    return d*d %p
  if b%2==1:
    return (a*power_func(a,b-1,p ))%p

B, W = map(int,input().split())
Mod = 10**9+7

mi = min(B,W)
BisBigger = 1
if W>B:BisBigger = -1

magick = 500000004
DP = [[0 for i in range(mi+1)] for j in range(B+W+1)]
DP[0][mi] = 1
for i in range(B+W):
  for j in range(mi+1):
    DP[i+1][j] += DP[i][j]
    if j < mi:
      DP[i+1][j]+= DP[i][j+1]
      
for i in range(B+W):
  if i < mi:
    print(magick)
  elif i == mi:
    inv = power_func(magick,i,Mod)
    print((BisBigger* DP[i][0]*inv*magick+ magick)%Mod)
  else :
    inv = inv * magick%Mod
    print((BisBigger* DP[i][0]*inv*magick+ magick)%Mod)

Submission status: Wrong Answer

Solution code:
def comb(n,k,p):
  """power_funcを用いて(nCk) mod p を求める"""
  from math import factorial
  if n<0 or k<0 or n<k: return 0
  if n==0 or k==0: return 1
  a=factorial(n) %p
  b=factorial(k) %p
  c=factorial(n-k) %p
  return (a*power_func(b,p-2,p)*power_func(c,p-2,p))%p

def power_func(a,b,p):
  """a^b mod p を求める"""
  if b==0: return 1
  if b%2==0:
    d=power_func(a,b//2,p)
    return d*d %p
  if b%2==1:
    return (a*power_func(a,b-1,p ))%p

B, W = map(int,input().split())
Mod = 10**9+7

mi = min(B,W)
BisBigger = 1
if W>B:BisBigger = -1

magick = 500000004
DP = [[0 for i in range(mi+1)] for j in range(B+W+1)]
DP[0][mi] = 1
for i in range(B+W):
  for j in range(mi+1):
    if j == 0:
      DP[i+1][j] = DP[i][j]
    DP[i+1][j] += DP[i][j]
    if j < mi:
      DP[i+1][j]+= DP[i][j+1]
      
for i in range(B+W):
  if i < mi:
    print(magick)
  elif i == mi:
    inv = power_func(magick,i,Mod)
    print((BisBigger* DP[i][0]*inv*magick+ magick)%Mod)
  else :
    inv = inv * magick%Mod
    print((BisBigger* DP[i][0]*inv*magick+ magick)%Mod)

Submission status: Wrong Answer

Solution code:
def comb(n,k,p):
  """power_funcを用いて(nCk) mod p を求める"""
  from math import factorial
  if n<0 or k<0 or n<k: return 0
  if n==0 or k==0: return 1
  a=factorial(n) %p
  b=factorial(k) %p
  c=factorial(n-k) %p
  return (a*power_func(b,p-2,p)*power_func(c,p-2,p))%p

def power_func(a,b,p):
  """a^b mod p を求める"""
  if b==0: return 1
  if b%2==0:
    d=power_func(a,b//2,p)
    return d*d %p
  if b%2==1:
    return (a*power_func(a,b-1,p ))%p

B, W = map(int,input().split())
Mod = 10**9+7

mi = min(B,W)
BisBigger = 1
if W>B:BisBigger = -1

magick = 500000004

for i in range(B+W):
  if i < mi:
    print(magick)
  elif i == mi:
    cons = comb(i,mi,Mod)*power_func(magick,i,Mod)%Mod*magick 
    print((BisBigger* cons+ magick)%Mod)
  else :
    cons = cons*i*power_func(i-mi,Mod-2,Mod)* magick
    print((BisBigger* cons+ magick)%Mod)

Submission status: Wrong Answer

Solution code:
def comb(n,k,p):
  """power_funcを用いて(nCk) mod p を求める"""
  from math import factorial
  if n<0 or k<0 or n<k: return 0
  if n==0 or k==0: return 1
  a=factorial(n) %p
  b=factorial(k) %p
  c=factorial(n-k) %p
  return (a*power_func(b,p-2,p)*power_func(c,p-2,p))%p

def power_func(a,b,p):
  """a^b mod p を求める"""
  if b==0: return 1
  if b%2==0:
    d=power_func(a,b//2,p)
    return d*d %p
  if b%2==1:
    return (a*power_func(a,b-1,p ))%p

B, W = map(int,input().split())
Mod = 10**9+7

mi = min(B,W)
BisBigger = 1
if W>B:BisBigger = -1

magick = 500000004
inv_2 = power_func(2,Mod-2,Mod)
for i in range(B+W):
  if i < mi:
    print(magick)
  elif i == mi:
    cons = BisBigger* comb(i,mi,Mod)*power_func(inv_2,i,Mod)%Mod*magick 
    print((cons+ magick)%Mod)
  else :
    cons = cons*i*power_func(i-mi,Mod-2,Mod)* inv_2
    print((cons+ magick)%Mod)

Submission status: Wrong Answer

Solution code:
def comb(n,k,p):
  """power_funcを用いて(nCk) mod p を求める"""
  from math import factorial
  if n<0 or k<0 or n<k: return 0
  if n==0 or k==0: return 1
  a=factorial(n) %p
  b=factorial(k) %p
  c=factorial(n-k) %p
  return (a*power_func(b,p-2,p)*power_func(c,p-2,p))%p

def power_func(a,b,p):
  """a^b mod p を求める"""
  if b==0: return 1
  if b%2==0:
    d=power_func(a,b//2,p)
    return d*d %p
  if b%2==1:
    return (a*power_func(a,b-1,p ))%p

B, W = map(int,input().split())
Mod = 10**9+7

mi = min(B,W)

magick = 500000004
inv_2 = power_func(2,Mod-2,Mod)
for i in range(B+W):
  if i < mi:
    print(magick)
  elif i == mi:
    cons = comb(i,mi,Mod)*power_func(inv_2,i-mi+2,Mod)%Mod*magick + magick
    print(cons%Mod)
  else :
    cons = comb(i,mi,Mod)*power_func(inv_2,i-mi+2,Mod)%Mod*magick + magick
    print(cons%Mod)

Submission status: Time Limit Exceeded

Solution code:
H,W=map(int,input().split())
#TLE回答
mod =10**9 + 7
def frac_to_int(X,Y):
    return X*pow(Y,mod-2,mod)%mod
for k in range(H+W):
    cnt=2**(k+1)
    for i in range(2**(k+1)):
        white=0
        black=0
        s=format(i,"0%ib"%(k+1))
        for j in range(k+1):
            if s[j]=="0":
                white+=1
            else:
                black+=1
        if s[-1]=="0" and white<=W:
            cnt-=1
        elif s[-1]=="1" and black>H:
            cnt-=1
    print(frac_to_int(cnt,pow(2,k+1,mod)))

Submission status: Time Limit Exceeded

Solution code:
b,w=map(int,input().split())
dp=[0]*(b+w)
dp[0]=1/2
mod=pow(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] # g1[i]=i! % mod　:階乗
g2=[1,1] # g2[i]=(i!)^(-1) % mod　:階乗の逆元
inverse=[0,1]
for i in range(2,b+w+1):
  g1.append((g1[-1]*i)%mod)
  inverse.append((-inverse[mod%i]*(mod//i))%mod)
  g2.append((g2[-1]*inverse[-1])%mod)
t1,t2=0,0
for i in range(1,1+b+w):
  t=pow(2,mod-2,mod)
  if i-b>0:
    t1*=2
    t1+=cmb(i-2,b-1,mod)
    tmp=t1*pow(2,mod-1-i,mod)
    tmp%=mod
    t-=tmp
    t%=mod
  if i-w>0:
    t2*=2
    t2+=cmb(i-2,w-1,mod)
    tmp=t2*pow(2,mod-1-i,mod)
    tmp%=mod
    t+=tmp
    t%=mod
  print(t)

Submission status: Time Limit Exceeded

Solution code:
b,w=map(int,input().split())
dp=[0]*(b+w)
dp[0]=1/2
mod=pow(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] # g1[i]=i! % mod　:階乗
g2=[1,1] # g2[i]=(i!)^(-1) % mod　:階乗の逆元
inverse=[0,1]
for i in range(2,b+w+1):
  g1.append((g1[-1]*i)%mod)
  inverse.append((-inverse[mod%i]*(mod//i))%mod)
  g2.append((g2[-1]*inverse[-1])%mod)

for i in range(1,1+b+w):
  t=pow(2,mod-2,mod)
  t1,t2=0,0
  if i-b>0:
    t1=sum([cmb(i-1,x,mod) for x in range(b,i+1)])%mod
    t1*=pow(2,mod-1-i,mod)
    t1%=mod
    t-=t1
    t%=mod
  if i-w>0:
    t2=sum([cmb(i-1,x,mod) for x in range(w,i+1)])%mod
    t2*=pow(2,mod-1-i,mod)
    t2%=mod
    t+=t2
    t%=mod
  print(t)

Submission status: Time Limit Exceeded

Solution code:
def examA():
    N = DI()/dec(7)
    ans = N
    print(N)
    return

def examB():
    ans = 0
    print(ans)
    return

def examC():
    ans = 0
    print(ans)
    return

def examD():
    ans = 0
    print(ans)
    return

def examE():
    class combination():
        # 素数のmod取るときのみ　速い
        def __init__(self, n, mod):
            self.n = n
            self.mod = mod
            self.fac = [1] * (n + 1)
            self.inv = [1] * (n + 1)
            for j in range(1, n + 1):
                self.fac[j] = self.fac[j - 1] * j % mod

            self.inv[n] = pow(self.fac[n], mod - 2, mod)
            for j in range(n - 1, -1, -1):
                self.inv[j] = self.inv[j + 1] * (j + 1) % mod

        def comb(self, n, r):
            if r > n or n < 0 or r < 0:
                return 0
            return self.fac[n] * self.inv[n - r] * self.inv[r] % self.mod
    B, W = LI()
    N = B+W
    C = combination(N,mod)

    ans = [0]*N
    inv_2 = pow(2,mod-2,mod)
    now_W = 0
    now_B = 0
    for i in range(N):
        cur = inv_2
        if i>=W:
            #print(i)
            now_W = now_W*2 + C.comb(i-1, i-W)
            cur += pow(inv_2,i+1,mod)*now_W
        if i>=B:
            now_B = now_B * 2 + C.comb(i - 1, i - B)
            cur -= pow(inv_2, i + 1, mod) * now_B
        cur %= mod
        ans[i] = cur

    for v in ans:
        print(v)
    return

def examF():
    ans = 0
    print(ans)
    return

from decimal import getcontext,Decimal as dec
import sys,bisect,itertools,heapq,math,random
from copy import deepcopy
from heapq import heappop,heappush,heapify
from collections import Counter,defaultdict,deque
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
def I(): return int(input())
def LI(): return list(map(int,sys.stdin.readline().split()))
def DI(): return dec(input())
def LDI(): return list(map(dec,sys.stdin.readline().split()))
def LSI(): return list(map(str,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def SI(): return sys.stdin.readline().strip()
global mod,mod2,inf,alphabet,_ep
mod = 10**9 + 7
mod2 = 998244353
inf = 10**18
_ep = dec("0.000000000001")
alphabet = [chr(ord('a') + i) for i in range(26)]
alphabet_convert = {chr(ord('a') + i): i for i in range(26)}

getcontext().prec = 28

sys.setrecursionlimit(10**7)

if __name__ == '__main__':
    examE()

"""
142
12 9 1445 0 1
asd dfg hj o o
aidn
"""

Submission status: Time Limit Exceeded

Solution code:
M=10**9+7;B,W=map(int,input().split());F=[1];I=[1];p=q=0;C=lambda n,k:F[n]*pow(F[k]*F[n-k],M-2,M)if n>=k else 0
for i in range(1,B+W+1):F+=[F[-1]*i];I+=[I[-1]+I[-1]%2*M>>1];print((1-p+q)*I[1]%M);p+=C(i-1,B-1)*I[i];q+=C(i-1,W-1)*I[i]