Problem p04046 (python)

Fixed submission:
h,w,a,b = map(int,input().split()) #入力
mod = 10**9+7 

#前計算　f[i] = i!
f=[1]
for i in range(h+w):
  f.append(f[i]*(i+1)%mod)

#C(n,r,p) = ( n! * r!^(p-2) * (n-r)!^(p-2) )%p
#pythonだとpow()で二分累乗法が使える
def comb(n, r, p):
  return f[n] * pow(f[r], p-2, p) * pow(f[n-r], p-2, p) % p

#紫点ごとに調べる
ans=0
for i in range(b, w):
  ans+= comb(h+i-a-1, i, mod) * comb(w-1-i+a-1, a-1, mod) % mod

print(ans%mod)

Buggy submission (verdict: Runtime Error):
h,w,a,b= map(int,input().split()) 
mod=10**9+7
f=[1]
for i in range(h+w):
  f.append(f[i]*(i+1)%mod)
def comb(n,r,p):
  return f[n]*pow(f[r],p-2,p)*pow(f[n-r],p-2,p)%p
ans=0
for i in range(w-b):
  ans+=comb(h-a+b-1+i,b+i,mod)*comb(h+a-b-2-i,a-1,mod)%mod
print(ans%mod)

Buggy submission (verdict: Runtime Error):
import numpy as np
import math
import sys
sys.float_info.max
H, W, A, B = map(int, input().split())

StoB = np.zeros(B)
BtoE = np.zeros(B)
sum = 0
# print(StoB)
# print(BtoE)
all = math.factorial(H + W - 2) / (math.factorial(H - 1) * math.factorial(W - 1))
# print(all)
for i in range(B):
    # print(i)
    # print(H - A)
    StoB[i] = math.factorial((i) + (H - A - 1)) / (math.factorial(i) * math.factorial(H - A - 1))
    # print(StoB[i])
# print(StoB)
    BtoE[i] = math.factorial((W - i) + A - 2) / (math.factorial(W - i - 1) * math.factorial(A - 1))
# print(BtoE)
    sum += StoB[i] * BtoE[i]
print(int(all - sum) % (10 ** 9 - 7))

Buggy submission (verdict: Runtime Error):
import numpy as np
import math
import sys
sys.float_info.max
H, W, A, B = map(int, input().split())

StoB = np.zeros(B)
BtoE = np.zeros(B)
sum = 0
# print(StoB)
# print(BtoE)
all = math.factorial(H + W - 2) / (math.factorial(H - 1) * math.factorial(W - 1))
# print(all)
for i in range(B):
    # print(i)
    # print(H - A)
    StoB[i] = math.factorial((i) + (H - A - 1)) / (math.factorial(i) * math.factorial(H - A - 1))
    # print(StoB[i])
# print(StoB)
    BtoE[i] = math.factorial((W - i) + A - 2) / (math.factorial(W - i - 1) * math.factorial(A - 1))
# print(BtoE)
    sum += StoB[i] * BtoE[i]
print(int(all - sum) / (10 ** 9 - 7))

Buggy submission (verdict: Runtime Error):
import numpy as np
import math
import sys
sys.float_info.max
H, W, A, B = map(int, input().split())

StoB = np.zeros(B)
BtoE = np.zeros(B)
sum = 0
# print(StoB)
# print(BtoE)
all = math.factorial(H + W - 2) / (math.factorial(H - 1) * math.factorial(W - 1))
# print(all)
for i in range(B):
    # print(i)
    # print(H - A)
    StoB[i] = math.factorial((i) + (H - A - 1)) / (math.factorial(i) * math.factorial(H - A - 1))
    # print(StoB[i])
# print(StoB)
    BtoE[i] = math.factorial((W - i) + A - 2) / (math.factorial(W - i - 1) * math.factorial(A - 1))
# print(BtoE)
    sum += StoB[i] * BtoE[i]
print(int(all - sum))

Buggy submission (verdict: Runtime Error):
import numpy as np
import math
import sys
sys.float_info.max
H, W, A, B = map(int, input().split())

StoB = np.zeros(B)
BtoE = np.zeros(B)
sum = 0
# print(StoB)
# print(BtoE)
all = math.factorial(H + W - 2) / (math.factorial(H - 1) * math.factorial(W - 1))
# print(all)
for i in range(B):
    # print(i)
    # print(H - A)
    StoB[i] = math.factorial((i) + (H - A - 1)) / (math.factorial(i) * math.factorial(H - A - 1))
    # print(StoB[i])
# print(StoB)
    BtoE[i] = math.factorial((W - i) + A - 2) / (math.factorial(W - i - 1) * math.factorial(A - 1))
# print(BtoE)
    sum += StoB[i] * BtoE[i]
print(all - sum)