Language: C++

#include <cstdio>
#include <vector>

int N;
int A[100003];
int cnt[100003];

using namespace std;

template< bool B, class T = void >
using enable_if_t = typename enable_if<B,T>::type;

template<int M, bool IsPrime = false>
class Modulo {
  using ll = long long;
  int n;
  static enable_if_t<IsPrime, ll> inv(ll a, ll p) {
    return (a == 1 ? 1 : (1 - p * inv(p % a, a)) / a + p);
  }
public:
  Modulo () : n(0) {;}
  Modulo (int m) : n(m) {
    if (n >= M) n %= M;
    else if (n < 0) n = (n % M + M) % M;
  }
  Modulo (ll m) {
    if (m >= M) m %= M;
    else if (m < 0) m = (m % M + M) % M;
    n = m;
  }
  explicit operator int() const { return n; }
  explicit operator ll() const { return n; }
  bool operator==(const Modulo &a) const { return n == a.n; }
  Modulo operator+=(const Modulo &a) { n += a.n; if (n >= M) n -= M; return *this; }
  Modulo operator-=(const Modulo &a) { n -= a.n; if (n < 0) n += M; return *this; }
  Modulo operator*=(const Modulo &a) { n = (ll(n) * a.n) % M; return *this; }
  Modulo operator+(const Modulo &a) const { Modulo res = *this; return res += a; }
  Modulo operator-(const Modulo &a) const { Modulo res = *this; return res -= a; }
  Modulo operator*(const Modulo &a) const { Modulo res = *this; return res *= a; }
  Modulo operator^(int n) const {
    if (n == 0) return Modulo(1);
    const Modulo a = *this;
    Modulo res = (a * a) ^ (n / 2);
    return n % 2 ? res * a : res;
  }
  enable_if_t<IsPrime, Modulo> operator/(const Modulo &a) const {
    return *this * inv(ll(a), M);
  }
};

const int mod = 1000000007;

template<int M = mod> Modulo<M, true> fact(int n, bool sw = true) {
  static vector<Modulo<M, true>> v1 = {1}, v2 = {1};
  if (n >= (int)v1.size()) {
    const int from = v1.size(), to = n + 1024;
    v1.reserve(to);
    v2.reserve(to);
    for (int i = from; i < to; ++i) {
      v1.push_back(v1.back() * Modulo<M, true>(i));
      v2.push_back(v2.back() / Modulo<M, true>(i));
    }
  }
  return sw ? v1[n] : v2[n];
}

template<int M = mod> Modulo<M, true> comb(int a, int b) {
  if (b < 0 || b > a) return 0;
  return fact<M>(a, true) * fact<M>(b, false) * fact<M>(a-b, false);
}

using Mod = Modulo<mod, true>;

int main() {
  scanf("%d", &N);
  for (int i = 1; i <= N + 1; i++) {
    int x;
    scanf("%d", &x);
    A[i] = x;
    cnt[x]++;
  }
  //printf("N: %d\n", N);

  int dup = 0;
  for (int i = 1; i <= N + 1; i++) {
    if (cnt[i] == 2) {
      dup = i;
    }
  }

  //printf("dup: %d\n", dup);

  int d1i = 0;
  int d2i = 0;
  int i = 1;
  for (; i <= N + 1; i++) {
    //printf("i: %d, A[i]: %d\n", i, A[i]);
    if (A[i] == dup) {
      d1i = i++;
      break;
    }
  }

  for (; i <= N + 1; i++) {
    //printf("i: %d, A[i]: %d\n", i, A[i]);
    if (A[i] == dup) {
      d2i = i;
      break;
    }
  }
  //printf("d1i: %d, d2i: %d\n", d1i, d2i);

  for (int i = 1; i <= N + 1; i++) {
    //printf("all: %d\n", N + 1);
    auto all = comb<mod>(N + 1, i);

    int prev = d1i - 1;
    int post = N + 1 - d2i;
    //printf("prev: %d, post: %d\n", prev, post);
    Mod dupsum = 0;
    for (int prev_choice = 0; prev_choice < d1i; prev_choice++) {
      int post_choice = i - prev_choice - 1;
      if (post_choice < 0) {
        continue;
      }
      //printf("prev_choice: %d, post_choice: %d\n", prev_choice, post_choice);
      auto x = comb<mod>(prev, prev_choice);
      auto y = comb<mod>(post, post_choice);
      dupsum = dupsum + (x * y);
    }
    printf("%lld\n", static_cast<long long>(all - dupsum));
  }
}


