Problem p03674 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
#define rep(i, n) for (int i = 0, i##_len = (int)(n); i < i##_len; i++)
#define reps(i, n) for (int i = 1, i##_len = (int)(n); i <= i##_len; i++)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rreps(i, n) for (int i = ((int)(n)); i > 0; i--)
#define repi(i, x)                                                             \
  for (auto i = (x).begin(), i##_fin = (x).end(); i != i##_fin; i++)
#define all(x) (x).begin(), (x).end()
#define F first
#define S second
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define eb emplace_back
string solve(bool a) { return ((a) ? "Yes" : "No"); }
typedef vector<int> Vi;
typedef vector<Vi> VVi;
typedef pair<int, int> Pi;
typedef vector<Pi> VPi;
typedef vector<long long> V;
typedef vector<V> VV;
typedef pair<long long, long long> P;
typedef vector<P> VP;
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
  os << "(" << p.first << "," << p.second << ")";
  return os;
}
template <class T> ostream &operator<<(ostream &os, const vector<T> &v) {
  os << "{";
  rep(i, v.size()) {
    if (i)
      os << ",";
    os << v[i];
  }
  os << "}";
  return os;
}
template <class T, class U> istream &operator>>(istream &is, pair<T, U> &p) {
  is >> p.first >> p.second;
  return is;
}
template <class T> istream &operator>>(istream &is, vector<T> &v) {
  rep(i, v.size()) { is >> v[i]; }
  return is;
}
const long long INFLL = 1LL << 60;
const int INF = 1 << 30;
const int MAX = 510000;
const int MOD = 1000000007;
ll mod = 1e9 + 7;
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) { // 二項係数:nCk計算
  if (n < k)
    return 0;
  if (n < 0 || k < 0)
    return 0;
  return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
const double PI = acos(-1);
int main() {
  int n;
  ll ans = 0LL;
  cin >> n;
  COMinit();
  Vi a(n + 1);
  cin >> a;
  map<int, int> dis;
  int left, right;
  rep(i, n) {
    dis[a[i]] += 0;
    if (dis[a[i]] != 0) {
      left = dis[a[i]] - 1;
      right = i;
    } else {
      dis[a[i]] = i + 1;
    }
  }
  clog << left << " " << right << endl;
  cout << n << endl;

  for (int i = 1; i < n; i++) {
    ans = COM(n + 1, i + 1) - COM(left + n - right, i);
    ans %= mod;
    ans += mod;

    ans %= mod;

    cout << ans << endl;
  }
  cout << 1 << endl;
}
/*
1 2 1 3

4- 1
6 - 1
4 - 0
1 - 0

1 4 2 3 4 5
6- 1
15 - 1-1
20
15 -

33 -1
33*32/2 -1 -2 =525
33*32*31/6 - 3=5453
*/

Fixed submission:
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
#define rep(i, n) for (int i = 0, i##_len = (int)(n); i < i##_len; i++)
#define reps(i, n) for (int i = 1, i##_len = (int)(n); i <= i##_len; i++)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rreps(i, n) for (int i = ((int)(n)); i > 0; i--)
#define repi(i, x)                                                             \
  for (auto i = (x).begin(), i##_fin = (x).end(); i != i##_fin; i++)
#define all(x) (x).begin(), (x).end()
#define F first
#define S second
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define eb emplace_back
string solve(bool a) { return ((a) ? "Yes" : "No"); }
typedef vector<int> Vi;
typedef vector<Vi> VVi;
typedef pair<int, int> Pi;
typedef vector<Pi> VPi;
typedef vector<long long> V;
typedef vector<V> VV;
typedef pair<long long, long long> P;
typedef vector<P> VP;
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
  os << "(" << p.first << "," << p.second << ")";
  return os;
}
template <class T> ostream &operator<<(ostream &os, const vector<T> &v) {
  os << "{";
  rep(i, v.size()) {
    if (i)
      os << ",";
    os << v[i];
  }
  os << "}";
  return os;
}
template <class T, class U> istream &operator>>(istream &is, pair<T, U> &p) {
  is >> p.first >> p.second;
  return is;
}
template <class T> istream &operator>>(istream &is, vector<T> &v) {
  rep(i, v.size()) { is >> v[i]; }
  return is;
}
const long long INFLL = 1LL << 60;
const int INF = 1 << 30;
const int MAX = 510000;
const int MOD = 1000000007;
ll mod = 1e9 + 7;
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) { // 二項係数:nCk計算
  if (n < k)
    return 0;
  if (n < 0 || k < 0)
    return 0;
  return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
const double PI = acos(-1);
int main() {
  int n;
  ll ans = 0LL;
  cin >> n;
  COMinit();
  Vi a(n + 1);
  cin >> a;
  map<int, int> dis;
  int left = 0, right = 0;
  rep(i, n + 1) {
    dis[a[i]] += 0;
    if (dis[a[i]] != 0) {
      left = dis[a[i]] - 1;
      right = i;
    } else {
      dis[a[i]] = i + 1;
    }
  }
  clog << left << " " << right << endl;
  cout << n << endl;

  for (int i = 1; i < n; i++) {
    ans = COM(n + 1, i + 1) - COM(left + n - right, i);
    ans %= mod;
    ans += mod;

    ans %= mod;

    cout << ans << endl;
  }
  cout << 1 << endl;
}
/*
1 2 1 3

4- 1
6 - 1
4 - 0
1 - 0

1 4 2 3 4 5
6- 1
15 - 1-1
20
15 -

33 -1
33*32/2 -1 -2 =525
33*32*31/6 - 3=5453
*/