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: Time Limit Exceeded

Solution code:
b, w = map(int, input().split())
MOD = 10 ** 9 + 7
list_size = 200001

f_list = [1] * list_size
f_r_list = [1] * list_size

for i in range(list_size - 1):
	f_list[i + 1] = int((f_list[i] * (i + 2)) % MOD)

def power(n, x):
	if x == 1:
		return n
	elif x % 2 == 0:
		return power(int((n * n) % MOD), int(x / 2))
	else:
		return int((n * power(n, x - 1)) % MOD)

f_r_list[-1] = power(f_list[-1], MOD - 2)

for i in range(2, list_size + 1):
	f_r_list[-i] = int((f_r_list[-i + 1] * (list_size + 2 - i)) % MOD)

def comb(n, r):
	if n < r:
		return 0
	elif n == 0 or r == 0 or n == r:
		return 1
	else:
		return (((f_list[n - 1] * f_r_list[n - r - 1]) % MOD) * f_r_list[r - 1]) % MOD 

def calc(y, x):
	return (y * pow(x, MOD-2, MOD)) % MOD

ans = 500000004
print(ans)
for i in range(1, b+w):
	if i-1 >= b-1:
		ans -= calc(comb(i-1, b-1), pow(2, i+1))
	if i-w >= 0:
		ans += calc(comb(i-1, i-w), pow(2, i+1))
	ans %= MOD
	print(ans)

Submission status: Time Limit Exceeded

Solution code:
B, W = map(int,input().split())
Mod = 10**9+7
magick = 500000004

inv_t = [0]+[1]
for i in range(2,B+W+1):
   inv_t += [inv_t[Mod % i] * (Mod - int(Mod / i)) % Mod]

consts_B, consts_W = [0]*(B-1)+ [1], [0]*(W-1)+[1]
for i in range(B+W):
  if i >= B: consts_B += [consts_B[-1]*(i)*inv_t[i-B+1]%Mod]
  if i >= W: consts_W += [consts_W[-1]*(i)*inv_t[i-W+1]%Mod]

p, q = 0, 0
inv = 1
for i in range(B+W):
  print((1-p+q)*magick%Mod)
  inv *= magick%Mod
  p += consts_B[i]*inv
  q += consts_W[i]*inv

Submission status: Time Limit Exceeded

Solution code:
B, W = map(int,input().split())
Mod = 10**9+7
magick = 500000004

inv_t = [0]+[1]
for i in range(2,B+W+1):
   inv_t += [inv_t[Mod % i] * (Mod - int(Mod / i)) % Mod]

consts_B, consts_W = [0]*(B-1)+ [1], [0]*(W-1)+[1]
for i in range(B+W):
  if i >= B: consts_B += [consts_B[-1]*(i)*inv_t[i-B+1]%Mod]
  if i >= W: consts_W += [consts_W[-1]*(i)*inv_t[i-W+1]%Mod]

p, q = 0, 0
inv = 1
for i in range(B+W):
  print((1-p+q)*magick%Mod)
  inv *= magick
  p += consts_B[i]*inv
  q += consts_W[i]*inv

Submission status: Time Limit Exceeded

Solution code:
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
magick = 500000004

inv_t = [0]+[1]
for i in range(2,B+W+1):
   inv_t += [inv_t[Mod % i] * (Mod - int(Mod / i)) % Mod]

consts_B, consts_W = [0]*(B-1)+ [1], [0]*(W-1)+[1]
for i in range(B+W):
  if i >= B: consts_B += [consts_B[-1]*(i)*inv_t[i-B+1]%Mod]
  if i >= W: consts_W += [consts_W[-1]*(i)*inv_t[i-W+1]%Mod]

p, q = 0, 0
inv = 1
for i in range(B+W):
  print((1-p+q)*magick%Mod)
  inv *= magick
  p += consts_B[i]*inv
  q += consts_W[i]*inv

Submission status: Time Limit Exceeded

Solution code:
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
magick = 500000004

consts_B, consts_W = [0]*(B-1)+ [1], [0]*(W-1)+[1]
for i in range(B+W):
  if i >= B: consts_B += [consts_B[-1]*(i)*power_func(i-B+1, Mod-2,Mod)%Mod]
  if i >= W: consts_W += [consts_W[-1]*(i)*power_func(i-W+1, Mod-2,Mod)%Mod]