Compiler output:
a.cc:17:10: error: reference to 'enable_if_t' is ambiguous
   17 |   static enable_if_t<IsPrime, ll> inv(ll a, ll p) {
      |          ^~~~~~~~~~~
In file included from /usr/include/c++/14/bits/stl_pair.h:60,
                 from /usr/include/c++/14/bits/stl_algobase.h:64,
                 from /usr/include/c++/14/vector:62,
                 from a.cc:2:
/usr/include/c++/14/type_traits:2711:11: note: candidates are: 'template<bool _Cond, class _Tp> using std::enable_if_t = typename std::enable_if::type'
 2711 |     using enable_if_t = typename enable_if<_Cond, _Tp>::type;
      |           ^~~~~~~~~~~
a.cc:11:7: note:                 'template<bool B, class T> using enable_if_t = typename std::enable_if::type'
   11 | using enable_if_t = typename enable_if<B,T>::type;
      |       ^~~~~~~~~~~
a.cc:46:3: error: reference to 'enable_if_t' is ambiguous
   46 |   enable_if_t<IsPrime, Modulo> operator/(const Modulo &a) const {
      |   ^~~~~~~~~~~
/usr/include/c++/14/type_traits:2711:11: note: candidates are: 'template<bool _Cond, class _Tp> using std::enable_if_t = typename std::enable_if::type'
 2711 |     using enable_if_t = typename enable_if<_Cond, _Tp>::type;
      |           ^~~~~~~~~~~
a.cc:11:7: note:                 'template<bool B, class T> using enable_if_t = typename std::enable_if::type'
   11 | using enable_if_t = typename enable_if<B,T>::type;
      |       ^~~~~~~~~~~
a.cc: In instantiation of 'Modulo<M, true> fact(int, bool) [with int M = 1000000007]':
a.cc:69:17:   required from 'Modulo<M, true> comb(int, int) [with int M = 1000000007]'
   69 |   return fact<M>(a, true) * fact<M>(b, false) * fact<M>(a-b, false);
      |          ~~~~~~~^~~~~~~~~
a.cc:115:25:   required from here
  115 |     auto all = comb<mod>(N + 1, i);
      |                ~~~~~~~~~^~~~~~~~~~
a.cc:61:30: error: no match for 'operator/' (operand types are '__gnu_cxx::__alloc_traits<std::allocator<Modulo<1000000007, true> >, Modulo<1000000007, true> >::value_type' {aka 'Modulo<1000000007, true>'} and 'Modulo<1000000007, true>')
   61 |       v2.push_back(v2.back() / Modulo<M, true>(i));
      |                    ~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~
a.cc:61:30: note: candidate: 'operator/(long long int, long long int)' (built-in)
a.cc:61:30: note:   no known conversion for argument 2 from 'Modulo<1000000007, true>' to 'long long int'
a.cc:61:30: note: candidate: 'operator/(long long int, int)' (built-in)
a.cc:61:30: note:   no known conversion for argument 2 from 'Modulo<1000000007, true>' to 'int'
a.cc:61:30: note: candidate: 'operator/(int, long long int)' (built-in)
a.cc:61:30: note:   no known conversion for argument 2 from 'Modulo<1000000007, true>' to 'long long int'
a.cc:61:30: note: candidate: 'operator/(int, int)' (built-in)
a.cc:61:30: note:   no known conversion for argument 2 from 'Modulo<1000000007, true>' to 'int'