Problem p03676 (C++)

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

#define DUMP(x) cerr << #x << "=" << x << endl
#define DUMP2(x, y)                                                            \
  cerr << "(" << #x << ", " << #y << ") = (" << x << ", " << y << ")" << endl
#define BINARY(x) static_cast<bitset<16>>(x)

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, m, n) for (int i = m; i < (int)(n); i++)

#define in_range(x, y, w, h)                                                   \
  (0 <= (int)(x) && (int)(x) < (int)(w) && 0 <= (int)(y) && (int)(y) < (int)(h))
#define ALL(a) (a).begin(), (a).end()

typedef long long ll;
const int INF = 1e9;
const ll INFLL = 1e18;
typedef pair<int, int> PII;
int dx[4] = {0, -1, 1, 0}, dy[4] = {-1, 0, 0, 1};

const ll MOD = 1e9 + 7;
vector<ll> inv_mod;

void list_mod_inverse(ll n, ll m) {
  inv_mod.resize(n + 1);
  inv_mod[1] = 1;
  for (int i = 2; i <= n; i++) {
    inv_mod[i] = inv_mod[m % i] * (m - m / i) % m;
  }
}

ll next_conb(ll n, ll k, ll now) {
  if (n < k)
    return 0;
  return ((now * inv_mod[k] % MOD) * (n - k + 1)) % MOD;
}

int main() {
  ios::sync_with_stdio(false);

  ll N;
  cin >> N;
  ll NN = N + 1;
  vector<int> appear(N + 1, -1);

  ll a, b;

  rep(i, NN) {
    int A;
    cin >> A;

    if (appear[A] >= 0) {
      a = appear[A];
      b = N - i;
    } else {
      appear[A] = i;
    }
  }

  list_mod_inverse(2 * NN, MOD);

  ll all = NN, diff = 0, sum = 1;

  cout << N << endl;
  for (int k = 2; k <= NN; k++) {
    if (a + b >= k - 1) {
      sum = next_conb(a + b, k - 1, sum);
    } else {
      sum = 0;
    }

    all = next_conb(NN, k, all);

    cout << (all - sum + MOD) % MOD << endl;
    assert(all >= sum);
  }
}

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

#define DUMP(x) cerr << #x << "=" << x << endl
#define DUMP2(x, y)                                                            \
  cerr << "(" << #x << ", " << #y << ") = (" << x << ", " << y << ")" << endl
#define BINARY(x) static_cast<bitset<16>>(x)

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, m, n) for (int i = m; i < (int)(n); i++)

#define in_range(x, y, w, h)                                                   \
  (0 <= (int)(x) && (int)(x) < (int)(w) && 0 <= (int)(y) && (int)(y) < (int)(h))
#define ALL(a) (a).begin(), (a).end()

typedef long long ll;
const int INF = 1e9;
const ll INFLL = 1e18;
typedef pair<int, int> PII;
int dx[4] = {0, -1, 1, 0}, dy[4] = {-1, 0, 0, 1};

const ll MOD = 1e9 + 7;
vector<ll> inv_mod;

void list_mod_inverse(ll n, ll m) {
  inv_mod.resize(n + 1);
  inv_mod[1] = 1;
  for (int i = 2; i <= n; i++) {
    inv_mod[i] = inv_mod[m % i] * (m - m / i) % m;
  }
}

ll next_conb(ll n, ll k, ll now) {
  if (n < k)
    return 0;
  return ((now * inv_mod[k] % MOD) * (n - k + 1)) % MOD;
}

int main() {
  ios::sync_with_stdio(false);

  ll N;
  cin >> N;
  ll NN = N + 1;
  vector<int> appear(N + 1, -1);

  ll a, b;

  rep(i, NN) {
    int A;
    cin >> A;

    if (appear[A] >= 0) {
      a = appear[A];
      b = N - i;
    } else {
      appear[A] = i;
    }
  }

  list_mod_inverse(2 * NN, MOD);

  ll all = NN, diff = 0, sum = 1;

  cout << N << endl;
  for (int k = 2; k <= NN; k++) {
    if (a + b >= k - 1) {
      sum = next_conb(a + b, k - 1, sum);
    } else {
      sum = 0;
    }

    all = next_conb(NN, k, all);

    cout << (all - sum + MOD) % MOD << endl;
  }
}