Problem:


Score : 400 points

Problem Statement

We have a large square grid with H rows and W columns.
Iroha is now standing in the top-left cell.
She will repeat going right or down to the adjacent cell, until she reaches the bottom-right cell.

However, she cannot enter the cells in the intersection of the bottom A rows and the leftmost B columns. (That is, there are A×B forbidden cells.) There is no restriction on entering the other cells.

Find the number of ways she can travel to the bottom-right cell.

Since this number can be extremely large, print the number modulo 10^9+7.

Constraints

 1 ≦ H, W ≦ 100,000

 1 ≦ A < H

 1 ≦ B < W

Input

The input is given from Standard Input in the following format:

H W A B

Output

Print the number of ways she can travel to the bottom-right cell, modulo 10^9+7.

Sample Input 1

2 3 1 1

Sample Output 1

2

We have a 2×3 grid, but entering the bottom-left cell is forbidden. The number of ways to travel is two: "Right, Right, Down" and "Right, Down, Right".

Sample Input 2

10 7 3 4

Sample Output 2

3570

There are 12 forbidden cells.

Sample Input 3

100000 100000 99999 99999

Sample Output 3

1

Sample Input 4

100000 100000 44444 55555

Sample Output 4

738162020



Sample input:
2 3 1 1


Sample output:
2

Submission status: Runtime Error

Solution code:
h,w,a,b= map(int,input().split())
k=h-a
l=b-1
print(k,l)
def fun(x,y,k,l):
    print(x,y,h,w)
    if(x== h-1 and y== w-1):
        return(1)
    else:
        kk=0
        #print(h,w,k,l)
        if(x+1 < h and y <w):
            if(x+1 >= k and y <= l):
                pass
            else:
                kk+=fun(x+1,y,k,l)
        if(x < h and y+1 <w):
            if(x >= k and y+1 <= l):
                pass
            else:
                kk+=fun(x,y+1,k,l)
        return(kk%1000000007)
print(fun(0,0,k,l))

Submission status: Runtime Error

Solution code:
import math
rows=int(input());
cols=int(input());
m=int(input());
n=int(input());

ans1=math.factorial(cols+rows-2)/((math.factorial(cols-1))*math.factorial(rows-1));
ans2=math.factorial(m+n-2)/((math.factorial(m-1))*math.factorial(n-1));
print(ans1-ans2)

Submission status: Runtime Error

Solution code:
import math

def comb(n, r):
    return f[n] // (f[n-r] * f[r])

H,W,A,B=map(int,input().split())
f=[1]
for i in range(1,100001):
  f.append(f[i-1]*i%M)
M=10**9+7
ans=0
for i in range(B,W):
  a=comb(H-A-1+i,i)%M
  b=comb(A+W-2-i,W-1-i)%M
  c=(a*b)%M
  ans+=c
  ans%=M
print(ans)

Submission status: Runtime Error

Solution code:
def comb(n, r):
    r = min(r, n-r)
    ret = 1

    for i in range(r):
        ret *= (n-i)/(r-i)
    return int(ret)


mod = 10**9+7


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

all_path = comb(H+W-2, H-1)

remove_path = 0
for i in range(B):
    tmp = comb(H-A+i, i)
    tmp *= comb(W-i-1, A-1)
    remove_path += tmp


print((all_path - remove_path) % mod)

Submission status: Runtime Error

Solution code:
mod = 1000000007
H, W, A, B = map(int, raw_input().split())

factorial = [1]
for n in range(1, H+W):
    factorial.append(factorial[n-1]*n%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 = [0] * (H+W)
inverseFactorial[H+W-1] = power(factorial[H+W-1], mod-2)
for n in range(H+W-2, -1, -1):
    inverseFactorial[n] = inverseFactorial[n+1] * (n+1) % mod

def combi(n, m):
    return factorial[n] * inverseFactorial[m] * inverseFactorial[n-m] % mod

sum = 0
for i in range(B+1, W+1):
    sum = (sum + combi(H-A-1+i-1, i-1) * combi(A-1+W-i, W-i)) % mod
print (sum)

Submission status: Runtime Error

Solution code:
import scipy.misc as scm

H, W, A, B = [int(input()) for _ in range(4)]
MOD = 10**9 + 7
f = [1]
a = [1]
for i in range(1, H+W-1):
    f.append((f[i-1] * i) % MOD)
    a.append(pow(f[i], MOD-2, MOD))
ans = 0
for i in range(B, W, 1):
    ans += (((f[(H-A-1)+i] * a[H-A-1] * a[i]) % MOD) * ((f[(A-1)+(W-1-i)] * a[A-1] * a[W-1-i]) % MOD))
    ans %= MOD
print(ans)

Submission status: Runtime Error

Solution code:
H, W, A, B = [int(input()) for _ in range(4)]
MOD = 10**9 + 7
f = [1]
a = [1]
for i in range(1, H+W-1):
    f.append((f[i-1] * i) % MOD)
    a.append(pow(f[i], MOD-2, MOD))
ans = 0
for i in range(B, W, 1):
    ans += (((f[(H-A-1)+i] * a[H-A-1] * a[i]) % MOD) * ((f[(A-1)+(W-1-i)] * a[A-1] * a[W-1-i]) % MOD))
    ans %= MOD
print(ans)

Submission status: Runtime Error

Solution code:
#H, W, A, B = [int(input()) for _ in range(4)]
MOD = 10**9 + 7
f = [1]
a = [1]
for i in range(1, H+W-1):
    f.append((f[i-1] * i) % MOD)
    a.append(pow(f[i], MOD-2, MOD))
ans = 0
for i in range(B, W, 1):
    ans += (((f[(H-A-1)+i] * a[H-A-1] * a[i]) % MOD) * ((f[(A-1)+(W-1-i)] * a[A-1] * a[W-1-i]) % MOD))
    ans %= MOD
print(ans)