Problem p04046 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <bitset>
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <vector>
using namespace std;
typedef long long int ll;
#define bit(n, k) ((n >> k) & 1) /*nのk bit目*/

const int MOD = 1000000007;
const int CMAX = 110000;

struct ModInt {
  ll a;
  ModInt() : a(0) {}
  ModInt(ll x) {
    x %= MOD;
    if (x < 0)
      x += MOD;
    a = x;
  }

  ModInt operator+=(const ModInt p) {
    a += p.a;
    if (a >= MOD)
      a -= MOD;
    return *this;
  }
  ModInt operator-=(const ModInt p) {
    a -= p.a;
    if (a < 0)
      a += MOD;
    return *this;
  }
  ModInt operator*=(const ModInt p) {
    a = (a * p.a) % MOD;
    return *this;
  }

  ModInt operator+(const ModInt p) {
    ModInt x(a);
    return x += p;
  }
  ModInt operator-(const ModInt p) {
    ModInt x(a);
    return x -= p;
  }
  ModInt operator*(const ModInt p) {
    ModInt x(a);
    return x *= p;
  }
  ModInt operator=(ll p) {
    p %= MOD;
    if (p < 0)
      p += MOD;
    a = p;
    return *this;
  }

  bool operator==(const ModInt p) { return a == p.a; }

  bool operator!=(const ModInt p) { return a != p.a; }

  ModInt pow(ll N) {
    ModInt ans(1), p(a);
    while (N > 0) {
      if (bit(N, 0)) {
        ans *= p;
      }
      p *= p;
      N >>= 1;
    }
    return ans;
  }
  ModInt inverse() { return pow(MOD - 2); }
};

ModInt Mr(ll p) {
  p %= MOD;
  if (p < 0)
    p += MOD;
  ModInt x(p);
  return x;
}

ModInt fac[CMAX], finv[CMAX], inv[CMAX];

void COMinit() {
  fac[0] = fac[1] = 1;
  finv[0] = finv[1] = 1;
  inv[1] = 1;
  for (int i = 2; i < CMAX; i++) {
    fac[i] = fac[i - 1] * Mr(i);
    inv[i] = Mr(MOD) - inv[MOD % i] * Mr(MOD / i);
    finv[i] = finv[i - 1] * inv[i];
  }
}

ModInt COM(int n, int k) {
  if (n < k)
    return Mr(0);
  if (n < 0 || k < 0)
    return Mr(0);
  return fac[n] * finv[k] * finv[n - k];
}

signed main(void) {
  int H, W, A, B;
  cin >> H >> W >> A >> B;
  COMinit();
  ModInt ans(0);
  for (int i = 0; i <= H - A - 1; i++) {
    ans += COM(B + i - 1, i) * COM(W - B - 1 + H - 1 - i, H - 1 - i);
    // cout<<ans.a<<endl;
  }
  cout << ans.a << endl;
}

Fixed submission:
#include <algorithm>
#include <bitset>
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <vector>
using namespace std;
typedef long long int ll;
#define bit(n, k) ((n >> k) & 1) /*nのk bit目*/

const int MOD = 1000000007;
const int CMAX = 210000;

struct ModInt {
  ll a;
  ModInt() : a(0) {}
  ModInt(ll x) {
    x %= MOD;
    if (x < 0)
      x += MOD;
    a = x;
  }

  ModInt operator+=(const ModInt p) {
    a += p.a;
    if (a >= MOD)
      a -= MOD;
    return *this;
  }
  ModInt operator-=(const ModInt p) {
    a -= p.a;
    if (a < 0)
      a += MOD;
    return *this;
  }
  ModInt operator*=(const ModInt p) {
    a = (a * p.a) % MOD;
    return *this;
  }

  ModInt operator+(const ModInt p) {
    ModInt x(a);
    return x += p;
  }
  ModInt operator-(const ModInt p) {
    ModInt x(a);
    return x -= p;
  }
  ModInt operator*(const ModInt p) {
    ModInt x(a);
    return x *= p;
  }
  ModInt operator=(ll p) {
    p %= MOD;
    if (p < 0)
      p += MOD;
    a = p;
    return *this;
  }

  bool operator==(const ModInt p) { return a == p.a; }

  bool operator!=(const ModInt p) { return a != p.a; }

  ModInt pow(ll N) {
    ModInt ans(1), p(a);
    while (N > 0) {
      if (bit(N, 0)) {
        ans *= p;
      }
      p *= p;
      N >>= 1;
    }
    return ans;
  }
  ModInt inverse() { return pow(MOD - 2); }
};

ModInt Mr(ll p) {
  p %= MOD;
  if (p < 0)
    p += MOD;
  ModInt x(p);
  return x;
}

ModInt fac[CMAX], finv[CMAX], inv[CMAX];

void COMinit() {
  fac[0] = fac[1] = 1;
  finv[0] = finv[1] = 1;
  inv[1] = 1;
  for (int i = 2; i < CMAX; i++) {
    fac[i] = fac[i - 1] * Mr(i);
    inv[i] = Mr(MOD) - inv[MOD % i] * Mr(MOD / i);
    finv[i] = finv[i - 1] * inv[i];
  }
}

ModInt COM(int n, int k) {
  if (n < k)
    return Mr(0);
  if (n < 0 || k < 0)
    return Mr(0);
  return fac[n] * finv[k] * finv[n - k];
}

signed main(void) {
  int H, W, A, B;
  cin >> H >> W >> A >> B;
  COMinit();
  ModInt ans(0);
  for (int i = 0; i <= H - A - 1; i++) {
    ans += COM(B + i - 1, i) * COM(W - B - 1 + H - 1 - i, H - 1 - i);
    // cout<<ans.a<<endl;
  }
  cout << ans.a << endl;
}