Problem p02782 (C++)

Buggy submission (status: Runtime Error):
#define _USE_MATH_DEFINES
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <cstring>
#include <ctime>
#include <deque>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;

#define int long long
#define double long double
#define mp make_pair
#define all(a) a.begin(), a.end()
#define pb push_back
#define debug(x) cerr << #x << ": " << x << '\n';
#define ppoint(p) cout << #p << ' ' << p.x << ' ' << p.y << '\n';
#define fi first
#define se second
#define FOR(i, n) for (int i = 0; i < n; ++i)
// typedef long long ll;
typedef pair<int, int> pii;

template <typename T1, typename T2> inline bool chkmin(T1 &x, T2 y) {
  return y < x ? (x = y, true) : false;
};
template <typename T1, typename T2> inline bool chkmax(T1 &x, T2 y) {
  return y > x ? (x = y, true) : false;
};

void fast() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
}

const int mod = 1e9 + 7;
const int N = 1e6 + 10;
int f[N], rf[N];

int mult(int a, int b) { return a * b % mod; }

int c(int n, int k) { return mult(mult(f[n], rf[k]), rf[n - k]); }

int binpow(int a, int b) {
  if (b == 0)
    return 1;
  if (b & 1)
    return mult(binpow(a, b - 1), a);
  return binpow(mult(a, a), b / 2);
}

int get(int a, int b) {
  int res = 0;
  for (int i = 1; i <= a + 1; i++) {
    res += c(i + b, i);
  }
  return res;
}

int md(int x) {
  x %= mod;
  x += mod;
  x %= mod;
  return x;
}

signed main() {
  fast();
  f[0] = 1;
  for (int i = 1; i < N; i++)
    f[i] = mult(i, f[i - 1]);
  rf[N - 1] = binpow(f[N - 1], mod - 2);
  for (int i = N - 2; i >= 0; i--)
    rf[i] = mult(i + 1, rf[i + 1]);
  for (int i = N - 10; i <= N - 1; i++) {
    //	debug(mult(f[i], rf[i]))
  }
  int r1, r2, c1, c2;
  cin >> r1 >> c1 >> r2 >> c2;
  cout << md(get(r2, c2) - get(r1 - 1, c2) - get(r2, c1 - 1) +
             get(r1 - 1, c1 - 1))
       << '\n';
  return 0;
}

Fixed submission:
#define _USE_MATH_DEFINES
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <cstring>
#include <ctime>
#include <deque>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;

#define int long long
#define double long double
#define mp make_pair
#define all(a) a.begin(), a.end()
#define pb push_back
#define debug(x) cerr << #x << ": " << x << '\n';
#define ppoint(p) cout << #p << ' ' << p.x << ' ' << p.y << '\n';
#define fi first
#define se second
#define FOR(i, n) for (int i = 0; i < n; ++i)
// typedef long long ll;
typedef pair<int, int> pii;

template <typename T1, typename T2> inline bool chkmin(T1 &x, T2 y) {
  return y < x ? (x = y, true) : false;
};
template <typename T1, typename T2> inline bool chkmax(T1 &x, T2 y) {
  return y > x ? (x = y, true) : false;
};

void fast() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
}

const int mod = 1e9 + 7;
const int N = 2e6 + 10;
int f[N], rf[N];

int mult(int a, int b) { return a * b % mod; }

int c(int n, int k) { return mult(mult(f[n], rf[k]), rf[n - k]); }

int binpow(int a, int b) {
  if (b == 0)
    return 1;
  if (b & 1)
    return mult(binpow(a, b - 1), a);
  return binpow(mult(a, a), b / 2);
}

int get(int a, int b) {
  int res = 0;
  for (int i = 1; i <= a + 1; i++) {
    res += c(i + b, i);
  }
  return res;
}

int md(int x) {
  x %= mod;
  x += mod;
  x %= mod;
  return x;
}

signed main() {
  fast();
  f[0] = 1;
  for (int i = 1; i < N; i++)
    f[i] = mult(i, f[i - 1]);
  rf[N - 1] = binpow(f[N - 1], mod - 2);
  for (int i = N - 2; i >= 0; i--)
    rf[i] = mult(i + 1, rf[i + 1]);
  for (int i = N - 10; i <= N - 1; i++) {
    //	debug(mult(f[i], rf[i]))
  }
  int r1, r2, c1, c2;
  cin >> r1 >> c1 >> r2 >> c2;
  cout << md(get(r2, c2) - get(r1 - 1, c2) - get(r2, c1 - 1) +
             get(r1 - 1, c1 - 1))
       << '\n';
  return 0;
}