Problem p03676 (C++)

Buggy submission (status: Runtime Error):
/*#include <cstdio>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#define x first
#define y second
#define mp make_pair
#define pb push_back
#define LL long long
#define ll long long
#define Pair pair<int,int>
#define LOWBIT(x) x & (-x)
using namespace std;*/

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

#define LL long long
#define ll long long

const LL MOD = 1e9 + 7;
const int maxn = 1e9 + 10;
// const int INF=0x7ffffff;
// const int magic=348;
// const int zero=200;

int n;
// LL p,p1;
LL id1, id2;
LL a[100048];
int v[100048];
int cnt[100048];

LL fac[100048], finv[100048], inv[100048];

void make() {
  fac[0] = fac[1] = 1;
  finv[0] = finv[1] = 1;
  inv[1] = 1;
  for (int i = 2; i < maxn; i++) {
    inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
    fac[i] = fac[i - 1] * (ll)i % MOD;
    finv[i] = finv[i - 1] * inv[i] % MOD;
  }
}
ll C(int a, int b) {
  if (a < b)
    return 0;
  return fac[a] * (finv[b] * finv[a - b] % MOD) % MOD;
}

int main() {
  // LL i;
  // cin>>n;
  /*memset(cnt,0,sizeof(cnt));
  for (i=1;i<=n+1;i++)
  {
          cin>>a[i];
          cnt[a[i]]++;
  }
  p=p1=0;
  for (i=1;i<=n+1;i++)
          if (cnt[a[i]]==2)
                  if (p1==0) p1=i; else p=i;*/
  /*	memset(a, 0, sizeof(a));
memset(v, 0, sizeof(v));
for(ll i = 1; i <= n + 1; ++i){
  cin >> a[i];
  v[a[i]]++;
}
for(ll i = 1; i <= n + 1; ++i){
  if(v[a[i]] == 2 && !id1){
      id1 = i;
  }
  else if(v[a[i]] == 2) {
      id2 = i;
  }
}
  LL ans;
  make();
  LL L=max(id1-1,0LL),R=max(n+1-id2,0LL);
  for (ll i=0;i<=n;i++)
  {
          ans=C(n+1,(i+1)*1LL);
          ans-=C(L+R,i*1LL);
          if (ans<0) ans+=MOD;
          cout<<ans<<endl;
  }
  return 0;*/
  ll n;
  make();
  ll id1 = 0, id2 = 0;
  cin >> n;
  memset(a, 0, sizeof(a));
  memset(v, 0, sizeof(v));
  for (ll i = 1; i <= n + 1; ++i) {
    cin >> a[i];
    v[a[i]]++;
  }
  for (ll i = 1; i <= n + 1; ++i) {
    if (v[a[i]] == 2 && !id1) {
      id1 = i;
    } else if (v[a[i]] == 2) {
      id2 = i;
    }
  }
  ll L = max(id1 - 1LL, 0LL),
     /*M = id2 - id1 - 1LL*/ R = max(n + 1LL - id2, 0LL);
  ll res = 0;
  for (ll i = 1; i <= n + 1; ++i) {
    res = C(n + 1, i * 1LL);
    res -= C(L + R, (i - 1) * 1LL);
    if (res < 0)
      res += MOD;
    cout << res << '\n';
  }
  return 0;
}

Fixed submission:
/*#include <cstdio>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#define x first
#define y second
#define mp make_pair
#define pb push_back
#define LL long long
#define ll long long
#define Pair pair<int,int>
#define LOWBIT(x) x & (-x)
using namespace std;*/

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

#define LL long long
#define ll long long

const LL MOD = 1e9 + 7;
const int maxn = 1e5 + 10;

// const int INF=0x7ffffff;
// const int magic=348;
// const int zero=200;

int n;
// LL p,p1;
LL id1, id2;
LL a[100048];
int v[100048];
int cnt[100048];

LL fac[100048], finv[100048], inv[100048];

void make() {
  fac[0] = fac[1] = 1;
  finv[0] = finv[1] = 1;
  inv[1] = 1;
  for (int i = 2; i < maxn; i++) {
    inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
    fac[i] = fac[i - 1] * (ll)i % MOD;
    finv[i] = finv[i - 1] * inv[i] % MOD;
  }
}
ll C(int a, int b) {
  if (a < b)
    return 0;
  return fac[a] * (finv[b] * finv[a - b] % MOD) % MOD;
}

int main() {
  // LL i;
  // cin>>n;
  /*memset(cnt,0,sizeof(cnt));
  for (i=1;i<=n+1;i++)
  {
          cin>>a[i];
          cnt[a[i]]++;
  }
  p=p1=0;
  for (i=1;i<=n+1;i++)
          if (cnt[a[i]]==2)
                  if (p1==0) p1=i; else p=i;*/
  /*	memset(a, 0, sizeof(a));
memset(v, 0, sizeof(v));
for(ll i = 1; i <= n + 1; ++i){
  cin >> a[i];
  v[a[i]]++;
}
for(ll i = 1; i <= n + 1; ++i){
  if(v[a[i]] == 2 && !id1){
      id1 = i;
  }
  else if(v[a[i]] == 2) {
      id2 = i;
  }
}
  LL ans;
  make();
  LL L=max(id1-1,0LL),R=max(n+1-id2,0LL);
  for (ll i=0;i<=n;i++)
  {
          ans=C(n+1,(i+1)*1LL);
          ans-=C(L+R,i*1LL);
          if (ans<0) ans+=MOD;
          cout<<ans<<endl;
  }
  return 0;*/
  ll n;
  make();
  ll id1 = 0, id2 = 0;
  cin >> n;
  memset(a, 0, sizeof(a));
  memset(v, 0, sizeof(v));
  for (ll i = 1; i <= n + 1; ++i) {
    cin >> a[i];
    v[a[i]]++;
  }
  for (ll i = 1; i <= n + 1; ++i) {
    if (v[a[i]] == 2 && !id1) {
      id1 = i;
    } else if (v[a[i]] == 2) {
      id2 = i;
    }
  }
  ll L = max(id1 - 1LL, 0LL),
     /*M = id2 - id1 - 1LL*/ R = max(n + 1LL - id2, 0LL);
  ll res = 0;
  for (ll i = 1; i <= n + 1; ++i) {
    res = C(n + 1, i * 1LL);
    res -= C(L + R, (i - 1) * 1LL);
    if (res < 0)
      res += MOD;
    cout << res << '\n';
  }
  return 0;
}