Problem p02782 (C++)

Buggy submission (status: Runtime Error):
/*
AuThOr GaRyMr
*/
#include <bits/stdc++.h>
#define rb(a, b, c) for (int a = b; a <= c; ++a)
#define rl(a, b, c) for (int a = b; a >= c; --a)
#define LL long long
#define IT iterator
#define PB push_back
#define II(a, b) make_pair(a, b)
#define FIR first
#define SEC second
#define FREO freopen("check.out", "w", stdout)
#define rep(a, b) for (int a = 0; a < b; ++a)
#define KEEP while (1)
#define SRAND                                                                  \
  mt19937 rng(chrono::steady_clock::now().time_since_epoch().count())
#define random(a) rng() % a
#define ALL(a) a.begin(), a.end()
#define POB pop_back
#define ff fflush(stdout)
#define fastio ios::sync_with_stdio(false)
using namespace std;
const int INF = 0x3f3f3f3f;
typedef pair<int, int> mp;
typedef pair<mp, mp> superpair;
const int MAXN = 1e6, MOD = 1e9 + 7;
int r1, r2, c1, c2;
struct Combinatorics {
  LL fact[MAXN + 1] = {1};
  void INIT() { rb(i, 1, MAXN) fact[i] = fact[i - 1] * i, fact[i] %= MOD; }
  LL quick_pow(LL A, LL B) {
    if (!B)
      return 1;
    LL tmp = quick_pow(A, B >> 1);
    tmp *= tmp;
    tmp %= MOD;
    if (B & 1) {
      tmp *= A;
      tmp %= MOD;
    }
    return tmp;
  }
  LL inv(LL A) { return quick_pow(A, MOD - 2); }
  LL P(LL A, LL B) { return fact[B] * inv(fact[B - A]) % MOD; }
  LL C(LL A, LL B) { return P(A, B) * inv(fact[A]) % MOD; }
} com;
LL f(int i, int j) { return com.C(j, i + j); }
LL g(int i, int j) {
  // total in O(n)
  LL Res = 0;
  rb(I, 0, i) {
    Res += f(I + 1, j);
    //		cout<<I+1<<" "<<j<<" "<<com.C(2,3)<<endl;
    Res %= MOD;
  }
  //	cout<<Res<<endl;
  return Res;
}
int main() {
  fastio;
  com.INIT();
  cin >> r1 >> c1 >> r2 >> c2;
  //	cout<<g(1,1)<<endl;
  cout << (g(r2, c2) - g(r2, c1 - 1) - g(r1 - 1, c2) + g(r1 - 1, c1 - 1) + MOD +
           MOD) %
              MOD;
  return 0;
}


Fixed submission:
/*
AuThOr GaRyMr
*/
#include <bits/stdc++.h>
#define rb(a, b, c) for (int a = b; a <= c; ++a)
#define rl(a, b, c) for (int a = b; a >= c; --a)
#define LL long long
#define IT iterator
#define PB push_back
#define II(a, b) make_pair(a, b)
#define FIR first
#define SEC second
#define FREO freopen("check.out", "w", stdout)
#define rep(a, b) for (int a = 0; a < b; ++a)
#define KEEP while (1)
#define SRAND                                                                  \
  mt19937 rng(chrono::steady_clock::now().time_since_epoch().count())
#define random(a) rng() % a
#define ALL(a) a.begin(), a.end()
#define POB pop_back
#define ff fflush(stdout)
#define fastio ios::sync_with_stdio(false)
using namespace std;
const int INF = 0x3f3f3f3f;
typedef pair<int, int> mp;
typedef pair<mp, mp> superpair;
const int MAXN = 2e6 + 10, MOD = 1e9 + 7;
int r1, r2, c1, c2;
struct Combinatorics {
  LL fact[MAXN + 1] = {1};
  void INIT() { rb(i, 1, MAXN) fact[i] = fact[i - 1] * i, fact[i] %= MOD; }
  LL quick_pow(LL A, LL B) {
    if (!B)
      return 1;
    LL tmp = quick_pow(A, B >> 1);
    tmp *= tmp;
    tmp %= MOD;
    if (B & 1) {
      tmp *= A;
      tmp %= MOD;
    }
    return tmp;
  }
  LL inv(LL A) { return quick_pow(A, MOD - 2); }
  LL P(LL A, LL B) { return fact[B] * inv(fact[B - A]) % MOD; }
  LL C(LL A, LL B) { return P(A, B) * inv(fact[A]) % MOD; }
} com;
LL f(int i, int j) { return com.C(j, i + j); }
LL g(int i, int j) {
  // total in O(n)
  LL Res = 0;
  rb(I, 0, i) {
    Res += f(I + 1, j);
    //		cout<<I+1<<" "<<j<<" "<<com.C(2,3)<<endl;
    Res %= MOD;
  }
  //	cout<<Res<<endl;
  return Res;
}
int main() {
  fastio;
  com.INIT();
  cin >> r1 >> c1 >> r2 >> c2;
  //	cout<<g(1,1)<<endl;
  cout << (g(r2, c2) - g(r2, c1 - 1) - g(r1 - 1, c2) + g(r1 - 1, c1 - 1) + MOD +
           MOD) %
              MOD;
  return 0;
}