Problem p02990 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define forn(i, n) for (ll i = 0; i < (n); i++)
#define fori(i, b, e) for (ll i = (b); i < (e); i++)
#define forr(i, b, e) for (ll i = (b); i >= (e); i--)
#define allele(v) v.begin(), v.end()
#define fi first
#define se second
#define Mat vector<vector<ll>>
#define Arr vector<ll>
#define Matd vector<vector<ld>>
#define Arrd vector<ld>

class Combination {
public:
  vector<ll> fact;
  vector<ll> inv;
  ll mod;
  ll mod_inv(ll x) {
    ll n = mod - 2LL;
    ll res = 1LL;
    while (n > 0) {
      if (n & 1)
        res = res * x % mod;
      x = x * x % mod;
      n >>= 1;
    }
    return res;
  }
  ll nCr(ll n, ll r) {
    if (r > n)
      return 0;
    return ((fact[n] * inv[r] % mod) * inv[n - r]) % mod;
  }
  ll nPr(ll n, ll r) {
    if (r > n)
      return 0;
    return (fact[n] * inv[n - r]) % mod;
  }
  Combination(ll n, ll _mod) {
    mod = _mod;
    fact.resize(n + 1);
    fact[0] = 1;
    forn(i, n) { fact[i + 1] = (fact[i] * (i + 1LL)) % mod; }
    inv.resize(n + 1);
    forn(i, n + 1) { inv[i] = mod_inv(fact[i]); }
  }
};

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  const ll mod = 1e9 + 7;
  const ll N = 505;
  Combination comb(N, mod);
  ll b, r;
  cin >> r >> b;
  r = r - b;
  Mat M(N + 1, Arr(N + 1));
  forn(i, N) M[i][0] = 1;
  forn(j, N) M[0][j] = 0;
  fori(i, 1, N) fori(j, 1, N) M[i][j] = (M[i - 1][j] + M[i][j - 1]) % mod;

  fori(i, 1, b + 1) {
    cout << ((comb.nCr(r + 1, i) * M[i][b - i]) % mod) << endl;
  }
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define forn(i, n) for (ll i = 0; i < (n); i++)
#define fori(i, b, e) for (ll i = (b); i < (e); i++)
#define forr(i, b, e) for (ll i = (b); i >= (e); i--)
#define allele(v) v.begin(), v.end()
#define fi first
#define se second
#define Mat vector<vector<ll>>
#define Arr vector<ll>
#define Matd vector<vector<ld>>
#define Arrd vector<ld>

class Combination {
public:
  vector<ll> fact;
  vector<ll> inv;
  ll mod;
  ll mod_inv(ll x) {
    ll n = mod - 2LL;
    ll res = 1LL;
    while (n > 0) {
      if (n & 1)
        res = res * x % mod;
      x = x * x % mod;
      n >>= 1;
    }
    return res;
  }
  ll nCr(ll n, ll r) {
    if (r > n)
      return 0;
    return ((fact[n] * inv[r] % mod) * inv[n - r]) % mod;
  }
  ll nPr(ll n, ll r) {
    if (r > n)
      return 0;
    return (fact[n] * inv[n - r]) % mod;
  }
  Combination(ll n, ll _mod) {
    mod = _mod;
    fact.resize(n + 1);
    fact[0] = 1;
    forn(i, n) { fact[i + 1] = (fact[i] * (i + 1LL)) % mod; }
    inv.resize(n + 1);
    forn(i, n + 1) { inv[i] = mod_inv(fact[i]); }
  }
};

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  const ll mod = 1e9 + 7;
  const ll N = 2005;
  Combination comb(N, mod);
  ll b, r;
  cin >> r >> b;
  r = r - b;
  Mat M(N + 1, Arr(N + 1));
  forn(i, N) M[i][0] = 1;
  forn(j, N) M[0][j] = 0;
  fori(i, 1, N) fori(j, 1, N) M[i][j] = (M[i - 1][j] + M[i][j - 1]) % mod;

  fori(i, 1, b + 1) {
    cout << ((comb.nCr(r + 1, i) * M[i][b - i]) % mod) << endl;
  }
  return 0;
}