class Factorial:
    def __init__(self, max_fact, mod):
        #mod should be prime number
        #using homogeneous_product(n,r), max_fact ≧ max(n+r-1)
        f = [1] * (max_fact + 1)
        for idx in range(2, max_fact + 1):
            f[idx] = f[idx - 1] * idx
            f[idx] %= mod
        if mod > max_fact:
            fi = [pow(f[-1], mod - 2, mod)]
            for idx in range(max_fact, 0, -1):
                fi += [fi[-1] * idx % mod]
            fi = fi[::-1]
        else:
            fi = [pow(n, mod - 2, mod) for n in f]
        self.mod = mod
        self.f = f
        self.fi = fi

    def factorial(self, n):
        return self.f[n]

    def factorial_inverse(self, n):
        return self.fi[n]

    def combination(self, n, r):
        f = self.f
        fi = self.fi
        return f[n] * fi[r] * fi[n - r] % self.mod

    def permutation(self, n, r):
        return self.f[n] * self.fi[n - r] % self.mod

    def homogeneous_product(self, n, r):
        f = self.f
        fi = self.fi
        return f[n + r - 1] * fi[r] * fi[n - 1] % self.mod

max_fact = 2 * 10 ** 6
mod = 10**9 + 7
fact_instance = Factorial(max_fact, mod)
comb = fact_instance.combination
perm = fact_instance.permutation
combrep = fact_instance.homogeneous_product

H, W, A, B = [int(_) for _ in input().split()]
ans = comb(H + W - 2, H - 1)
for x in range(H - A, H):
    ans -= comb(x + B - 1, B - 1) * comb(H - 2 - x + W - B, W - B - 1)
    ans %= mod
print(ans)

SIZE=2*10**5; MOD=10**9+7 #998244353 #ここを変更する

SIZE += 1
inv = [0]*SIZE  # inv[j] = j^{-1} mod MOD
fac = [0]*SIZE  # fac[j] = j! mod MOD
finv = [0]*SIZE # finv[j] = (j!)^{-1} mod MOD
fac[0] = fac[1] = 1
finv[0] = finv[1] = 1
for i in range(2,SIZE):
    fac[i] = fac[i-1]*i%MOD
finv[-1] = pow(fac[-1],MOD-2,MOD)
for i in range(SIZE-1,0,-1):
    finv[i-1] = finv[i]*i%MOD
    inv[i] = finv[i]*fac[i-1]%MOD

def choose(n,r): # nCk mod MOD の計算
    if 0 <= r <= n:
        return (fac[n]*finv[r]%MOD)*finv[n-r]%MOD
    else:
        return 0

# coding: utf-8
# Your code here!
import sys
read = sys.stdin.read
readline = sys.stdin.readline

h,w,a,b = map(int,read().split())

ans = 0
for r in range(0,h-a):
    ans += choose(b-1+r,b-1)*choose(w-b-1+h-r-1,w-b-1)

print(ans%MOD)

Score : <var>400</var> points

Problem Statement

We have a large square grid with <var>H</var> rows and <var>W</var> 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 <var>A</var> rows and the leftmost <var>B</var> columns. (That is, there are <var>A×B</var> 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 <var>10^9+7</var>.

Constraints

<var> 1 ≦ H, W ≦ 100,000</var>

<var> 1 ≦ A < H</var>

<var> 1 ≦ B < W</var>

Input

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

<var>H</var> <var>W</var> <var>A</var> <var>B</var>

Output

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

Sample Input 1

2 3 1 1

Sample Output 1

2

We have a <var>2×3</var> 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 <var>12</var> forbidden cells.

Sample Input 3

100000 100000 99999 99999

Sample Output 3

1

Sample Input 4

100000 100000 44444 55555

Sample Output 4

738162020


import math

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

H,W,A,B=map(int,input().split())
f=[1]
M=10**9+7
for i in range(1,H+W):
  f.append(f[i-1]*i%M)
ans=0
for i in range(B,W):
  aa=(f[H-A-1+i]//(f[H-A-1] * f[i]))%M
  bb=(f[A+W-2-i]//(f[A-1]*f[W-1-i]))%M
  cc=(aa*bb)%M
  ans+=cc
  ans%=M
print(ans)