Language: C++

#include <iostream>
#include <sstream>
#include <string>
#include <cassert>
#include <cmath>
#include <climits>
#include <cstdio>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <algorithm>
#include <functional>
#include <numeric>
#include <iomanip>

using namespace std;
typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;

#define REP(i,n) for(int i = 0; i < (int)(n); ++i)
#define FOR(i,a,b) for(int i = (a); i < (int)(b); ++i)
#define ALL(c) (c).begin(), (c).end()
#define SIZE(v) ((int)v.size())

#define pb push_back
#define mp make_pair
#define mt make_tuple

ll MOD = 1000000007;

ll modPow(ll x, ll y)
{
    ll r=1, a=x;
    while (y > 0) {
        if ( (y&1)==1 ) {
            r = (r * a) % MOD;
        }
        a = (a * a) % MOD;
        y /= 2;
    }
    
    return r;
}
// Modular multiplicative inverse through Fermat's little theorem:
// 繝輔ぉ繝ｫ繝槭・縺ｮ蟆丞ｮ夂炊繧医ｊ, a^-1 竕｡ a^(p-2) (mod p) 縺ｨ縺・≧縺ｮ繧剃ｽｿ縺・ｉ縺励＞
// 縺溘□縺励｝縺檎ｴ謨ｰ縺ｮ譎ゅ＠縺区・繧顔ｫ九◆縺ｪ縺・ll modInverse(ll x)
{
    return modPow(x, MOD-2);
}

// Modular division x / y, find modular multiplicative inverse of y
// and multiply by x.
ll modDivision(ll p, ll q)
{
    return (p * modInverse(q)) % MOD;
}

// Binomial coifficient C(n,k) in O(k) time.
ll n_choose_k(ll n, int k)
{
    if (k > n) {
        return 0;
    }
    ll p = 1, q = 1;
    for (int i=1; i<=k; i++) {
        q = ( q * i) % MOD;
        p = ( p * (n - i + 1) ) % MOD;
    }
    return modDivision( p, q);
}

int main(void)
{
    cin.sync_with_stdio(false);
    int N;
    cin >> N;
    vector<ll> As(N+1);
    vector<int> count(N+1);
    ll target = -1;
    REP(n,N+1) {
        cin >> As[n];
        ++count[As[n]];
        if (count[As[n]] == 2) target = As[n];
    }

    // left, mid, right
    vector<int> splits(3);
    int idx = 0;
    for(auto a: As) {
        if (a == target) ++idx;
        else ++splits[idx];
    }
    auto left = splits[0];
    auto mid = splits[1];
    auto right = splits[2];

    // REP(n, 3) cout << splits[n] << ",";
    // cout << endl;

    vector<ll> ans(N+2);

    // (i) no targets + more
    FOR(k, 1, N) {
        ans[k] += n_choose_k(N-1, k);
        ans[k] %= MOD;
    }
    // (ii) two targets + 0 or more
    FOR(k, 2, N+2) {
        ans[k] += n_choose_k(N-1, k-2);
        ans[k] %= MOD;
    }
    // (iii) one target only
    ans[1] += 1;
    // (iv) one target + more
    FOR(k, 1, N) {
        if (k > (N-1 - left - right)) {
            ans[k + 1] += 2 * n_choose_k(N-1, k);
            ans[k + 1] %= MOD;
        }
        else {
            // auto tmp1 = n_choose_k(N-1, k);
            // auto tmp2 = n_choose_k(mid, k);

            // ans[k + 1] += tmp2 * 2;
            // ans[k + 1] %= MOD;
            // ans[k + 1] += (tmp1 - tmp2 + MOD);
            // ans[k + 1] %= MOD;

            auto tmp1 = n_choose_k(left + right, k);
            ans[k + 1] += tmp1;
            ans[k + 1] %= MOD;

            auto tmp2 = n_choose_k(N-1, k);
            ans[k + 1] += 2 * (tmp2 - tmp1 + MOD);
            ans[k + 1] %= MOD;
        }
    }
    
    FOR(i, 1, N+2) cout << ans[i] << endl;
    

    return 0;
}


Compiler output:
a.cc:51:1: error: expected unqualified-id before '{' token
   51 | {
      | ^
a.cc: In function 'll modDivision(ll, ll)':
a.cc:59:17: error: 'modInverse' was not declared in this scope
   59 |     return (p * modInverse(q)) % MOD;
      |                 ^~~~~~~~~~