p, q = 0, 0
inv = 1
for i in range(B+W):
  print((1-p+q)*magick%Mod)
  inv *= magick
  p += consts_B[i]*inv
  q += consts_W[i]*inv

Submission status: Time Limit Exceeded

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
magick = 500000004

consts_B, consts_W = [], []
for i in range(B+W):
  consts_B += [comb(i,B-1,Mod)]
  consts_W += [comb(i,W-1,Mod)]

p, q = 0, 0
inv = 1
for i in range(B+W):
  print((1-p+q)*magick%Mod)
  inv *= magick
  p += consts_B[i]*inv
  q += consts_W[i]*inv

Submission status: Time Limit Exceeded

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
magick = 500000004

p, q = 0, 0
inv = 1
for i in range(B+W):
  print((1-p+q)*magick%Mod)
  inv *= magick
  p += comb(i,B-1,Mod)*inv
  q += comb(i,W-1,Mod)*inv

Submission status: Time Limit Exceeded

Solution code:
from collections import defaultdict
B,W = map(int,input().split())
mod = 10**9+7

fact = [0]*(10**6+1)
fact[0] = 1
for i in range(10**6):
    fact[i+1] = fact[i]*(i+1)%mod

def comb_(n,k):
    return fact[n]*pow(fact[k],mod-2,mod)*pow(fact[n-k],mod-2,mod)*pow(2,(n+1)*(mod-2),mod)%mod

f_B = defaultdict(lambda:pow(2,mod-2,mod))
f_W = defaultdict(lambda:pow(2,mod-2,mod))
g = defaultdict(lambda:pow(2,W*(mod-2),mod))

for i in range(B,B+W):
    f_B[i+1] = f_B[i]-comb_(i-1,B-1)*pow(2,mod-2,mod)
    f_B[i+1] %= mod

for i in range(W,B+W):
    f_W[i+1] = f_W[i]-comb_(i-1,W-1)*pow(2,mod-2,mod)
    f_W[i+1] %= mod

for i in range(W+1,B+W):
    g[i+1] = g[i] + comb_(i-1,W-1)
    g[i+1] %= mod

for i in range(1,B+W+1):
    if i < W+1:
        print(f_B[i])
    else:
        print((f_B[i]+f_W[i]+g[i]-pow(2,mod-2,mod))%mod)

Submission status: Time Limit Exceeded

Solution code:
B, W = map(int,input().split())
Mod = 10**9+7
magick = 500000004

DP_1 = [[0 for j in range(B+1)] for i in range(B+W+1)]
DP_1[0][B] = 1
for i in range(B+W):
  for j in range(B+1):
    if j == 0:
      DP_1[i+1][j] = 2*DP_1[i][j]+DP_1[i][j+1]
    elif j == B:
      DP_1[i+1][j] = DP_1[i][j]
    else:
      DP_1[i+1][j] = DP_1[i][j] +DP_1[i][j+1]
      
DP_2 = [[0 for j in range(W+1)] for i in range(B+W+1)]
DP_2[0][W] = 1
for i in range(B+W):
  for j in range(W+1):
    if j == 0:
      DP_2[i+1][j] = 2*DP_2[i][j]+DP_2[i][j+1]
    elif j == W:
      DP_2[i+1][j] = DP_2[i][j]
    else:
      DP_2[i+1][j] = DP_2[i][j] +DP_2[i][j+1]
      
inv = 1
for i in range(B+W):
  print(((-DP_1[i][0]+DP_2[i][0])*inv*magick+ magick)%Mod)
  inv = inv * magick%Mod

Submission status: Time Limit Exceeded

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

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

def main():
    B, W = LI()
    N = B + W
    p, q = 0, 0
    biB = binomials(N, B)
    biW = binomials(N, W)
    cnt = 1
    inv2 = mod_factorial(1, 2)
    denomi = inv2
    for i in range(N):
        p = p * 2 + biB[i]
        q = q * 2 + biW[i]
        ans = (cnt - p + q) * denomi % MOD
        print(ans)
        cnt = (cnt * 2) % MOD
        denomi = (denomi * inv2) % MOD

    return 0

