prithivMLmods/Coder-Stat huggingface dataset:
Problem p02782 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
ll ans = 0;
const ll mo = 1000000007;
auto mod = [](ll modx) {
  modx %= mo;
  modx += mo;
  modx %= mo;
  return modx;
};
const ll MAX = 1000100;
const ll MOD = 1000000007;
long long fac[MAX], finv[MAX], inv[MAX];
void COMinit() {
  fac[0] = fac[1] = 1;
  finv[0] = finv[1] = 1;
  inv[1] = 1;
  for (ll i = 2; i < MAX; i++) {
    fac[i] = fac[i - 1] * i % MOD;
    inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
    finv[i] = finv[i - 1] * inv[i] % MOD;
  }
}
long long COM(ll n, ll k) {
  if (n < k)
    return 0;
  if (n < 0 || k < 0)
    return 0;
  return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
int main() {
  ll r, c, t, v;
  cin >> r >> c >> t >> v;
  COMinit();
  ans += COM(t + 1 + v + 1, v + 1) - 1;
  ans -= COM(r + v + 1, v + 1) - 1;
  ans -= COM(t + 1 + c, c) - 1;
  ans += COM(r + c, c) - 1;
  cout << mod(ans) << endl;
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
ll ans = 0;
const ll mo = 1000000007;
auto mod = [](ll modx) {
  modx %= mo;
  modx += mo;
  modx %= mo;
  return modx;
};
const ll MAX = 2000100;
const ll MOD = 1000000007;
long long fac[MAX], finv[MAX], inv[MAX];
void COMinit() {
  fac[0] = fac[1] = 1;
  finv[0] = finv[1] = 1;
  inv[1] = 1;
  for (ll i = 2; i < MAX; i++) {
    fac[i] = fac[i - 1] * i % MOD;
    inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
    finv[i] = finv[i - 1] * inv[i] % MOD;
  }
}
long long COM(ll n, ll k) {
  if (n < k)
    return 0;
  if (n < 0 || k < 0)
    return 0;
  return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
int main() {
  ll r, c, t, v;
  cin >> r >> c >> t >> v;
  COMinit();
  ans += COM(t + 1 + v + 1, v + 1) - 1;
  ans -= COM(r + v + 1, v + 1) - 1;
  ans -= COM(t + 1 + c, c) - 1;
  ans += COM(r + c, c) - 1;
  cout << mod(ans) << endl;
  return 0;
}
Problem p02782 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define fo(i, a, b) for (int i = (a); i <= (b); ++i)
#define rv(i, a, b) for (int i = (a); i >= (b); --i)
using namespace std;
const int M = 1200000;
const int md = 1e9 + 7;
typedef long long ll;
int n, m, k;
int fac[M], inv[M];
void ini() {
  inv[0] = inv[1] = 1;
  fac[0] = fac[1] = 1;
  fo(i, 2, M - 1) { inv[i] = 1ll * (md - md / i) * inv[md % i] % md; }
  fo(i, 2, M - 1) {
    inv[i] = 1ll * inv[i - 1] * inv[i] % md;
    fac[i] = 1ll * fac[i - 1] * i % md;
  }
}
ll C(int a, int b) {
  if (b < 0 || a < b)
    return 0;
  return 1ll * fac[a] * inv[a - b] % md * inv[b] % md;
}
ll f(int a, int b) { return C(a + b, a); }
int main() {
  ini();
  int r1, r2, c1, c2;
  cin >> r1 >> c1 >> r2 >> c2;
  ll ans = f(r1, c1);
  fo(i, r1 + 1, r2) ans = (ans + f(i, c2)) % md;
  fo(i, c1 + 1, c2) ans = (ans + f(r2, i)) % md;
  cout << ans << endl;
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
#define fo(i, a, b) for (int i = (a); i <= (b); ++i)
#define rv(i, a, b) for (int i = (a); i >= (b); --i)
using namespace std;
const int M = 2200000;
const int md = 1e9 + 7;
typedef long long ll;
int n, m, k;
int fac[M], inv[M];
void ini() {
  inv[0] = inv[1] = 1;
  fac[0] = fac[1] = 1;
  fo(i, 2, M - 1) { inv[i] = 1ll * (md - md / i) * inv[md % i] % md; }
  fo(i, 2, M - 1) {
    inv[i] = 1ll * inv[i - 1] * inv[i] % md;
    fac[i] = 1ll * fac[i - 1] * i % md;
  }
}
ll C(int a, int b) {
  if (b < 0 || a < b)
    return 0;
  return 1ll * fac[a] * inv[a - b] % md * inv[b] % md;
}
ll f(int a, int b) { return C(a + b, a); }
int main() {
  ini();
  int r1, r2, c1, c2;
  cin >> r1 >> c1 >> r2 >> c2;
  ll ans = f(r1, c1);
  fo(i, r1 + 1, r2) ans = (ans + f(i, c2)) % md;
  fo(i, c1 + 1, c2) ans = (ans + f(r2, i)) % md;
  cout << ans << endl;
  return 0;
}
Problem p02782 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MOD = 1000000007;

inline ll add(ll x, ll y) { return (x + y) % MOD; }
inline ll sub(ll x, ll y) {
  ll res = x - y;
  if (res < 0)
    res += MOD;
  return res;
}

const int MAX = 200005;
ll fac[MAX], finv[MAX], inv[MAX];

void COMinit() {
  fac[0] = fac[1] = 1;
  finv[0] = finv[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;
    finv[i] = finv[i - 1] * inv[i] % MOD;
  }
}

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

int main() {
  COMinit();
  int r1, c1, r2, c2;
  cin >> r1 >> c1 >> r2 >> c2;
  ll ans = 0;
  ans = add(ans, COM(r2 + c2 + 2, r2 + 1) - 1);
  ans = add(ans, COM(r1 + c1, r1) - 1);
  ans = sub(ans, COM(r2 + c1 + 1, r2 + 1) - 1);
  ans = sub(ans, COM(r1 + c2 + 1, r1) - 1);
  cout << ans << endl;
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MOD = 1000000007;

inline ll add(ll x, ll y) { return (x + y) % MOD; }
inline ll sub(ll x, ll y) {
  ll res = x - y;
  if (res < 0)
    res += MOD;
  return res;
}

const int MAX = 2000005;
ll fac[MAX], finv[MAX], inv[MAX];

void COMinit() {
  fac[0] = fac[1] = 1;
  finv[0] = finv[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;
    finv[i] = finv[i - 1] * inv[i] % MOD;
  }
}

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

int main() {
  COMinit();
  int r1, c1, r2, c2;
  cin >> r1 >> c1 >> r2 >> c2;
  ll ans = 0;
  ans = add(ans, COM(r2 + c2 + 2, r2 + 1) - 1);
  ans = add(ans, COM(r1 + c1, r1) - 1);
  ans = sub(ans, COM(r2 + c1 + 1, r2 + 1) - 1);
  ans = sub(ans, COM(r1 + c2 + 1, r1) - 1);
  cout << ans << endl;
  return 0;
}
Problem p02782 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
const int nmax = 1e6 + 5;
const int mod = 1e9 + 7;
int fact[nmax + 1], invfact[nmax + 1];
int modpow(int x, int y) {
  int ans = 1;
  while (y) {
    if (y & 1)
      ans = (1LL * ans * x) % mod;
    x = (1LL * x * x) % mod;
    y >>= 1;
  }
  return ans;
}
int nCr(int n, int r) {
  if (r > n)
    return 0;
  return (1LL * ((1LL * fact[n] * invfact[r]) % mod) * invfact[n - r]) % mod;
}
void preprocess() {
  fact[0] = 1;
  for (int i = 1; i <= nmax; i++) {
    fact[i] = (1LL * i * fact[i - 1]) % mod;
  }
  invfact[nmax] = modpow(fact[nmax], mod - 2);
  for (int i = nmax - 1; i >= 0; i--) {
    invfact[i] = (1LL * (i + 1) * invfact[i + 1]) % mod;
  }
}
int main() {
  int r1, c1, r2, c2;
  cin >> r1 >> c1 >> r2 >> c2;
  preprocess();
  long long ans = 0;
  for (int i = r1; i <= r2; i++) {
    ans += nCr(i + c2 + 1, i + 1);
    ans -= nCr(i + c1, i + 1);
    ans = (ans + mod) % mod;
  }
  cout << ans << "\n";
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
const int nmax = 2e6 + 5;
const int mod = 1e9 + 7;
int fact[nmax + 1], invfact[nmax + 1];
int modpow(int x, int y) {
  int ans = 1;
  while (y) {
    if (y & 1)
      ans = (1LL * ans * x) % mod;
    x = (1LL * x * x) % mod;
    y >>= 1;
  }
  return ans;
}
int nCr(int n, int r) {
  if (r > n)
    return 0;
  return (1LL * ((1LL * fact[n] * invfact[r]) % mod) * invfact[n - r]) % mod;
}
void preprocess() {
  fact[0] = 1;
  for (int i = 1; i <= nmax; i++) {
    fact[i] = (1LL * i * fact[i - 1]) % mod;
  }
  invfact[nmax] = modpow(fact[nmax], mod - 2);
  for (int i = nmax - 1; i >= 0; i--) {
    invfact[i] = (1LL * (i + 1) * invfact[i + 1]) % mod;
  }
}
int main() {
  int r1, c1, r2, c2;
  cin >> r1 >> c1 >> r2 >> c2;
  preprocess();
  long long ans = 0;
  for (int i = r1; i <= r2; i++) {
    ans += nCr(i + c2 + 1, i + 1);
    ans -= nCr(i + c1, i + 1);
    ans = (ans + mod) % mod;
  }
  cout << ans << "\n";
}
Problem p02782 (C++)

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

vector<long long> F, RF, R;
long long MOD = 1000000007;

void init(long long N) {
  F.resize(N + 1);
  RF.resize(N + 1);
  R.resize(N + 1);
  F[0] = F[1] = RF[0] = RF[1] = R[0] = R[1] = 1;
  for (int i = 2; i <= N; i++) {
    F[i] = (F[i - 1] * i) % MOD;
    R[i] = MOD - (R[MOD % i] * (MOD / i)) % MOD;
    RF[i] = (RF[i - 1] * R[i]) % MOD;
  }
}

long long Comb(long long N, long long M) {
  return (F[N] * ((RF[N - M] * RF[M]) % MOD)) % MOD;
}

int main() {
  long long R1, C1, R2, C2;
  cin >> R1 >> C1 >> R2 >> C2;
  R2++, C2++;
  init(200000);
  long long ANS = 0;
  ANS += Comb(R1 + C1, R1) - 1;
  ANS += Comb(R2 + C2, R2) - 1;
  ANS -= Comb(R1 + C2, R1) - 1;
  ANS -= Comb(R2 + C1, R2) - 1;
  ANS += MOD * 2;
  cout << ANS % MOD << endl;
}

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

vector<long long> F, RF, R;
long long MOD = 1000000007;

void init(long long N) {
  F.resize(N + 1);
  RF.resize(N + 1);
  R.resize(N + 1);
  F[0] = F[1] = RF[0] = RF[1] = R[0] = R[1] = 1;
  for (int i = 2; i <= N; i++) {
    F[i] = (F[i - 1] * i) % MOD;
    R[i] = MOD - (R[MOD % i] * (MOD / i)) % MOD;
    RF[i] = (RF[i - 1] * R[i]) % MOD;
  }
}

long long Comb(long long N, long long M) {
  return (F[N] * ((RF[N - M] * RF[M]) % MOD)) % MOD;
}

int main() {
  long long R1, C1, R2, C2;
  cin >> R1 >> C1 >> R2 >> C2;
  R2++, C2++;
  init(2000010);
  long long ANS = 0;
  ANS += Comb(R1 + C1, R1) - 1;
  ANS += Comb(R2 + C2, R2) - 1;
  ANS -= Comb(R1 + C2, R1) - 1;
  ANS -= Comb(R2 + C1, R2) - 1;
  ANS += MOD * 2;
  cout << ANS % MOD << endl;
}
Problem p02782 (C++)

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

using namespace std;

namespace {

constexpr size_t MOD = 1e9 + 7;
constexpr size_t MAX = 1e6 + 2;

size_t mod_pow(size_t x, size_t p) {
  size_t u = x;
  size_t t = 1;
  while (p) {
    if (p & 1) {
      t = t * u % MOD;
    }
    u = u * u % MOD;
    p >>= 1;
  }
  return t;
}

size_t mod_inv(size_t x) { return mod_pow(x, MOD - 2); }

vector<size_t> fact(MAX + 1), ifact(MAX + 1);

void init() {
  fact[0] = 1;
  for (size_t i = 1; i <= MAX; i++) {
    fact[i] = fact[i - 1] * i % MOD;
  }
  ifact[MAX] = mod_inv(fact[MAX]);
  for (long long i = MAX - 1; i >= 0; i--) {
    ifact[i] = ifact[i + 1] * (i + 1) % MOD;
  }
}

size_t mod_cmb(size_t x, size_t y) {
  return fact[x] * ifact[x - y] % MOD * ifact[y] % MOD;
}

} // namespace

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);

  init();

  int r1, r2, c1, c2;
  cin >> r1 >> c1 >> r2 >> c2;

  auto f = [&](int r, int c) { return mod_cmb(r + c, c); };
  auto g = [&](int r, int c) { return f(r + 1, c + 1) - f(r, 0); };

  auto ans = g(r2, c2);
  ans = ans + MOD - g(r1 - 1, c2);
  ans %= MOD;
  ans = ans + MOD - g(r2, c1 - 1);
  ans %= MOD;
  ans = ans + g(r1 - 1, c1 - 1);
  ans %= MOD;

  cout << ans << endl;

  return 0;
}


Fixed submission:
#include <bits/stdc++.h>

using namespace std;

namespace {

constexpr size_t MOD = 1e9 + 7;
constexpr size_t MAX = 2e6 + 2;

size_t mod_pow(size_t x, size_t p) {
  size_t u = x;
  size_t t = 1;
  while (p) {
    if (p & 1) {
      t = t * u % MOD;
    }
    u = u * u % MOD;
    p >>= 1;
  }
  return t;
}

size_t mod_inv(size_t x) { return mod_pow(x, MOD - 2); }

vector<size_t> fact(MAX + 1), ifact(MAX + 1);

void init() {
  fact[0] = 1;
  for (size_t i = 1; i <= MAX; i++) {
    fact[i] = fact[i - 1] * i % MOD;
  }
  ifact[MAX] = mod_inv(fact[MAX]);
  for (long long i = MAX - 1; i >= 0; i--) {
    ifact[i] = ifact[i + 1] * (i + 1) % MOD;
  }
}

size_t mod_cmb(size_t x, size_t y) {
  return fact[x] * ifact[x - y] % MOD * ifact[y] % MOD;
}

} // namespace

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);

  init();

  int r1, r2, c1, c2;
  cin >> r1 >> c1 >> r2 >> c2;

  auto f = [&](int r, int c) { return mod_cmb(r + c, c); };
  auto g = [&](int r, int c) { return f(r + 1, c + 1) - f(r, 0); };

  auto ans = g(r2, c2);
  ans = ans + MOD - g(r1 - 1, c2);
  ans %= MOD;
  ans = ans + MOD - g(r2, c1 - 1);
  ans %= MOD;
  ans = ans + g(r1 - 1, c1 - 1);
  ans %= MOD;

  cout << ans << endl;

  return 0;
}
Problem p02782 (C++)

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

#define REP(i, x, n) for (int i = x; i < (int)(n); i++)
#define rep(i, n) REP(i, 0, n)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) (int)(x.size())
#define popcount(x) __builtin_popcount(x)
#define popcountll(x) __builtin_popcountll(x)
#define uniq(x) x.erase(unique(x.begin(), x.end()), x.end())
#define F first
#define S second
#define mp make_pair
#define eb emplace_back
#define pii pair<int, int>
#define pll pair<ll, ll>

using namespace std;

typedef long long ll;

/* --- INFやMODの値が適切か確認する --- */
// const int INF = 1 << 30;
// const ll INF = 1LL << 60;
const ll MOD = 1000000007;

const int MAX = 1000005;
ll modFact[MAX];
ll modInv[MAX];
ll modFactInv[MAX];

// calc nCr % mod
ll comb(int n, int r) {
  return modFact[n] * (modFactInv[r] * modFactInv[n - r] % MOD) % MOD;
}

int main() {
  modFact[0] = modFact[1] = 1;
  modFactInv[0] = modFactInv[1] = 1;
  modInv[1] = 1;
  REP(i, 2, MAX) {
    modFact[i] = modFact[i - 1] * i % MOD;
    modInv[i] = MOD - modInv[MOD % i] * (MOD / i) % MOD;
    modFactInv[i] = modFactInv[i - 1] * modInv[i] % MOD;
  }

  int r1, c1, r2, c2;
  cin >> r1 >> c1 >> r2 >> c2;

  ll ans = 0;
  for (int i = c1; i <= c2; i++) {
    ans = (ans + comb(r2 + i + 1, i + 1)) % MOD;
    ans = (ans + MOD - comb(r1 - 1 + i + 1, i + 1)) % MOD;
  }

  cout << ans << endl;
}


Fixed submission:
#include <bits/stdc++.h>

#define REP(i, x, n) for (int i = x; i < (int)(n); i++)
#define rep(i, n) REP(i, 0, n)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) (int)(x.size())
#define popcount(x) __builtin_popcount(x)
#define popcountll(x) __builtin_popcountll(x)
#define uniq(x) x.erase(unique(x.begin(), x.end()), x.end())
#define F first
#define S second
#define mp make_pair
#define eb emplace_back
#define pii pair<int, int>
#define pll pair<ll, ll>

using namespace std;

typedef long long ll;

/* --- INFやMODの値が適切か確認する --- */
// const int INF = 1 << 30;
// const ll INF = 1LL << 60;
const ll MOD = 1000000007;

const int MAX = 2000005;
ll modFact[MAX];
ll modInv[MAX];
ll modFactInv[MAX];

// calc nCr % mod
ll comb(int n, int r) {
  return modFact[n] * (modFactInv[r] * modFactInv[n - r] % MOD) % MOD;
}

int main() {
  modFact[0] = modFact[1] = 1;
  modFactInv[0] = modFactInv[1] = 1;
  modInv[1] = 1;
  REP(i, 2, MAX) {
    modFact[i] = modFact[i - 1] * i % MOD;
    modInv[i] = MOD - modInv[MOD % i] * (MOD / i) % MOD;
    modFactInv[i] = modFactInv[i - 1] * modInv[i] % MOD;
  }

  int r1, c1, r2, c2;
  cin >> r1 >> c1 >> r2 >> c2;

  ll ans = 0;
  for (int i = c1; i <= c2; i++) {
    ans = (ans + comb(r2 + i + 1, i + 1)) % MOD;
    ans = (ans + MOD - comb(r1 - 1 + i + 1, i + 1)) % MOD;
  }

  cout << ans << endl;
}
Problem p02782 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define ll long long
#define MAX 1000005
#define P ((ll)1e9 + 7)
using namespace std;

ll qpow(ll a, ll n) {
  ll res = 1;
  while (n) {
    if (n & 1)
      res = res * a % P;
    a = a * a % P;
    n >>= 1;
  }
  return res;
}

ll fac[MAX], inv[MAX];

void init() {
  fac[0] = 1;
  for (int i = 1; i < MAX; i++) {
    fac[i] = fac[i - 1] * i % P;
  }
  inv[MAX - 1] = qpow(fac[MAX - 1], P - 2);
  for (int i = MAX - 2; i >= 0; i--) {
    inv[i] = inv[i + 1] * (i + 1) % P;
  }
}

ll C(ll n, ll m) {
  if (!m)
    return 1;
  return fac[n] * inv[m] % P * inv[n - m] % P;
}

ll calc(ll x, ll l, ll r) { return (C(r + 1, x + 1) - C(l, x + 1) + P) % P; }

int main() {
  init();
  ll x1, y1, x2, y2, ans = 0;
  cin >> x1 >> y1 >> x2 >> y2;
  for (int i = x1; i <= x2; i++) {
    ans = (ans + calc(i, i + y1, i + y2)) % P;
  }
  cout << ans << endl;

  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
#define ll long long
#define MAX 4000005
#define P ((ll)1e9 + 7)
using namespace std;

ll qpow(ll a, ll n) {
  ll res = 1;
  while (n) {
    if (n & 1)
      res = res * a % P;
    a = a * a % P;
    n >>= 1;
  }
  return res;
}

ll fac[MAX], inv[MAX];

void init() {
  fac[0] = 1;
  for (int i = 1; i < MAX; i++) {
    fac[i] = fac[i - 1] * i % P;
  }
  inv[MAX - 1] = qpow(fac[MAX - 1], P - 2);
  for (int i = MAX - 2; i >= 0; i--) {
    inv[i] = inv[i + 1] * (i + 1) % P;
  }
}

ll C(ll n, ll m) {
  if (!m)
    return 1;
  return fac[n] * inv[m] % P * inv[n - m] % P;
}

ll calc(ll x, ll l, ll r) { return (C(r + 1, x + 1) - C(l, x + 1) + P) % P; }

int main() {
  init();
  ll x1, y1, x2, y2, ans = 0;
  cin >> x1 >> y1 >> x2 >> y2;
  for (int i = x1; i <= x2; i++) {
    ans = (ans + calc(i, i + y1, i + y2)) % P;
  }
  cout << ans << endl;

  return 0;
}
Problem p02782 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <utility>
#include <vector>
typedef long long ll;
typedef long double ld;
using namespace std;

ll mod = 1000000007;
const int SIZE = 1000010;
ll fac[SIZE], finv[SIZE], inv[SIZE];
void COMinit(ll m) {
  fac[0] = fac[1] = 1;
  finv[0] = finv[1] = 1;
  inv[1] = 1;
  for (int i = 2; i < SIZE; ++i) {
    fac[i] = (fac[i - 1] * i) % m;
    inv[i] = m - (inv[m % i] * (m / i)) % m;
    finv[i] = (finv[i - 1] * inv[i]) % m;
  }
}
ll COM(int n, int k, ll m) {
  if (n < k)
    return 0;
  if (n < 0 || k < 0)
    return 0;
  return (fac[n] * ((finv[k] * finv[n - k]) % m)) % m;
}
ll solve(int R, int C) { return (COM(R + C + 2, R + 1, mod) + mod - 1) % mod; }

int main() {
  int r1, c1, r2, c2;
  cin >> r1 >> c1 >> r2 >> c2;
  COMinit(mod);
  cout << (solve(r2, c2) + solve(r1 - 1, c1 - 1) + mod * 2 - solve(r2, c1 - 1) -
           solve(r1 - 1, c2)) %
              mod
       << endl;
  return 0;
}

Fixed submission:
#include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <utility>
#include <vector>
typedef long long ll;
typedef long double ld;
using namespace std;

ll mod = 1000000007;
const int SIZE = 2000010;
ll fac[SIZE], finv[SIZE], inv[SIZE];
void COMinit(ll m) {
  fac[0] = fac[1] = 1;
  finv[0] = finv[1] = 1;
  inv[1] = 1;
  for (int i = 2; i < SIZE; ++i) {
    fac[i] = (fac[i - 1] * i) % m;
    inv[i] = m - (inv[m % i] * (m / i)) % m;
    finv[i] = (finv[i - 1] * inv[i]) % m;
  }
}
ll COM(int n, int k, ll m) {
  if (n < k)
    return 0;
  if (n < 0 || k < 0)
    return 0;
  return (fac[n] * ((finv[k] * finv[n - k]) % m)) % m;
}
ll solve(int R, int C) { return (COM(R + C + 2, R + 1, mod) + mod - 1) % mod; }

int main() {
  int r1, c1, r2, c2;
  cin >> r1 >> c1 >> r2 >> c2;
  COMinit(mod);
  cout << (solve(r2, c2) + solve(r1 - 1, c1 - 1) + mod * 2 - solve(r2, c1 - 1) -
           solve(r1 - 1, c2)) %
              mod
       << endl;
  return 0;
}
Problem p02782 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
#define rep(i, a, b) for (int i = (a); i < (b); i++)
#define rrep(i, a, b) for (int i = (a); i >= (b); i--)
typedef long long ll;
const ll mod = 1000000007;

const int MAX = 2100000;
ll fac[MAX], finv[MAX], inv[MAX];

void cominit() {
  fac[0] = fac[1] = 1;
  finv[0] = finv[1] = 1;
  inv[1] = 1;
  for (ll i = 2; i < MAX; i++) {
    fac[i] = fac[i - 1] * i % mod;
    inv[i] = mod - inv[mod % i] * (mod / i) % mod;
    finv[i] = finv[i - 1] * inv[i] % mod;
  }
}

ll com(ll n, ll k) {
  if (n < k)
    return 0;
  if (n < 0 || k < 0)
    return 0;
  return fac[n] * (finv[k] * finv[n - k] % mod) % mod;
}

int main() {
  ll r1, c1, r2, c2;
  cin >> r1 >> c1 >> r2 >> c2;
  cominit();
  ll ans = 0;
  for (int i = r1; i <= r2; i++) {
    for (int j = c1; j <= c2; j++) {
      ans = (ans + com(i + j, i)) % mod;
    }
  }
  vector<ll> x(r2 + 1, 0);
  for (int i = r1; i <= r2; i++) {
  }
  cout << ans << endl;

  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define rep(i, a, b) for (int i = (a); i < (b); i++)
#define rrep(i, a, b) for (int i = (a); i >= (b); i--)
typedef long long ll;
const ll mod = 1000000007;

const int MAX = 2100000;
ll fac[MAX], finv[MAX], inv[MAX];

void cominit() {
  fac[0] = fac[1] = 1;
  finv[0] = finv[1] = 1;
  inv[1] = 1;
  for (ll i = 2; i < MAX; i++) {
    fac[i] = fac[i - 1] * i % mod;
    inv[i] = mod - inv[mod % i] * (mod / i) % mod;
    finv[i] = finv[i - 1] * inv[i] % mod;
  }
}

ll com(ll n, ll k) {
  if (n < k)
    return 0;
  if (n < 0 || k < 0)
    return 0;
  return fac[n] * (finv[k] * finv[n - k] % mod) % mod;
}

int main() {
  ll r1, c1, r2, c2;
  cin >> r1 >> c1 >> r2 >> c2;
  cominit();
  ll ans = 0;
  ans += com(r2 + c2 + 2, c2 + 1);
  ans -= com(r1 + c2 + 1, r1);
  ans -= com(r2 + c1 + 1, r2 + 1);
  ans += com(r1 + c1, r1);
  ans = (ans + mod) % mod;
  cout << ans << endl;

  return 0;
}
Problem p02782 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
const int MAX = 1000001;
const int MOD = 1000000007;
long long fac[MAX], finv[MAX], inv[MAX];

void COMinit() {
  fac[0] = fac[1] = 1;
  finv[0] = finv[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;
    finv[i] = finv[i - 1] * inv[i] % MOD;
  }
}

long long COM(int n, int k) {
  if (n < k)
    return 0;
  if (n < 0 || k < 0)
    return 0;
  return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
int main() {
  int r1, c1, r2, c2;
  cin >> r1 >> c1 >> r2 >> c2;
  COMinit();
  long long ans = COM(r2 + c2 + 2, r2 + 1) - COM(r1 + c2 + 1, r1) -
                  COM(r2 + c1 + 1, r2 + 1) + COM(r1 + c1, r1);
  ans = (ans + MOD) % MOD;
  cout << ans << endl;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
const int MAX = 2000003;
const int MOD = 1000000007;
long long fac[MAX], finv[MAX], inv[MAX];

void COMinit() {
  fac[0] = fac[1] = 1;
  finv[0] = finv[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;
    finv[i] = finv[i - 1] * inv[i] % MOD;
  }
}

long long COM(int n, int k) {
  if (n < k)
    return 0;
  if (n < 0 || k < 0)
    return 0;
  return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
int main() {
  int r1, c1, r2, c2;
  cin >> r1 >> c1 >> r2 >> c2;
  COMinit();
  long long ans = COM(r2 + c2 + 2, r2 + 1) - COM(r1 + c2 + 1, r1) -
                  COM(r2 + c1 + 1, r2 + 1) + COM(r1 + c1, r1);
  ans = (ans + MOD) % MOD;
  cout << ans << endl;
}
Problem p02782 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define rep(i, x, y) for (int i = x; i <= y; i++)
using namespace std;

const int N = 1e6 + 10, mod = 1e9 + 7;
typedef long long ll;
ll r1, c1, r2, c2, n;
ll a1, a2, a3, a4;
ll fac[N], inv[N];

ll quick_pow(ll a, ll b) {
  ll ret = 1;
  for (; b; b >>= 1) {
    if (b & 1)
      ret = ret * a % mod;
    a = a * a % mod;
  }
  return ret;
}

ll C(ll n, ll m) { return fac[n] * inv[m] % mod * inv[n - m] % mod; }

ll calc(ll r, ll c) {
  ll ret = 0;
  rep(i, 0, r) ret = (ret + C(i + c + 1, c)) % mod;
  return ret;
}

int main() {
  cin >> r1 >> c1 >> r2 >> c2;

  n = r2 + c2 + 2;
  fac[0] = inv[0] = 1;
  rep(i, 1, n) fac[i] = (fac[i - 1] * i) % mod;
  inv[n] = quick_pow(fac[n], mod - 2);
  for (int i = n; i >= 1; i--)
    inv[i - 1] = inv[i] * i % mod;

  a1 = calc(r2, c2);
  a2 = calc(r1 - 1, c2);
  a3 = calc(r2, c1 - 1);
  a4 = calc(r1 - 1, c1 - 1);
  printf("%lld\n", (a1 - a2 - a3 + a4 + mod) % mod);
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
#define rep(i, x, y) for (int i = x; i <= y; i++)
using namespace std;

const int N = 2e6 + 10, mod = 1e9 + 7;
typedef long long ll;
ll r1, c1, r2, c2, n;
ll a1, a2, a3, a4;
ll fac[N], inv[N];

ll quick_pow(ll a, ll b) {
  ll ret = 1;
  for (; b; b >>= 1) {
    if (b & 1)
      ret = ret * a % mod;
    a = a * a % mod;
  }
  return ret;
}

ll C(ll n, ll m) { return fac[n] * inv[m] % mod * inv[n - m] % mod; }

ll calc(ll r, ll c) {
  ll ret = 0;
  rep(i, 0, r) ret = (ret + C(i + c + 1, c)) % mod;
  return ret;
}

int main() {
  cin >> r1 >> c1 >> r2 >> c2;

  n = r2 + c2 + 2;
  fac[0] = inv[0] = 1;
  rep(i, 1, n) fac[i] = (fac[i - 1] * i) % mod;
  inv[n] = quick_pow(fac[n], mod - 2);
  for (int i = n; i >= 1; i--)
    inv[i - 1] = inv[i] * i % mod;

  a1 = calc(r2, c2);
  a2 = calc(r1 - 1, c2);
  a3 = calc(r2, c1 - 1);
  a4 = calc(r1 - 1, c1 - 1);
  printf("%lld\n", (a1 - a2 - a3 + a4 + mod) % mod);
  return 0;
}
Problem p02782 (C++)

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

const int N = 1e6 + 20, MOD = (int)(1e9) + 7;

int f[N], ie[N], n1, m1, n2, m2;

int power(int a, int b) {
  int num = a, ans = 1;
  for (int i = 0; i < 31; i++) {
    if (b & (1 << i))
      ans = (1ll * ans * num) % MOD;
    num = (1ll * num * num) % MOD;
  }
  return ans;
}

int inverse_euler(int n) { return power(n, MOD - 2); }

int ncr(int n, int r) {
  return (1LL * f[n] * ((1LL * ie[r] * ie[n - r]) % MOD)) % MOD;
}

void precompute() {
  f[0] = 1;
  for (int i = 1; i < N; i++)
    f[i] = (1LL * f[i - 1] * i) % MOD;
  for (int i = 0; i < N; i++)
    ie[i] = inverse_euler(f[i]);
}

long long fn(long long n, long long m) {
  long long ans = 0;
  for (int i = 0; i <= n; i++)
    ans = (ans + ncr(i + m + 1, m)) % MOD;
  return ans;
}

int main() {
  precompute();

  cin >> n1 >> m1 >> n2 >> m2;
  cout << (fn(n2, m2) - fn(n1 - 1, m2) - fn(n2, m1 - 1) + fn(n1 - 1, m1 - 1) +
           3LL * MOD) %
              MOD;
}

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

const int N = 2e6 + 20, MOD = (int)(1e9) + 7;

int f[N], ie[N], n1, m1, n2, m2;

int power(int a, int b) {
  int num = a, ans = 1;
  for (int i = 0; i < 31; i++) {
    if (b & (1 << i))
      ans = (1ll * ans * num) % MOD;
    num = (1ll * num * num) % MOD;
  }
  return ans;
}

int inverse_euler(int n) { return power(n, MOD - 2); }

int ncr(int n, int r) {
  return (1LL * f[n] * ((1LL * ie[r] * ie[n - r]) % MOD)) % MOD;
}

void precompute() {
  f[0] = 1;
  for (int i = 1; i < N; i++)
    f[i] = (1LL * f[i - 1] * i) % MOD;
  for (int i = 0; i < N; i++)
    ie[i] = inverse_euler(f[i]);
}

long long fn(long long n, long long m) {
  long long ans = 0;
  for (int i = 0; i <= n; i++)
    ans = (ans + ncr(i + m + 1, m)) % MOD;
  return ans;
}

int main() {
  precompute();

  cin >> n1 >> m1 >> n2 >> m2;
  cout << (fn(n2, m2) - fn(n1 - 1, m2) - fn(n2, m1 - 1) + fn(n1 - 1, m1 - 1) +
           3LL * MOD) %
              MOD;
}
Problem p02782 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL_DEBUG
#include "LOCAL_DEBUG.hpp"
#endif
#define int long long

struct Combination {
  const int MOD = 1e9 + 7;

  vector<int> fact; // 　fact[i] = iの階乗
  void init(int n) {
    fact.resize(n + 1);
    fact[0] = fact[1] = 1;
    for (int i = 2; i <= n; i++) {
      fact[i] = i * fact[i - 1] % MOD;
    }
  }

  int nCr(int n, int r) { // nCr = n!/r!(n-r)!
    if (n < r)
      return 0;
    return fact[n] * mod_pow(fact[r] * fact[n - r] % MOD, MOD - 2) % MOD;
  }

  int mod_pow(int n, int p) { // a/n ≡ a*n^(p-2) nとpは互いに素
    int r = 1;
    for (; p > 0; p >>= 1) {
      if (p & 1LL)
        r = (r * n) % MOD;
      n = (n * n) % MOD;
    }
    return r; // r = n^p % MOD
  }

} comb;

const int MOD = 1e9 + 7;

signed main() {

  int x, y, p, q;
  cin >> x >> y >> p >> q;

  comb.init(1e6);
  int ans = comb.nCr(p + 1 + q + 1, p + 1) - 1 - comb.nCr(x + q + 1, x) + 1 +
            MOD - comb.nCr(p + y + 1, y) + 1 + comb.nCr(x + y, x) - 1;
  cout << ans % MOD << endl;

  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL_DEBUG
#include "LOCAL_DEBUG.hpp"
#endif
#define int long long

struct Combination {
  const int MOD = 1e9 + 7;

  vector<int> fact; // 　fact[i] = iの階乗
  void init(int n) {
    fact.resize(n + 1);
    fact[0] = fact[1] = 1;
    for (int i = 2; i <= n; i++) {
      fact[i] = i * fact[i - 1] % MOD;
    }
  }

  int nCr(int n, int r) { // nCr = n!/r!(n-r)!
    if (n < r)
      return 0;
    return fact[n] * mod_pow(fact[r] * fact[n - r] % MOD, MOD - 2) % MOD;
  }

  int mod_pow(int n, int p) { // a/n ≡ a*n^(p-2) nとpは互いに素
    int r = 1;
    for (; p > 0; p >>= 1) {
      if (p & 1LL)
        r = (r * n) % MOD;
      n = (n * n) % MOD;
    }
    return r; // r = n^p % MOD
  }

} comb;

const int MOD = 1e9 + 7;

signed main() {

  int x, y, p, q;
  cin >> x >> y >> p >> q;

  comb.init(2e6 + 2);
  int ans = comb.nCr(p + 1 + q + 1, p + 1) - 1 - comb.nCr(x + q + 1, x) + 1 -
            comb.nCr(p + y + 1, y) + 1 + comb.nCr(x + y, x) - 1;
  cout << (ans + MOD * 9) % MOD << endl;

  return 0;
}
Problem p02782 (C++)

Buggy submission (status: Runtime Error):
#include <iostream>
using namespace std;
const int M = 1000000007;

class ModComb {
  long long *fact, *facti;
  const int mod;

public:
  explicit ModComb(int n, int m) : mod(m) {
    fact = new long long[n + 1];
    facti = new long long[n + 1];
    fact[0] = 1;
    facti[0] = 1;
    for (int i = 1; i <= n; i++)
      fact[i] = (fact[i - 1] * i) % m;
    // calc 1/n!
    long long &inv = facti[n], pw = fact[n];
    inv = 1;
    for (int e = mod - 2; e > 0; e /= 2) {
      if (e & 1)
        inv = inv * pw % mod;
      pw = pw * pw % mod;
    }
    for (int i = n - 1; i > 0; i--)
      facti[i] = (facti[i + 1] * (i + 1)) % m;
  }

  ~ModComb() {
    if (fact)
      delete[] fact;
    if (facti)
      delete[] facti;
  }

  long long get(int n, int k) const {
    if (n < 0 || k < 0 || k > n)
      return 0;
    return fact[n] * facti[k] % mod * facti[n - k] % mod;
  }

  long long getPerm(int n, int k) const {
    if (n < 0 || k < 0 || k > n)
      return 0;
    return fact[n] * facti[n - k] % mod;
  }
} mc(1001001, M);

long long g(int r, int c) {
  long long ret = 0;
  for (int a = 0; a <= r; a++)
    ret += mc.get(a + c + 1, a + 1);
  return ret % M;
}

int main() {
  int r1, c1, r2, c2;
  cin >> r1 >> c1 >> r2 >> c2;
  long long ans = g(r2, c2) - g(r2, c1 - 1) - g(r1 - 1, c2) + g(r1 - 1, c1 - 1);
  cout << (ans % M + M) % M << endl;
}


Fixed submission:
#include <iostream>
using namespace std;
const int M = 1000000007;

class ModComb {
  long long *fact, *facti;
  const int mod;

public:
  explicit ModComb(int n, int m) : mod(m) {
    fact = new long long[n + 1];
    facti = new long long[n + 1];
    fact[0] = 1;
    facti[0] = 1;
    for (int i = 1; i <= n; i++)
      fact[i] = (fact[i - 1] * i) % m;
    // calc 1/n!
    long long &inv = facti[n], pw = fact[n];
    inv = 1;
    for (int e = mod - 2; e > 0; e /= 2) {
      if (e & 1)
        inv = inv * pw % mod;
      pw = pw * pw % mod;
    }
    for (int i = n - 1; i > 0; i--)
      facti[i] = (facti[i + 1] * (i + 1)) % m;
  }

  ~ModComb() {
    if (fact)
      delete[] fact;
    if (facti)
      delete[] facti;
  }

  long long get(int n, int k) const {
    if (n < 0 || k < 0 || k > n)
      return 0;
    return fact[n] * facti[k] % mod * facti[n - k] % mod;
  }

  long long getPerm(int n, int k) const {
    if (n < 0 || k < 0 || k > n)
      return 0;
    return fact[n] * facti[n - k] % mod;
  }
} mc(2001001, M);

long long g(int r, int c) {
  long long ret = 0;
  for (int a = 0; a <= r; a++)
    ret += mc.get(a + c + 1, a + 1);
  return ret % M;
}

int main() {
  int r1, c1, r2, c2;
  cin >> r1 >> c1 >> r2 >> c2;
  long long ans = g(r2, c2) - g(r2, c1 - 1) - g(r1 - 1, c2) + g(r1 - 1, c1 - 1);
  cout << (ans % M + M) % M << endl;
}
Problem p02782 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define int long long
#define f first
#define s second
using namespace std;
const int N = 1000009, mod = 1e9 + 7;
int f[N], iv[N];
int pw(int a, int t = mod - 2) {
  int x = 1;
  while (t) {
    if (t & 1)
      x = x * a % mod;
    a = a * a % mod, t >>= 1;
  }
  return x;
}
int C(int n, int r) {
  int x = (((f[n] * iv[r]) % mod) * iv[n - r]) % mod;
  return x;
}
int32_t main() {
  if (fopen("input.txt", "r"))
    freopen("input.txt", "r", stdin), freopen("output.txt", "w", stdout);
  ios::sync_with_stdio(0), cin.tie(0);
  f[0] = 1, iv[0] = 1;
  for (int i = 1; i < N; i++) {
    f[i] = i * f[i - 1] % mod;
    iv[i] = pw(f[i]);
  }
  int r1, r2, c1, c2, sum = 0;
  cin >> r1 >> c1 >> r2 >> c2;
  for (int i = c1; i <= c2; i++)
    sum = (sum + (C(r2 + i + 1, r2) + mod - C(r1 + i, r1 - 1))) % mod;
  cout << sum;
}

Fixed submission:
#include <bits/stdc++.h>
#define int long long
#define f first
#define s second
using namespace std;
const int N = 3000009, mod = 1e9 + 7;
int f[N], iv[N];
int pw(int a, int t = mod - 2) {
  int x = 1;
  while (t) {
    if (t & 1)
      x = x * a % mod;
    a = a * a % mod, t >>= 1;
  }
  return x;
}
int C(int n, int r) {
  int x = (((f[n] * iv[r]) % mod) * iv[n - r]) % mod;
  return x;
}
int32_t main() {
  if (fopen("input.txt", "r"))
    freopen("input.txt", "r", stdin), freopen("output.txt", "w", stdout);
  ios::sync_with_stdio(0), cin.tie(0);
  f[0] = 1, iv[0] = 1;
  for (int i = 1; i < N; i++) {
    f[i] = i * f[i - 1] % mod;
    iv[i] = pw(f[i]);
  }
  int r1, r2, c1, c2, sum = 0;
  cin >> r1 >> c1 >> r2 >> c2;
  for (int i = c1; i <= c2; i++)
    sum = (sum + (C(r2 + i + 1, r2) + mod - C(r1 + i, r1 - 1))) % mod;
  cout << sum;
}
Problem p02782 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
#define rep(i, j, n) for (int i = (int)(j); i < (int)(n); i++)
#define REP(i, j, n) for (int i = (int)(j); i <= (int)(n); i++)
#define MOD 1000000007
#define int long long
#define ALL(a) (a).begin(), (a).end()
#define vi vector<int>
#define vii vector<vi>
#define pii pair<int, int>
#define priq priority_queue<int>
#define disup(A, key) distance(A.begin(), upper_bound(ALL(A), (int)(key)))
#define dislow(A, key) distance(A.begin(), lower_bound(ALL(A), (int)(key)))
#define tii tuple<int, int, int>
#define Priq priority_queue<int, vi, greater<int>>
#define pb push_back
#define mp make_pair
#define INF (1ll << 60)
const int MAX = 510000;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
  fac[0] = fac[1] = 1;
  finv[0] = finv[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;
    finv[i] = finv[i - 1] * inv[i] % MOD;
  }
}

// 二項係数計算
long long COM(int n, int k) {
  if (n < k)
    return 0;
  if (n < 0 || k < 0)
    return 0;
  return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
signed main() {
  COMinit();
  int A, B, C, D;
  cin >> A >> B >> C >> D;
  int ans = 0;
  REP(i, A, C) {
    ans += COM(i + 1 + D, D);
    ans %= MOD;
    ans += MOD;
    ans -= COM(i + B, B - 1);
    ans %= MOD;
  }
  cout << ans << endl;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define rep(i, j, n) for (int i = (int)(j); i < (int)(n); i++)
#define REP(i, j, n) for (int i = (int)(j); i <= (int)(n); i++)
#define MOD 1000000007
#define int long long
#define ALL(a) (a).begin(), (a).end()
#define vi vector<int>
#define vii vector<vi>
#define pii pair<int, int>
#define priq priority_queue<int>
#define disup(A, key) distance(A.begin(), upper_bound(ALL(A), (int)(key)))
#define dislow(A, key) distance(A.begin(), lower_bound(ALL(A), (int)(key)))
#define tii tuple<int, int, int>
#define Priq priority_queue<int, vi, greater<int>>
#define pb push_back
#define mp make_pair
#define INF (1ll << 60)
const int MAX = 5100000;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
  fac[0] = fac[1] = 1;
  finv[0] = finv[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;
    finv[i] = finv[i - 1] * inv[i] % MOD;
  }
}

// 二項係数計算
long long COM(int n, int k) {
  if (n < k)
    return 0;
  if (n < 0 || k < 0)
    return 0;
  return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
signed main() {
  COMinit();
  int A, B, C, D;
  cin >> A >> B >> C >> D;
  int ans = 0;
  REP(i, A, C) {
    ans += COM(i + 1 + D, D);
    ans %= MOD;
    ans += MOD;
    ans -= COM(i + B, B - 1);
    ans %= MOD;
  }
  cout << ans << endl;
}
Problem p02783 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb push_back
#define F first
#define S second
#define mod 1000000007
#define all(a) a.begin(), a.end()
#define dbg(n) cout << #n << ' ' << n << endl;
#define dbg_v(v)                                                               \
  cout << #v << ":";                                                           \
  for (auto c : v)                                                             \
    cout << " " << c;                                                          \
  cout << endl;
int power(ll x, ll y) {
  ll res = 1;
  while (y > 0) {
    if (y & 1)
      res = (res * x) % mod;
    y = y >> 1;
    x = (x * x) % mod;
  }
  return res;
}
void solve() {
  int h, a;
  cin >> h >> a;
  int ans = (h + a - 1) / a;
  cout << ans << endl;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int T = 1;
  cin >> T;
  while (T--) {
    solve();
  }
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb push_back
#define F first
#define S second
#define mod 1000000007
#define all(a) a.begin(), a.end()
#define dbg(n) cout << #n << ' ' << n << endl;
#define dbg_v(v)                                                               \
  cout << #v << ":";                                                           \
  for (auto c : v)                                                             \
    cout << " " << c;                                                          \
  cout << endl;
int power(ll x, ll y) {
  ll res = 1;
  while (y > 0) {
    if (y & 1)
      res = (res * x) % mod;
    y = y >> 1;
    x = (x * x) % mod;
  }
  return res;
}
void solve() {
  int h, a;
  cin >> h >> a;
  int ans = (h + a - 1) / a;
  cout << ans << endl;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int T = 1;
  // cin>>T;
  while (T--) {
    solve();
  }
}
Problem p02783 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cmath>
#include <iostream>
#include <stdio.h>
#include <vector>
#define rep(i, cc, n) for (int i = cc; i <= n; ++i)
#define drep(i, cc, n) for (int i = cc; i >= n; --i)
typedef long long ll;
using namespace std;
int main() {
  int n, k;
  cin >> n >> k;
  int h[n];
  rep(i, 0, n - 1) cin >> h[i];
  sort(h, h + n);
  drep(i, n - 1, n - k) { h[i] = 0; }
  ll ans = 0;
  rep(i, 0, n - 1) { ans += h[i]; }
  cout << ans << endl;
  return 0;
}

Fixed submission:
#include <algorithm>
#include <cmath>
#include <iostream>
#include <stdio.h>
#include <vector>
#define rep(i, cc, n) for (int i = cc; i <= n; ++i)
#define drep(i, cc, n) for (int i = cc; i >= n; --i)
typedef long long ll;
using namespace std;
int main() {
  int h, a;
  cin >> h >> a;
  if (h % a > 0)
    cout << h / a + 1 << endl;
  else
    cout << h / a << endl;
  return 0;
}
Problem p02783 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
#define vi vector<long long>
#define vvi vector<vector<long long>>
int main(void) {
  int H, A;
  cin >> H, A;
  cout << H / A + (H % A == 0) ? (0) : (1);
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define vi vector<long long>
#define vvi vector<vector<long long>>
int main(void) {
  int H, A;
  cin >> H;
  cin >> A;
  int q = H / A;
  int r = (H % A == 0) ? (0) : (1);
  cout << q + r;
  return 0;
}
Problem p02783 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#include <cstdio>

using namespace std;

#define deb(x) cout << #x << " " << x << endl;

typedef long long ll;
const ll mod = 1000000007;

#define For(i, n) for (int i = 0; i < n; i++)

int main() {
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
  int t, i, n, j;
  cin >> t >> n;
  if (t % n == 0)
    cout << t / n;
  else {
    cout << t / n + 1;
  }

  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
#include <cstdio>

using namespace std;

#define deb(x) cout << #x << " " << x << endl;

typedef long long ll;
const ll mod = 1000000007;

#define For(i, n) for (int i = 0; i < n; i++)

int main() {
  // freopen("input.txt", "r", stdin);
  // freopen("output.txt", "w", stdout);
  int t, i, n, j;
  cin >> t >> n;
  if (t % n == 0)
    cout << t / n;
  else {
    cout << t / n + 1;
  }

  return 0;
}
Problem p02783 (C++)

Buggy submission (status: Runtime Error):
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<int, P> P1;
typedef pair<P, P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define mod 1000000007
#define fi first
#define sc second
#define rep(i, x) for (int i = 0; i < x; i++)
#define repn(i, x) for (int i = 1; i <= x; i++)
#define SORT(x) sort(x.begin(), x.end())
#define ERASE(x) x.erase(unique(x.begin(), x.end()), x.end())
#define POSL(x, v) (lower_bound(x.begin(), x.end(), v) - x.begin())
#define POSU(x, v) (upper_bound(x.begin(), x.end(), v) - x.begin())

int main() {
  int a, b;
  cout << (a + b - 1) / b << endl;
}

Fixed submission:
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<int, P> P1;
typedef pair<P, P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define mod 1000000007
#define fi first
#define sc second
#define rep(i, x) for (int i = 0; i < x; i++)
#define repn(i, x) for (int i = 1; i <= x; i++)
#define SORT(x) sort(x.begin(), x.end())
#define ERASE(x) x.erase(unique(x.begin(), x.end()), x.end())
#define POSL(x, v) (lower_bound(x.begin(), x.end(), v) - x.begin())
#define POSU(x, v) (upper_bound(x.begin(), x.end(), v) - x.begin())

int main() {
  int a, b;
  cin >> a >> b;
  cout << (a + b - 1) / b << endl;
}
Problem p02783 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <iostream>
using namespace std;
int main() {
  int h, a, j = 0;
  cin >> h >> a;
  while (h > 0) {
    h = a, j++;
  }
  cout << j << endl;
}

Fixed submission:
#include <iostream>
using namespace std;
int main() {
  int h, a, j = 0;
  cin >> h >> a;
  while (h > 0) {
    h -= a, j++;
  }
  cout << j << endl;
}
Problem p02783 (C++)

Buggy submission (status: Runtime Error):
#include <iostream>
using namespace std;

int main() {
  int H, A;
  cin >> H, A;
  if (H % A == 0) {
    cout << H / A << endl;
  } else {
    cout << (H / A) + 1 << endl;
  }
}


Fixed submission:
#include <iostream>
using namespace std;

int main() {
  int H, A;
  cin >> H >> A;
  if (H % A == 0) {
    cout << H / A << endl;
  } else {
    cout << (H / A) + 1 << endl;
  }
}
Problem p02783 (C++)

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

using namespace std;

#define FAST_IO                                                                \
  ios_base::sync_with_stdio(0);                                                \
  cin.tie(0)
#define FOR(i, a, b) for (int i = (a); i <= (b); i++)
#define REP(n) FOR(O, 1, (n))
#define pb push_back
#define f first
#define s second
typedef long double ld;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<int, pii> piii;
typedef vector<int> vi;
typedef vector<pii> vii;
typedef vector<ll> vl;
typedef vector<piii> viii;

const int MAXN = 1000100, MAXK = 30;
const ll MOD = 1e9 + 7;
const ll INF = 1e18;
const ld PI = asin(1) * 2;

int main() {
  FAST_IO;

  int h, a;
  cout << (h + a - 1) / a << endl;

  return 0;
}


Fixed submission:
#include <bits/stdc++.h>

using namespace std;

#define FAST_IO                                                                \
  ios_base::sync_with_stdio(0);                                                \
  cin.tie(0)
#define FOR(i, a, b) for (int i = (a); i <= (b); i++)
#define REP(n) FOR(O, 1, (n))
#define pb push_back
#define f first
#define s second
typedef long double ld;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<int, pii> piii;
typedef vector<int> vi;
typedef vector<pii> vii;
typedef vector<ll> vl;
typedef vector<piii> viii;

const int MAXN = 1000100, MAXK = 30;
const ll MOD = 1e9 + 7;
const ll INF = 1e18;
const ld PI = asin(1) * 2;

int main() {
  FAST_IO;

  int h, a;
  cin >> h >> a;
  cout << (h + a - 1) / a << endl;

  return 0;
}
Problem p02783 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <unistd.h>

#define ll long long
#define lst(x) x.size() - 1
#define ld long double
#define pr pair<ll, ll>
#define loop(i, n) for (int i = 0; i < n; ++i)
#define rep(i, x, n) for (int i = x; i <= n; ++i)
#define iteloop(type, data, name, it)                                          \
  for (type<data>::iterator it = name.begin(); it != name.end(); ++it)

using namespace __gnu_pbds;
using namespace std;

template <typename T>
using os = tree<T, null_type, less_equal<T>, rb_tree_tag,
                tree_order_statistics_node_update>;

const ll N = 3e5 + 5, M = 1e1 + 5, MOD = 1e9 + 7, OO = 1e13;
double h, a;
int main() {
  cin.sync_with_stdio(false), cin.tie(0), cout.tie(0);
#ifndef ONLINE_JUDGE
  freopen("in.txt", "rt", stdin);
  // freopen("in.txt", "wt" , stdout);
#endif // ONLINE_JUDGE
  cin >> h >> a;
  int ans = ceil(h / a);
  cout << ans << endl;
}


Fixed submission:
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <unistd.h>

#define ll long long
#define lst(x) x.size() - 1
#define ld long double
#define pr pair<ll, ll>
#define loop(i, n) for (int i = 0; i < n; ++i)
#define rep(i, x, n) for (int i = x; i <= n; ++i)
#define iteloop(type, data, name, it)                                          \
  for (type<data>::iterator it = name.begin(); it != name.end(); ++it)

using namespace __gnu_pbds;
using namespace std;

template <typename T>
using os = tree<T, null_type, less_equal<T>, rb_tree_tag,
                tree_order_statistics_node_update>;

const ll N = 3e5 + 5, M = 1e1 + 5, MOD = 1e9 + 7, OO = 1e13;
double h, a;
int main() {
  cin.sync_with_stdio(false), cin.tie(0), cout.tie(0);
#ifndef ONLINE_JUDGE
  //  freopen("in.txt", "rt" , stdin);
  // freopen("in.txt", "wt" , stdout);
#endif // ONLINE_JUDGE
  cin >> h >> a;
  int ans = ceil(h / a);
  cout << ans << endl;
}
Problem p02783 (C++)

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

int main() {
  int H, A;
  cin >> H, A;
  cout << (H + A - 1) / A << endl;
}


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

int main() {
  int H, A;
  cin >> H >> A;
  cout << (H + A - 1) / A << endl;
}