Problem p02782 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;

#define rep(i, n) for (int(i) = 0; (i) < (n); (i)++)
#define repn(i, n) for (int(i) = 1; (i) <= (n); (i)++)
#define repr(i, n) for (int(i) = (n - 1); (i) >= 0; (i)--)
#define all(x) (x).begin(), (x).end()
#define lint long long
#define ulint unsigned long long
#define fi first
#define se second
#define setpre(x) cout << fixed << setprecision(x)
#define ii(x)                                                                  \
  int x;                                                                       \
  cin >> (x)
#define ii2(x, y)                                                              \
  int x, y;                                                                    \
  cin >> (x) >> (y)
#define ii3(x, y, z)                                                           \
  int x, y, z;                                                                 \
  cin >> (x) >> (y) >> (z)
#define out(x) cout << (x) << endl
#define yn(x) cout << ((x) ? ("Yes") : ("No")) << endl
#define YN(x) cout << ((x) ? ("YES") : ("NO")) << endl
#define bit_c(x) __builtin_popcountll(x)

inline void logger() { cout << endl; }
template <typename A, typename... B> void logger(const A &a, const B &...b) {
  cout << a << " , ";
  logger(b...);
}

typedef pair<lint, lint> P;
const lint MOD = 1000000007;
const lint MOD9 = 998244353;
const lint INF = MOD * MOD;
const int MAX = 300000;

/* ...o(^-^)o... */

long long fac[MAX], facinv[MAX], inv[MAX];
void facinit() {
  fac[0] = fac[1] = 1;
  facinv[0] = facinv[1] = 1;
  inv[1] = 1;
  for (int i = 2; i < MAX; i++) {
    fac[i] = fac[i - 1] * i % MOD;
    inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
    facinv[i] = facinv[i - 1] * inv[i] % MOD;
  }
}

long long combi(long long a, long long b) {
  if (a < b)
    return 0;
  if (a < 0 || b < 0)
    return 0;
  return fac[a] * (facinv[b] * facinv[a - b] % MOD) % MOD;
}

int main() {
  lint r1, c1, r2, c2;
  cin >> r1 >> c1 >> r2 >> c2;
  facinit();
  lint ans = combi(r2 + c2 + 2, r2 + 1);
  ans += MOD - combi(r1 + c2 + 1, c2 + 1);
  ans %= MOD;
  ans += MOD - combi(r2 + c1 + 1, r2 + 1);
  ans %= MOD;
  ans += combi(r1 + c1, r1);
  ans %= MOD;
  out(ans);
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;

#define rep(i, n) for (int(i) = 0; (i) < (n); (i)++)
#define repn(i, n) for (int(i) = 1; (i) <= (n); (i)++)
#define repr(i, n) for (int(i) = (n - 1); (i) >= 0; (i)--)
#define all(x) (x).begin(), (x).end()
#define lint long long
#define ulint unsigned long long
#define fi first
#define se second
#define setpre(x) cout << fixed << setprecision(x)
#define ii(x)                                                                  \
  int x;                                                                       \
  cin >> (x)
#define ii2(x, y)                                                              \
  int x, y;                                                                    \
  cin >> (x) >> (y)
#define ii3(x, y, z)                                                           \
  int x, y, z;                                                                 \
  cin >> (x) >> (y) >> (z)
#define out(x) cout << (x) << endl
#define yn(x) cout << ((x) ? ("Yes") : ("No")) << endl
#define YN(x) cout << ((x) ? ("YES") : ("NO")) << endl
#define bit_c(x) __builtin_popcountll(x)

inline void logger() { cout << endl; }
template <typename A, typename... B> void logger(const A &a, const B &...b) {
  cout << a << " , ";
  logger(b...);
}

typedef pair<lint, lint> P;
const lint MOD = 1000000007;
const lint MOD9 = 998244353;
const lint INF = MOD * MOD;
const int MAX = 2000005;

/* ...o(^-^)o... */

long long fac[MAX], facinv[MAX], inv[MAX];
void facinit() {
  fac[0] = fac[1] = 1;
  facinv[0] = facinv[1] = 1;
  inv[1] = 1;
  for (int i = 2; i < MAX; i++) {
    fac[i] = fac[i - 1] * i % MOD;
    inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
    facinv[i] = facinv[i - 1] * inv[i] % MOD;
  }
}

long long combi(long long a, long long b) {
  if (a < b)
    return 0;
  if (a < 0 || b < 0)
    return 0;
  return fac[a] * (facinv[b] * facinv[a - b] % MOD) % MOD;
}

int main() {
  lint r1, c1, r2, c2;
  cin >> r1 >> c1 >> r2 >> c2;
  facinit();
  lint ans = combi(r2 + c2 + 2, r2 + 1);
  ans += MOD - combi(r1 + c2 + 1, c2 + 1);
  ans %= MOD;
  ans += MOD - combi(r2 + c1 + 1, r2 + 1);
  ans %= MOD;
  ans += combi(r1 + c1, r1);
  ans %= MOD;
  out(ans);
}