main()

Submission status: Time Limit Exceeded

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

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

def main():
    B, W = LI()
    N = B + W
    p, q = 0, 0
    biB = binomials(N, B)
    biW = binomials(N, W)
    cnt = 1
    inv2 = mod_factorial(1, 2)
    denomi = inv2
    for i in range(N):
        p = p * 2 + biB[i]
        q = q * 2 + biW[i]
        ans = (cnt - p + q) * denomi % MOD
        print(ans)
        cnt = (cnt * 2) % MOD
        denomi = (denomi * inv2) % MOD

    return 0

main()

Submission status: Time Limit Exceeded

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

def binomials(n, k):
    ret = [0] * (k + 1)
    ret[-1] = 1
    for i in range(k, n + 1):
        ret.append(ret[-1] * i // (i - k + 1))
    return ret

def main():
    B, W = LI()
    N = B + W
    p, q = 0, 0
    biB = binomials(N, B)
    biW = binomials(N, W)
    cnt = 1
    inv2 = mod_factorial(1, 2)
    denomi = inv2
    for i in range(N):
        p = p * 2 + biB[i]
        q = q * 2 + biW[i]
        ans = (cnt - p + q) * denomi % MOD
        print(ans)
        cnt = (cnt * 2) % MOD
        denomi = (denomi * inv2) % MOD

    return 0

main()

Submission status: Time Limit Exceeded

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

def main():
    B, W = LI()
    N = B + W
    p, q = 0, 0
    binomial = [0] * N
    cnt = 1
    inv2 = mod_factorial(1, 2)
    denomi = inv2
    for i in range(N):
        p = p * 2 + binomial[B - 1]
        q = q * 2 + binomial[W - 1]
        ans = (cnt - p + q) * denomi % MOD
        print(ans)
        binomial = [1] + [x + y for x, y in zip(binomial, binomial[1:])]
        cnt = (cnt * 2) % MOD
        denomi = (denomi * inv2) % MOD

    return 0

main()

Submission status: Time Limit Exceeded

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

def main():
    B, W = LI()
    N = B + W
    p, q = 0, 0
    binomial = [0] * N
    denomi = 1
    for i 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] + [x + y for x, y in zip(binomial, binomial[1:])]
        denomi *= 2

    return 0

main()

Submission status: Time Limit Exceeded

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

def main():
    B, W = LI()
    N = B + W
    p, q = 0, 0
    binomial = [0] * N
    for i in range(N):
        p += Fraction(binomial[B - 1], 2 ** i)
        q += Fraction(binomial[W - 1], 2 ** i)
        f = (1 - p + q) / 2
        x, y = f.numerator, f.denominator
        ans = mod_factorial(x, y)
        print(ans)
        binomial = [1] + [x + y for x, y in zip(binomial, binomial[1:])]

    return 0

main()

Submission status: Time Limit Exceeded

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

mod = 1000000007

def mul(a, b):
  return ((a % mod) * (b % mod)) % mod
  
