Buggy python submission (verdict: Time Limit Exceeded):
import sys
stdin = sys.stdin

sys.setrecursionlimit(10**5)

def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x)-1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())


# nの逆元のリスト
def inv_mod(n:int, mod:int) -> list:
    inv = [0,1]
    for i in range(2,n+1):
        inv.append(mod - ((mod//i)*inv[mod%i]) % mod)
    return inv
       
# nの階乗のリスト
def fact(n:int, mod:int) -> list:
    fac = [1,1]
    res = 1
    for i in range(2,n+1):
        res = res*i%mod
        fac.append(res)
    return fac

# nの階乗の逆元のリスト
def fact_inv(n:int, inv:list, mod:int) -> list:
    facInv = [1,1]
    for i in range(2,n+1):
        facInv.append(facInv[i-1]*inv[i] % mod)
    return facInv
        
# 二項係数
def nCr(n:int, r:int, mod:int, fac:list, facInv:list) -> int:
    if not (0<=r and r<=n):
        return 0
    
    return ((fac[n]*facInv[r]) % mod) * facInv[n-r] % mod

from collections import Counter

n = ni()
a = list(li())
# 2こあるものは何か
cnt = Counter(a)
two = cnt.most_common(1)[0][0]

left = a.index(two)
right = a[::-1].index(two)

# 二項係数準備
MOD = 10**9+7

inv = inv_mod(n+2,MOD)
fac = fact(n+2,MOD)
fac_inv = fact_inv(n+2,inv,MOD)

for i in range(1,n+2):
    if 1 < i < n+1:
        ans = nCr(n+1,i,MOD,fac,fac_inv)
        for j in range(i):
            if j <= left and (i-j-1) <= right:
                ans -= nCr(left,j,MOD,fac,fac_inv) * nCr(right,(i-j-1),MOD,fac,fac_inv)
                
        if ans < 0:
            ans += MOD
            
        print(ans)
        
    elif i == 1:
        print(n)
    else:
        print(1)

Fixed submission:
import sys
stdin = sys.stdin

sys.setrecursionlimit(10**5)

def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x)-1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())


# nの逆元のリスト
def inv_mod(n:int, mod:int) -> list:
    inv = [0,1]
    for i in range(2,n+1):
        inv.append(mod - ((mod//i)*inv[mod%i]) % mod)
    return inv
       
# nの階乗のリスト
def fact(n:int, mod:int) -> list:
    fac = [1,1]
    res = 1
    for i in range(2,n+1):
        res = res*i%mod
        fac.append(res)
    return fac

# nの階乗の逆元のリスト
def fact_inv(n:int, inv:list, mod:int) -> list:
    facInv = [1,1]
    for i in range(2,n+1):
        facInv.append(facInv[i-1]*inv[i] % mod)
    return facInv
        
# 二項係数
def nCr(n:int, r:int, mod:int, fac:list, facInv:list) -> int:
    if not (0<=r and r<=n):
        return 0
    
    return ((fac[n]*facInv[r]) % mod) * facInv[n-r] % mod

from collections import Counter

n = ni()
a = list(li())
# 2こあるものは何か
cnt = Counter(a)
two = cnt.most_common(1)[0][0]

left = a.index(two)
right = a[::-1].index(two)

# 二項係数準備
MOD = 10**9+7

inv = inv_mod(n+2,MOD)
fac = fact(n+2,MOD)
fac_inv = fact_inv(n+2,inv,MOD)

for i in range(1,n+2):
    if 1 < i < n+1:
        ans = nCr(n+1,i,MOD,fac,fac_inv)

        if left+right >= i-1:
            ans -= nCr(left+right,i-1,MOD,fac,fac_inv)
            
        if ans < 0:
            ans += MOD
            
        print(ans)
        
    elif i == 1:
        print(n)
    else:
        print(1)