Problem p04046 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
#define rep(i, a, n) for (int i = a; i < n; i++)
#define per(i, a, n) for (int i = n - 1; i >= a; i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
typedef vector<int> VI;
typedef long long ll;
typedef pair<int, int> PII;
const ll mod = 1000000007;
ll powmod(ll a, ll b) {
  ll res = 1;
  a %= mod;
  assert(b >= 0);
  for (; b; b >>= 1) {
    if (b & 1)
      res = res * a % mod;
    a = a * a % mod;
  }
  return res;
}
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
template <class T> ostream &operator<<(ostream &o, const vector<T> &v) {
  o << "{";
  for (int i = 0; i < (int)v.size(); i++)
    o << (i > 0 ? ", " : "") << v[i];
  o << "}";
  return o;
}
// head
struct edge {
  int to, cap, rev, cost;
};
vector<edge> G[1000];
void add_edge(int from, int to, int cap, int cost = 0) {
  G[from].push_back(edge{to, cap, (int)G[to].size(), cost});
  G[to].push_back(edge{from, 0, (int)G[from].size() - 1, -cost});
}

const int CMAX = 100001;
long long fact[CMAX] = {};
long long revFact[CMAX] = {};
void setFact(int N) {
  fact[0] = 1;
  for (int i = 1; i < N; i++) {
    fact[i] = fact[i - 1] * i;
    fact[i] %= mod;
  }
  revFact[N - 1] = powmod(fact[N - 1], mod - 2);
  for (int i = N - 2; i >= 0; i--) {
    revFact[i] = revFact[i + 1] * (i + 1);
    revFact[i] %= mod;
  }
}

long long getC(int a, int b) {
  return (((fact[a] * revFact[b]) % mod) * revFact[a - b]) % mod;
}

int main() {
  ll H, W, A, B;
  std::cin >> H >> W >> A >> B;
  setFact(CMAX);
  ll ans = 0;
  rep(i, B, W) {
    ans += getC(i + H - A - 1, H - A - 1) * getC(W - 1 - i + A - 1, A - 1);
    ans %= mod;
  }
  std::cout << ans << '\n';
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define rep(i, a, n) for (int i = a; i < n; i++)
#define per(i, a, n) for (int i = n - 1; i >= a; i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
typedef vector<int> VI;
typedef long long ll;
typedef pair<int, int> PII;
const ll mod = 1000000007;
ll powmod(ll a, ll b) {
  ll res = 1;
  a %= mod;
  assert(b >= 0);
  for (; b; b >>= 1) {
    if (b & 1)
      res = res * a % mod;
    a = a * a % mod;
  }
  return res;
}
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
template <class T> ostream &operator<<(ostream &o, const vector<T> &v) {
  o << "{";
  for (int i = 0; i < (int)v.size(); i++)
    o << (i > 0 ? ", " : "") << v[i];
  o << "}";
  return o;
}
// head
struct edge {
  int to, cap, rev, cost;
};
vector<edge> G[1000];
void add_edge(int from, int to, int cap, int cost = 0) {
  G[from].push_back(edge{to, cap, (int)G[to].size(), cost});
  G[to].push_back(edge{from, 0, (int)G[from].size() - 1, -cost});
}

const int CMAX = 200012;
long long fact[CMAX] = {};
long long revFact[CMAX] = {};
void setFact(int N) {
  fact[0] = 1;
  for (int i = 1; i < N; i++) {
    fact[i] = fact[i - 1] * i;
    fact[i] %= mod;
  }
  revFact[N - 1] = powmod(fact[N - 1], mod - 2);
  for (int i = N - 2; i >= 0; i--) {
    revFact[i] = revFact[i + 1] * (i + 1);
    revFact[i] %= mod;
  }
}

long long getC(int a, int b) {
  return (((fact[a] * revFact[b]) % mod) * revFact[a - b]) % mod;
}

int main() {
  ll H, W, A, B;
  std::cin >> H >> W >> A >> B;
  setFact(CMAX);
  ll ans = 0;
  rep(i, B, W) {
    ans += getC(i + H - A - 1, H - A - 1) * getC(W - 1 - i + A - 1, A - 1);
    ans %= mod;
  }
  std::cout << ans << '\n';
}