memo={0:1,1:2}
def power2(y):
  if y in memo:
    pass
  elif y % 2 == 0 :
    memo[y] = power2(y/2)**2 % mod
  else            : 
    memo[y] = power2(y//2)**2 * 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)

#分母


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

Submission status: Time Limit Exceeded

Solution code:
import sys
input=sys.stdin.readline
sys.setrecursionlimit(10**9)
mod=10**9+7
b,w=map(int,input().split())
n=b+w

def power(x,n):
    if n==0:
        return 1
    elif n%2:
        return power(x,n//2)**2*x%mod
    else:
        return power(x,n//2)**2%mod
def modinv(n):
    return power(n,mod-2)

factorial=[1]
for i in range(1,n+1):
    factorial.append(factorial[i-1]*i%mod)
inverse=[0]*(n+1)
inverse[-1]=modinv(factorial[-1])
for i in range(n)[::-1]:
    inverse[i]=inverse[i+1]*(i+1)%mod
def comb(n,r):
    if n<r:
        return 0
    return factorial[n]*inverse[r]*inverse[n-r]%mod

Pb,Pw=[0]*n,[0]*n
inv2=modinv(2)
for i in range(1,n):
    Pb[i]=(Pb[i-1]+comb(i-1,b-1)*power(inv2,i))%mod
    Pw[i]=(Pw[i-1]+comb(i-1,w-1)*power(inv2,i))%mod
for i in range(n):
    print((1-Pb[i]+Pw[i])*inv2%mod)

Submission status: Time Limit Exceeded

Solution code:
import sys
input=sys.stdin.readline
sys.setrecursionlimit(10**9)
mod=10**9+7
b,w=map(int,input().split())
n=b+w

factorial=[1]
for i in range(1,n+1):
    factorial.append(factorial[i-1]*i%mod)
inverse=[0]*(n+1)
inverse[-1]=pow(factorial[-1],mod-2,mod)
for i in range(n-1,-1,-1):
    inverse[i]=inverse[i+1]*(i+1)%mod
def comb(n,r):
    if n<r:
        return 0
    return factorial[n]*inverse[r]*inverse[n-r]%mod
def power(x,n,mod):
    if n==0:
        return 1
    elif n%2:
        return power(x,n//2,mod)**2*x%mod
    else:
        return power(x,n//2,mod)**2%mod
def modinv(n,mod):
    return power(n,mod-2,mod)

Pb,Pw=[0]*n,[0]*n
inv2=modinv(2,mod)
for i in range(1,n):
    Pb[i]=(Pb[i-1]+comb(i-1,b-1)*power(inv2,i,mod))%mod
    Pw[i]=(Pw[i-1]+comb(i-1,w-1)*power(inv2,i,mod))%mod
for i in range(n):
    print((1-Pb[i]+Pw[i])*inv2%mod)

Submission status: Time Limit Exceeded

Solution code:
B,W=map(int,input().split())
mod=10**9+7
kaijo=[1]
Xdiv=[1]
two=pow(2,mod-2,mod)
for i in range(1,1+B+W):
    kaijo.append((kaijo[-1])*i%mod)
    Xdiv.append((Xdiv[-1]*two)%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)
def conb(a,b):
    return (kaijo[a]*gyaku[a-b]*gyaku[b])%mod
Blost,Wlost=0,0
if B==W:
    for k in range(1,B):
        print(two)
    for k in range(B,B+W):
        print(((1+Wlost-Blost)%mod*two)%mod)
        Blost=(Blost+conb(k-1,B-1)*Xdiv[k])%mod
        Wlost=(Wlost+conb(k-1,W-1)*Xdiv[k])%mod
    print(((1+Wlost-Blost)%mod*two)%mod)
elif B<W:
    for k in range(1,B):
        print(two)
    for k in range(B,W):
        print(((1+Wlost-Blost)%mod*two)%mod)
        Blost=(Blost+conb(k-1,B-1)*Xdiv[k])%mod
    for k in range(W,B+W):
        print(((1+Wlost-Blost)%mod*two)%mod)
        Blost=(Blost+conb(k-1,B-1)*Xdiv[k])%mod
        Wlost=(Wlost+conb(k-1,W-1)*Xdiv[k])%mod
    print(((1+Wlost-Blost)%mod*two)%mod)
elif B>W:
    for k in range(1,W):
        print(two)
    for k in range(W,B):
        print(((1+Wlost-Blost)%mod*two)%mod)
        Wlost=(Wlost+conb(k-1,W-1)*Xdiv[k])%mod
    for k in range(B,B+W):
        print(((1+Wlost-Blost)%mod*two)%mod)
        Blost=(Blost+conb(k-1,B-1)*Xdiv[k])%mod
        Wlost=(Wlost+conb(k-1,W-1)*Xdiv[k])%mod
    print(((1+Wlost-Blost)%mod*two)%mod)

Submission status: Time Limit Exceeded

Solution code:
B,W=map(int,input().split())
mod=10**9+7
kaijo=[1]
Xdiv=[1]
two=pow(2,mod-2,mod)
for i in range(1,1+B+W):
    kaijo.append((kaijo[-1])*i%mod)
    Xdiv.append((Xdiv[-1]*two)%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)
def conb(a,b):
    return (kaijo[a]*gyaku[a-b]*gyaku[b])%mod
Blost,Wlost=0,0
if B==W:
    for k in range(1,B):
        print(two)
    for k in range(B,B+W):
        print(((1+Wlost-Blost)*two)%mod)
        Blost=(Blost+conb(k-1,B-1)*Xdiv[k])%mod
        Wlost=(Wlost+conb(k-1,W-1)*Xdiv[k])%mod
    print(((1+Wlost-Blost)*two)%mod)
elif B<W:
    for k in range(1,B):
        print(two)
    for k in range(B,W):
        print(((1+Wlost-Blost)*two)%mod)
        Blost=(Blost+conb(k-1,B-1)*Xdiv[k])%mod
    for k in range(W,B+W):
        print(((1+Wlost-Blost)*two)%mod)
        Blost=(Blost+conb(k-1,B-1)*Xdiv[k])%mod
        Wlost=(Wlost+conb(k-1,W-1)*Xdiv[k])%mod
    print(((1+Wlost-Blost)*two)%mod)
elif B>W:
    for k in range(1,W):
        print(two)
    for k in range(W,B):
        print(((1+Wlost-Blost)*two)%mod)
        Wlost=(Wlost+conb(k-1,W-1)*Xdiv[k])%mod
    for k in range(B,B+W):
        print(((1+Wlost-Blost)*two)%mod)
        Blost=(Blost+conb(k-1,B-1)*Xdiv[k])%mod
        Wlost=(Wlost+conb(k-1,W-1)*Xdiv[k])%mod
    print(((1+Wlost-Blost)*two)%mod)

Submission status: Time Limit Exceeded

Solution code:
B,W=map(int,input().split())
mod=10**9+7
kaijo=[1]
Xdiv=[1]
two=pow(2,mod-2,mod)
for i in range(1,1+B+W):
    kaijo.append((kaijo[-1])*i%mod)
    Xdiv.append((Xdiv[-1]*two)%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)
def conb(a,b):
    if a<b:return 0
    return (kaijo[a]*gyaku[a-b]*gyaku[b])%mod
Blost,Wlost=0,0
for k in range(1,B+W):
    print(((1+Wlost-Blost)*two)%mod)
    Blost=(Blost+conb(k-1,B-1)*Xdiv[k])%mod
    Wlost=(Wlost+conb(k-1,W-1)*Xdiv[k])%mod
print(((1+Wlost-Blost)*two)%mod)

Submission status: Time Limit Exceeded

Solution code:
B,W=map(int,input().split())
mod=10**9+7
kaijo=[1]
Xdiv=[1]
two=pow(2,mod-2,mod)
for i in range(1,1+B+W):
    kaijo.append((kaijo[-1])*i%mod)
    Xdiv.append((Xdiv[-1]*two)%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)
def conb(a,b):
    if a<b:return 0
    return (kaijo[a]*gyaku[a-b]*gyaku[b])%mod
Blost,Wlost=[0],[0]
for k in range(1,B+W):
    Blost.append((Blost[-1]+conb(k-1,B-1)*Xdiv[k])%mod)
    Wlost.append((Wlost[-1]+conb(k-1,W-1)*Xdiv[k])%mod)
    print(((1+Wlost[k-1]-Blost[k-1])*two)%mod)
print(((1+Wlost[B+W-1]-Blost[B+W-1])*two)%mod)

Submission status: Time Limit Exceeded

Solution code:
mod=10**9+7
inv2=5*10**8+4
B,W=map(int,input().split())
 
Factorial=[1]*(B+W+1)
for i in range(1,B+W+1):
  Factorial[i]=Factorial[i-1]*(i)%mod
def power(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
 
inverseFactorial=[1]*(B+W+1)
inverseFactorial[B+W]=power(Factorial[B+W],mod-2)
for i in range(0,B+W)[::-1]:
  inverseFactorial[i]=(inverseFactorial[i+1]*(i+1))%mod
  
def comb(x,y):
  if x<y or y<0:
    return 0
  else:
    return (Factorial[x]*inverseFactorial[y]*inverseFactorial[x-y])%mod
w,b=[0]*(B+W+1),[0]*(B+W+1)
for i in range(1,B+W+1):
  w[i]=(w[i-1]+comb(i-1,W-1)*power(2,B+W-i))%mod
  b[i]=(b[i-1]+comb(i-1,B-1)*power(2,B+W-i))%mod
ans=[0]*(B+W+1)
#print(w)
#print(b)
for i in range(1,B+W+1):
  ans[i]=(power(2,B+W)+w[i-1]-b[i-1])*power(inv2,B+W+1)
  print(ans[i]%mod)

Submission status: Time Limit Exceeded

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
  
memo={0:1,1:2}
def power2(y):
  if y in memo:
    pass
  elif y % 2 == 0 :
    memo[y] = power2(y/2)**2 % mod
  else            : 
    memo[y] = power2(y//2)**2 * 2 % mod
  return memo[y]

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


#B-1列目
B_1 = [0]*(B) + [1]*(W)
for i in range(B, W+B-1):
  #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)
for i in range(B, W+B-1):
  B_0[i+1]=B_0[i]*2 + B_1[i+1]
#print(B_0)

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

#分母

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

Submission status: Time Limit Exceeded

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))


#B-1列目
B_1 = [0]*(B) + [1]*(W)
for i in range(B, W+B-1):
  #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)
for i in range(B, W+B-1):
  B_0[i+1]=B_0[i]*2 + B_1[i+1]
#print(B_0)

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

#分母

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

Submission status: Time Limit Exceeded

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))%mod
  print(a)

Submission status: Time Limit Exceeded

Solution code:
#!/usr/bin/env python3
import math
import operator as op
import os
import sys
from functools import reduce
from io import BytesIO, IOBase

sys.stdout, stream = IOBase(), BytesIO()
sys.stdout.flush = lambda: os.write(1, stream.getvalue()) and not stream.truncate(0) and stream.seek(0)
sys.stdout.write = lambda s: stream.write(s.encode())

input = BytesIO(os.read(0, os.fstat(0).st_size)).readline

MOD = 10**9 + 7
MODF = float(MOD)

MAGIC = 6755399441055744.0
SHRT = 65536.0

MODF_INV = 1.0 / MODF
SHRT_INV = 1.0 / SHRT

fround = lambda x: (x + MAGIC) - MAGIC
fmod = lambda a: a - MODF * fround(MODF_INV * a)
fmul = lambda a, b, c=0.0: fmod(fmod(a * SHRT) * fround(SHRT_INV * b) + a * (b - SHRT * fround(b * SHRT_INV)) + c)


def memoize(f):
    """ Memoization decorator for a function taking one or more arguments. """

    class memodict(dict):
        def __getitem__(self, *key):
            return dict.__getitem__(self, key)

        def __missing__(self, key):
            ret = self[key] = f(*key)
            return ret

    return memodict().__getitem__


@memoize
def fpow(x, y):
    if y == 0:
        return 1.0

    res = 1.0
    while y > 1:
        if y & 1 == 1:
            res = fmul(res, x)
        x = fmul(x, x)
        y >>= 1

    return fmul(res, x)


@memoize
def factorial_p(n):
    ans = 1
    if n <= MOD // 2:
        for i in range(1, n + 1):
            ans = fmul(ans, i)
    else:
        for i in range(1, MOD - n):
            ans = fmul(ans, i)
        ans = fpow(ans, MOD - 2)

        if n % 2 == 0:
            ans = MOD - ans

    return ans


@memoize
def nCr_p(n, r):
    ans = 1.0
    while (n != 0) or (r != 0):
        ans = fmul(fmul(fmul(ans, factorial_p(n)), fpow(factorial_p(r), MOD - 2)), fpow(factorial_p(n - r), MOD - 2))
        n //= MOD
        r //= MOD

    return ans


def main():
    b, w = map(int, input().split())

    inv_2 = [1.0] * (b + w)
    for i in range(b + w - 1):
        inv_2[i + 1] = fmul(inv_2[i], 500000004.0)

    for i in range(1, b + w + 1):
        res = 0.0

        for j in range(max(i - b, 0), min(w, i)):
            res += fmul(nCr_p(i - 1, j), inv_2[i])
        for j in range(w, i):
            res += fmul(nCr_p(i - 1, j), inv_2[i - 1])

        print(int(res) % MOD)


if __name__ == '__main__':
    main()