Problem p04046 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
/* typedef */
typedef long long ll;
typedef pair<int, int> pii;
/* constant */
const int INF = 1 << 30;
const ll LINF = 1LL << 50;
const int mod = 1000000007;
/* struct for mod Calculation*/
struct mint {
  ll x;
  mint(ll x = 0) : x((x % mod + mod) % mod) {}
  mint operator-() const { return mint(-x); }
  mint &operator+=(const mint a) {
    if ((x += a.x) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator-=(const mint a) {
    if ((x += mod - a.x) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator*=(const mint a) {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const {
    mint res(*this);
    return res += a;
  }
  mint operator-(const mint a) const {
    mint res(*this);
    return res -= a;
  }
  mint operator*(const mint a) const {
    mint res(*this);
    return res *= a;
  }
  mint pow(ll t) const {
    if (!t)
      return 1;
    mint a = pow(t >> 1);
    a *= a;
    if (t & 1)
      a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const { return pow(mod - 2); }
  mint &operator/=(const mint a) { return (*this) *= a.inv(); }
  mint operator/(const mint a) const {
    mint res(*this);
    return res /= a;
  }
};
/* global variables */
/* function */
struct Fact {
  // vector size : n + 1
  vector<mint> fact, ifact;
  // precaliculation O(n)
  Fact(int n) : fact(n + 1), ifact(n + 1) {
    assert(n < mod);
    // 0! = 1;
    fact[0] = 1;
    // 1! = 0! * 1 ... n! = (n-1)! * n
    for (int i = 1; i <= n; i++)
      fact[i] = fact[i - 1] * i;
    // 1/n! = n!^(-1)
    ifact[n] = fact[n].inv();
    // (n-1)!^(-1) = n!^(-1) * n ... 0!^(-1) = 1!^(-1) * 1
    for (int i = n; i >= 1; --i)
      ifact[i - 1] = ifact[i] * i;
  }
  mint operator()(int n, int k) { return fact[n + k] * ifact[n] * ifact[k]; }
};
/* global variables */
/* function */
/* main */
int main() {
  int H, W, A, B;
  cin >> H >> W >> A >> B;
  Fact f = Fact(100005);
  mint ans = 0;
  for (int i = B; i <= W - 1; i++) {
    ans += f(H - A - 1, i) * f(A - 1, W - i - 1);
  }
  cout << ans.x << '\n';
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
/* typedef */
typedef long long ll;
typedef pair<int, int> pii;
/* constant */
const int INF = 1 << 30;
const ll LINF = 1LL << 50;
const int mod = 1000000007;
/* struct for mod Calculation*/
struct mint {
  ll x;
  mint(ll x = 0) : x((x % mod + mod) % mod) {}
  mint operator-() const { return mint(-x); }
  mint &operator+=(const mint a) {
    if ((x += a.x) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator-=(const mint a) {
    if ((x += mod - a.x) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator*=(const mint a) {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const {
    mint res(*this);
    return res += a;
  }
  mint operator-(const mint a) const {
    mint res(*this);
    return res -= a;
  }
  mint operator*(const mint a) const {
    mint res(*this);
    return res *= a;
  }
  mint pow(ll t) const {
    if (!t)
      return 1;
    mint a = pow(t >> 1);
    a *= a;
    if (t & 1)
      a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const { return pow(mod - 2); }
  mint &operator/=(const mint a) { return (*this) *= a.inv(); }
  mint operator/(const mint a) const {
    mint res(*this);
    return res /= a;
  }
};
/* global variables */
/* function */
struct Fact {
  // vector size : n + 1
  vector<mint> fact, ifact;
  // precaliculation O(n)
  Fact(int n) : fact(n + 1), ifact(n + 1) {
    assert(n < mod);
    // 0! = 1;
    fact[0] = 1;
    // 1! = 0! * 1 ... n! = (n-1)! * n
    for (int i = 1; i <= n; i++)
      fact[i] = fact[i - 1] * i;
    // 1/n! = n!^(-1)
    ifact[n] = fact[n].inv();
    // (n-1)!^(-1) = n!^(-1) * n ... 0!^(-1) = 1!^(-1) * 1
    for (int i = n; i >= 1; --i)
      ifact[i - 1] = ifact[i] * i;
  }
  mint operator()(int n, int k) { return fact[n + k] * ifact[n] * ifact[k]; }
};
/* global variables */
/* function */
/* main */
int main() {
  int H, W, A, B;
  cin >> H >> W >> A >> B;
  Fact f = Fact(200005);
  mint ans = 0;
  for (int i = B; i <= W - 1; i++) {
    ans += f(H - A - 1, i) * f(A - 1, W - i - 1);
  }
  cout << ans.x << '\n';
}