Problem p04046 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define int llint
#define rep(i, a, n) for (int(i) = (int)(a); (i) < (int)(n); ++(i))
#define repe(i, a, n) for (int(i) = (int)(a); (i) <= (int)(n); ++(i))
#define repif(i, a, x) for (int(i) = (int)(a); (x); ++(i))
#define repr(i, a, n) for (int(i) = ((int)(a)-1); (i) >= (int)(n); --(i))
#define reper(i, a, n) for (int(i) = (int)(a); (i) >= (int)(n); --(i))
#define chmax(a, b) a = max(a, b)
#define chmin(a, b) a = min(a, b)
#define SIZE(x) ((int)(x).size())
#define ALL(x) (x).begin(), (x).end()
#define RNG(x, a, n) &((x)[a]), &((x)[n])
#define ADD(a, b) ((((a + MOD) % MOD) + ((b + MOD) % MOD)) % MOD)
#define MUL(a, b) ((((a) % MOD) * ((b) % MOD)) % MOD)
#define CEIL(x) ((int)ceil(((double)x)))
#define POW(x, y) ((int)pow(x, y))
#define UNIQUE(x) (x).erase(unique(ALL((x))), (x).end())
#define YES cout << "YES" << endl
#define NO cout << "NO" << endl
#define Yes cout << "Yes" << endl
#define No cout << "No" << endl
#define yes cout << "yes" << endl;
#define no cout << "no" << endl;
#define fcout cout << fixed << setprecision(10)
#define pb push_back
#define pf push_front
#define mp make_pair
#define mt make_tuple
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define EPS (1e-20)
#define INF INT_MAX
#define INFLL LLONG_MAX
#define MOD 1000000007
using llint = long long;
using VI = std::vector<int>;
using PII = std::pair<int, int>;
using SI = std::set<int>;
using MII = std::map<int, int>;
using TIII = std::tuple<int, int, int>;
using MCI = std::map<char, int>;
using VPII = std::vector<PII>;
using namespace std;

int H, W, A, B;
int fact[200010], invFact[200010];

void makeFact() {
  int N = 200010;
  fact[0] = 1;
  repe(i, 1, N) fact[i] = MUL(fact[i - 1], i);
  int M = MOD - 2;
  int pow = fact[N - 1];
  invFact[N - 1] = 1;
  do {
    if (M & 1)
      invFact[N - 1] = MUL(invFact[N - 1], pow);
    pow = MUL(pow, pow);
  } while (M >>= 1);
  repr(i, N - 1, 0) invFact[i] = MUL(invFact[i + 1], i + 1);
}

int comb(int n, int k) {
  if (n < 0 || k < 0 || n < k)
    return 0;
  return MUL(fact[n], MUL(invFact[k], invFact[n - k]));
}

int solve() {
  int ans = 0;
  rep(i, 0, H - A) ans =
      ADD(ans, comb(B - 1 + i, i) * comb(W - B - 1 + H - i - 1, W - B - 1));
  return ans;
}

signed main() {
  cin >> H >> W >> A >> B;

  makeFact();

  cout << solve() << endl;

  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
#define int llint
#define rep(i, a, n) for (int(i) = (int)(a); (i) < (int)(n); ++(i))
#define repe(i, a, n) for (int(i) = (int)(a); (i) <= (int)(n); ++(i))
#define repif(i, a, x) for (int(i) = (int)(a); (x); ++(i))
#define repr(i, a, n) for (int(i) = ((int)(a)-1); (i) >= (int)(n); --(i))
#define reper(i, a, n) for (int(i) = (int)(a); (i) >= (int)(n); --(i))
#define chmax(a, b) a = max(a, b)
#define chmin(a, b) a = min(a, b)
#define SIZE(x) ((int)(x).size())
#define ALL(x) (x).begin(), (x).end()
#define RNG(x, a, n) &((x)[a]), &((x)[n])
#define ADD(a, b) ((((a + MOD) % MOD) + ((b + MOD) % MOD)) % MOD)
#define MUL(a, b) ((((a) % MOD) * ((b) % MOD)) % MOD)
#define CEIL(x) ((int)ceil(((double)x)))
#define POW(x, y) ((int)pow(x, y))
#define UNIQUE(x) (x).erase(unique(ALL((x))), (x).end())
#define YES cout << "YES" << endl
#define NO cout << "NO" << endl
#define Yes cout << "Yes" << endl
#define No cout << "No" << endl
#define yes cout << "yes" << endl;
#define no cout << "no" << endl;
#define fcout cout << fixed << setprecision(10)
#define pb push_back
#define pf push_front
#define mp make_pair
#define mt make_tuple
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define EPS (1e-20)
#define INF INT_MAX
#define INFLL LLONG_MAX
#define MOD 1000000007
using llint = long long;
using VI = std::vector<int>;
using PII = std::pair<int, int>;
using SI = std::set<int>;
using MII = std::map<int, int>;
using TIII = std::tuple<int, int, int>;
using MCI = std::map<char, int>;
using VPII = std::vector<PII>;
using namespace std;

int H, W, A, B;
int fact[200010], invFact[200010];

void makeFact() {
  int N = 200010;
  fact[0] = 1;
  rep(i, 1, N) fact[i] = MUL(fact[i - 1], i);
  int M = MOD - 2;
  int pow = fact[N - 1];
  invFact[N - 1] = 1;
  do {
    if (M & 1)
      invFact[N - 1] = MUL(invFact[N - 1], pow);
    pow = MUL(pow, pow);
  } while (M >>= 1);
  repr(i, N - 1, 0) invFact[i] = MUL(invFact[i + 1], i + 1);
}

int comb(int n, int k) {
  if (n < 0 || k < 0 || n < k)
    return 0;
  return MUL(fact[n], MUL(invFact[k], invFact[n - k]));
}

int solve() {
  int ans = 0;
  rep(i, 0, H - A) ans =
      ADD(ans, comb(B - 1 + i, i) * comb(W - B - 1 + H - i - 1, W - B - 1));
  return ans;
}

signed main() {
  cin >> H >> W >> A >> B;

  makeFact();

  cout << solve() << endl;

  return 0;
}