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

Solution (Python):
B,W=map(int,input().split())
mod=10**9+7
kaijo={0:1}
Xdiv={0:1}
two=pow(2,mod-2,mod)
for i in range(1,1+B+W):
    kaijo[i]=(kaijo[i-1]*i)%mod
    Xdiv[i]=(Xdiv[i-1]*two)%mod
gyaku={B+W:pow(kaijo[B+W],mod-2,mod)}
for i in range(B+W,0,-1):
    gyaku[i-1]=(gyaku[i]*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)

Solution (Python):
Q = 10**9+7
def getInv(N):
    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())
Z = getInv(B+W)
I = [1]*(B+W+1)
for i in range(1,B+W+1):
    I[i] = (I[i-1]*Z[i])%Q

F = [1]*(B+W+1)
for i in range(1,B+W+1):
    F[i] = F[i-1]*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 += 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 += 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)
    
    
    
    
    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)

Solution (Python):
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)
p2=[1]*(B+W+1)
for i in range(1,B+W+1):
  p2[i]=(p2[i-1]*2)%mod
bunbo=power(inv2,B+W+1)  

for i in range(1,B+W+1):
  w[i]=(w[i-1]+comb(i-1,W-1)*p2[B+W-i])%mod
  b[i]=(b[i-1]+comb(i-1,B-1)*p2[B+W-i])%mod
ans=[0]*(B+W+1)


for i in range(1,B+W+1):
  ans[i]=(p2[B+W]+w[i-1]-b[i-1])*bunbo
  print(ans[i]%mod)

Solution (Python):


import sys
input = sys.stdin.readline

SIZE=200002; 
MOD = 10**9+7
bai= 500000000+4

inv = [0]*(SIZE+1)
fac = [0]*(SIZE+1)
finv = [0]*(SIZE+1)
inv[1] = 1
fac[0] = fac[1] = 1
finv[0] = finv[1] = 1
for i in range(2,SIZE+1):
    inv[i] = MOD -(MOD//i)*inv[MOD%i]%MOD
    fac[i] = fac[i-1]*i%MOD
    finv[i]= finv[i-1]*inv[i]%MOD

def choose(n,r): 
    if 0 <= r <= n:
        return (fac[n]*finv[r]%MOD)*finv[n-r]%MOD
    else:
        return 0



b,w = [int(i) for i in input().split()]

c = min(b,w)
for i in [0]*c:
    print(bai)

ans = bai
p=pow(bai,c+1,MOD)
for i in range(c,b+w):

    ans += p*(choose(i-1,i-w) - choose(i-1,b-1))
    p= p*bai; p%=MOD
    ans = ans%MOD
    print(ans)

Solution (Python):
INF = 1000000007

def ex_gcd(a, b):
	x1, x2 = 0, 1
	y1, y2 = 1, 0
	q = 0
	while b:
		x1, x2 = x2, x1 - q * x2
		y1, y2 = y2, y1 - q * y2
		q = a // b
		a, b = b, a % b
	return a, x2, y2

def invert(x, mod=INF):
	return ex_gcd(x, mod)[1] % mod

B, W = map(int, input().split())

p = 0
q = 0
c1, c2 = 0, 1
d1, d2 = 0, 1
s = 1
for k in range(1, B + W + 1):
	if B + 1 < k:
		c1 = c2
		c2 *= invert((k - 1) - B) * (k - 1) % INF
		c2 %= INF
	if W + 1 < k:
		d1 = d2
		d2 *= invert((k - 1) - W) * (k - 1) % INF
		d2 %= INF
	if B < k:
		p += (c2 - c1) * s % INF
		p %= INF
	if W < k:
		q += (d2 - d1) * s % INF
		q %= INF
	print((q + invert(2) * (1 - p - q)) % INF)
	s *= invert(2)
	s %= INF

Solution (Python):
Q = 10**9+7
def getInv(N):
    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())
Z = getInv(B+W)
I = [1]*(B+W+1)
for i in range(1,B+W+1):
    I[i] = (I[i-1]*Z[i])%Q

F = [1]*(B+W+1)
for i in range(1,B+W+1):
    F[i] = F[i-1]*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: 
        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: 
        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)

Solution (Python):
mod=10**9+7
def gcd(x,y):
    if x<y:
        x,y=y,x
    
    if x%y==0:
        return y
    else:
        return gcd(y,x%y)
def egcd(a, b):
    (x,lastx)=(0,1)
    (y,lasty)=(1,0)
    while b != 0:
        q = a // b
        (a, b) = (b, a % b)
        (x, lastx) = (lastx - q * x, x)
        (y, lasty) = (lasty - q * y, y)
    return (lastx, lasty, a)
def inv(x):
    return egcd(x,mod)[0]%mod
N=2*10**5+10
B,W=map(int,input().split())
Blist=[0 for i in range(N+1)]
Wlist=[0 for i in range(N+1)]
Fact=[0 for i in range(N+1)]
Finv=[0 for i in range(N+1)]
Exp2=[0 for i in range(N+1)]
Fact[0]=1;Finv[0]=1
Exp2[0]=1
for i in range(N):
    Exp2[i+1]=(Exp2[i]*2)%mod
for i in range(N):
    Fact[i+1]=(Fact[i]*(i+1))%mod
    Finv[i+1]=inv(Fact[i+1])
def C(n,k):
    if k<0 or n<k:
        return 0
    else:
        return (Finv[k]*(Fact[n]*Finv[n-k])%mod)%mod
Blist[0]=1;Wlist[0]=1
for i in range(N):
    Blist[i+1]=(2*Blist[i]-C(i,B-1))%mod
    Wlist[i+1]=(2*Wlist[i]-C(i,W-1))%mod


ans=[0 for i in range(B+W)]
for i in range(B+W):
    ans[i]=(Blist[i]-Wlist[i]+Exp2[i])%mod
    ans[i]=(ans[i]*inv(Exp2[i+1]))%mod
for line in ans:
    print(line)

Solution (Python):

B, W = map(int, input().split())

LARGE = 10**9 + 7


modulo = [0]*(2*10**5+1)
modulo[0] = 1
for i in range(1, 2*10**5+1):
    modulo[i] =(5*10**8 + 4) * modulo[i-1] % LARGE

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)

def modinv(a, m):
    g, x, y = egcd(a, m)
    if g != 1:
        raise Exception('modular inverse does not exist')
    else:
        return x % m    
    
frac_mod = [0]*(2*10**5+1)
frac_inv_mod = [0]*(2*10**5+1)
frac_mod[0] = 1
frac_inv_mod[0] = 1
frac_mod[1] = 1
frac_inv_mod[1] = 1

for i in range(2, 2*10**5+1):
    frac_mod[i] = frac_mod[i-1]*i % LARGE
    frac_inv_mod[i] = frac_inv_mod[i-1]*modinv(i, LARGE) % LARGE

B_lost_list = [0]*(B+W)
W_lost_list = [0]*(B+W)

def nCk_mod(n, k):
    return frac_mod[n]*frac_inv_mod[k]*frac_inv_mod[n-k] % LARGE

for n in range(B, B+W):
    B_lost_list[n] = nCk_mod(n-1, B-1)*modulo[n]
    
for n in range(W, B+W):
    W_lost_list[n] = nCk_mod(n-1, W-1)*modulo[n]
    

b = 0
w = 0
for i in range(B+W):
    b = (b + B_lost_list[i]) % LARGE
    w = (w + W_lost_list[i]) % LARGE
    
    print((500000004 + w * 500000004 - b * 500000004) % LARGE)