Problem:
 Score : 600 points    Problem Statement You are given an integer sequence of length n+1 , a_1,a_2,...,a_{n+1} , which consists of the n integers 1,...,n .
It is known that each of the n integers 1,...,n appears at least once in this sequence.  For each integer k=1,...,n+1 , find the number of the different subsequences (not necessarily contiguous) of the given sequence with length k , modulo 10^9+7 .      Notes   If the contents of two subsequences are the same, they are not separately counted even if they originate from different positions in the original sequence.    A subsequence of a sequence a with length k is a sequence obtained by selecting k of the elements of a and arranging them without changing their relative order. For example, the sequences 1,3,5 and 1,2,3 are subsequences of 1,2,3,4,5 , while 3,1,2 and 1,10,100 are not.        Constraints  1 \leq n \leq 10^5  1 \leq a_i \leq n  Each of the integers 1,...,n appears in the sequence.  n and a_i are integers.         Input Input is given from Standard Input in the following format:  n  a_1  a_2 ... a_{n+1}       Output Print n+1 lines.
The k -th line should contain the number of the different subsequences of the given sequence with length k , modulo 10^9+7 .        Sample Input 1 3
1 2 1 3      Sample Output 1 3
5
4
1  There are three subsequences with length 1 : 1 and 2 and 3 .  There are five subsequences with length 2 : 1,1 and 1,2 and 1,3 and 2,1 and 2,3 .  There are four subsequences with length 3 : 1,1,3 and 1,2,1 and 1,2,3 and 2,1,3 .  There is one subsequence with length 4 : 1,2,1,3 .       Sample Input 2 1
1 1      Sample Output 2 1
1  There is one subsequence with length 1 : 1 .  There is one subsequence with length 2 : 1,1 .       Sample Input 3 32
29 19 7 10 26 32 27 4 11 20 2 8 16 23 5 14 6 12 17 22 18 30 28 24 15 1 25 3 13 21 19 31 9      Sample Output 3 32
525
5453
40919
237336
1107568
4272048
13884156
38567100
92561040
193536720
354817320
573166440
818809200
37158313
166803103
166803103
37158313
818809200
573166440
354817320
193536720
92561040
38567100
13884156
4272048
1107568
237336
40920
5456
528
33
1  Be sure to print the numbers modulo 10^9+7 .

Solution (Python):
N = int(input())
a = list(map(int, input().split()))
table = [-1] * (N + 1)
d = [0, 0]
mod = 10 ** 9 + 7
class Factorial:
  def __init__(self, n, mod):
    self.f=[1]
    for i in range(1, n + 1):
      self.f.append(self.f[-1] * i % mod)
    self.i=[pow(self.f[-1], mod - 2, mod)]
    for i in range(1, n + 1)[: : -1]:
      self.i.append(self.i[-1] * i % mod)
    self.i.reverse()
  def factorial(self, i):
    return self.f[i]
  def ifactorial(self, i):
    return self.i[i]
  def combi(self, n, k):
    return self.f[n] * self.i[n - k] % mod * self.i[k] % mod
f = Factorial(N + 1, mod)
for i in range(N + 1):
  if table[a[i]] != -1:
    d = [table[a[i]], i]
    break
  table[a[i]] = i
for i in range(1, N + 2):
  x = f.combi(N + 1, i)
  w = 0
  if N + d[0] - d[1] >= i - 1:
    w = f.combi(d[0] + N - d[1], i - 1)
  print((x - w) % mod)

Solution (Python):
def main():
	n,*a = map(int,open(0).read().split())
	dbl = sum(a)-n*(n+1)//2
	l,r = [i for i,j in enumerate(a) if j==dbl]
	const = n+l-r
	m = n + 1
	mod = 10**9+7
	fac = [1]*(m+1)
	inv = [1]*(m+1)
	for i in range(1,m+1):
		fac[i] = fac[i-1] * i % mod
	inv[-1] = pow(fac[-1], mod - 2, mod)
	for i in range(m-1, -1, -1):
		inv[i] = inv[i+1] * (i+1) % mod
	def cmb(n,r):
		if n<r:return 0
		return fac[n] * inv[n-r] * inv[r] % mod
	for k in range(1,n+2):
		print((cmb(n+1,k)-cmb(const,k-1)) % mod)
if __name__=="__main__":main()

Solution (Python):
from collections import Counter
n,*a = map(int,open(0).read().split())
dbl = Counter(a).most_common()[0][0]
l,r = [i for i,j in enumerate(a) if j==dbl]
const = n+l-r
m = n + 1
mod = 10**9+7
fac = [1]*(m+1)
inv = [1]*(m+1)
for i in range(1,m+1):
	fac[i] = fac[i-1] * i % mod
inv[-1] = pow(fac[-1], mod - 2, mod)
for i in range(m-1, -1, -1):
	inv[i] = inv[i+1] * (i+1) % mod
def cmb(n,r):
	if n<r:return 0
	return fac[n] * inv[n-r] * inv[r] % mod
for k in range(1,n+2):
	print((cmb(n+1,k)-cmb(const,k-1)) % mod)

Solution (Python):
from collections import Counter

class ModComb:
    def __init__(self, MAX, mod=10 ** 9 + 7):
        fac = [1, 1]
        finv = [1, 1]
        inv = [0, 1]
        for i in range(2, MAX):
            fac.append(fac[i - 1] * i % mod)
            inv.append(mod - inv[mod % i] * (mod // i) % mod)
            finv.append(finv[i - 1] * inv[i] % mod)
        self.fac, self.finv, self.mod = fac, finv, mod

    def nCk(self, n, k):
        if n < k or n < 0 or k < 0:
            return 0
        fac, finv, mod = self.fac, self.finv, self.mod
        return fac[n] * (finv[k] * finv[n - k] % mod) % mod

mod = 10 ** 9 + 7

N, *A = map(int, open(0).read().split())

C = Counter(A)
t = C.most_common()[0][0]
left = A.index(t)
right = A.index(t, left + 1)

mc = ModComb(10 ** 5 + 5, mod=mod)

m = left + N - right
for k in range(1, N + 2):
    print((mc.nCk(N + 1, k) - mc.nCk(m, k - 1)) % mod)

Solution (Python):
class ModComb:
    def __init__(self, MAX, mod=10 ** 9 + 7):
        fac = [1, 1]
        finv = [1, 1]
        inv = [0, 1]
        for i in range(2, MAX):
            fac.append(fac[i - 1] * i % mod)
            inv.append(mod - inv[mod % i] * (mod // i) % mod)
            finv.append(finv[i - 1] * inv[i] % mod)
        self.fac, self.finv, self.mod = fac, finv, mod

    def nCk(self, n, k):
        if n < k or n < 0 or k < 0:
            return 0
        fac, finv, mod = self.fac, self.finv, self.mod
        return fac[n] * (finv[k] * finv[n - k] % mod) % mod

mod = 10 ** 9 + 7

N, *A = map(int, open(0).read().split())

mc = ModComb(10 ** 5 + 5, mod=mod)

used = {}
left, right = 0, 0
for i, a in enumerate(A):
    if a in used:
        right = i
        left = used[a]
        break
    used[a] = i

m = left + N - right
for k in range(1, N + 2):
    print((mc.nCk(N + 1, k) - mc.nCk(m, k - 1)) % mod)

Solution (Python):
class ModComb:
    def __init__(self, MAX, mod=10 ** 9 + 7):
        fac = [1, 1]
        finv = [1, 1]
        inv = [0, 1]
        for i in range(2, MAX):
            fac.append(fac[i - 1] * i % mod)
            inv.append(mod - inv[mod % i] * (mod // i) % mod)
            finv.append(finv[i - 1] * inv[i] % mod)
        self.fac, self.finv, self.mod = fac, finv, mod

    def nCk(self, n, k):
        if n < k or n < 0 or k < 0:
            return 0
        fac, finv, mod = self.fac, self.finv, self.mod
        return fac[n] * (finv[k] * finv[n - k] % mod) % mod

mod = 10 ** 9 + 7

N, *A = map(int, open(0).read().split())

mc = ModComb(210000, mod=mod)

used = {}
left, right = 0, 0
for i, a in enumerate(A):
    if a in used:
        right = i
        left = used[a]
        break
    used[a] = i

m = left + N - right
for k in range(1, N + 2):
    print((mc.nCk(N + 1, k) - mc.nCk(m, k - 1)) % mod)

Solution (Python):


import sys
from collections import Counter

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

class FactInvMOD:
    """ 階乗たくさん使う時用のテーブル準備 """

    def __init__(self, MAX, MOD):
        """ MAX：階乗に使う数値の最大以上まで作る """
        
        MAX += 1
        self.MAX = MAX
        self.MOD = MOD
        
        factorial = [1] * MAX
        factorial[0] = factorial[1] = 1
        for i in range(2, MAX):
            factorial[i] = factorial[i-1] * i % MOD
        
        inverse = [1] * MAX
        
        inverse[MAX-1] = pow(factorial[MAX-1], MOD-2, MOD)
        for i in range(MAX-2, 0, -1):
            
            inverse[i] = inverse[i+1] * (i+1) % MOD
        self.fact = factorial
        self.inv = inverse
    
    def nCr(self, n, r):
        """ 組み合わせの数 (必要な階乗と逆元のテーブルを事前に作っておく) """

        if n < r: return 0
        
        r = min(r, n-r)
        
        numerator = self.fact[n]
        
        denominator = self.inv[r] * self.inv[n-r] % self.MOD
        return numerator * denominator % self.MOD

    def nPr(self, n, r):
        """ 順列 """

        if n < r: return 0
        return self.fact[n] * self.inv[n-r] % self.MOD

    def nHr(self, n, r):
        """ 重複組み合わせ """

        
        return self.nCr(r+n-1, r)

N = INT()
A = LIST()


target = 0
for k, v in Counter(A).items():
    if v == 2:
        target = k
        break
idx = A.index(target)

btw = A[idx+1:].index(target)

fim = FactInvMOD(N+1, MOD)
for i in range(1, N+2):
    
    ans = fim.nCr(N+1, i) - fim.nCr(N-1-btw, i-1)
    print(ans%MOD)

Solution (Python):
def extgcd(a,b):
    r = [1,0,a]
    w = [0,1,b]
    while w[2] != 1:
        q = r[2]//w[2]
        r2 = w
        w2 = [r[0]-q*w[0],r[1]-q*w[1],r[2]-q*w[2]]
        r = r2
        w = w2
    return [w[0],w[1]]
def mod_inv(a,mod):
    x = extgcd(a,mod)[0]
    return (mod + x % mod)% mod
n = int(input())
mod = 10**9 + 7
a = list(map(int,input().split()))
il = [[]for i in range(n)]
for i in range(n+1):
    il[a[i]-1].append(i)
    if len(il[a[i]-1]) > 1:
        p,q = il[a[i]-1]
comb = 1
comb2 = 1
c = p + n - q
for i in range(n+1):
    comb = (((comb*(n+1-i))%mod)*mod_inv(i+1,mod))%mod
    if c >= i:
        print((comb-comb2)%mod)
        comb2 = (((comb2*(c-i))%mod)*mod_inv(i+1,mod))%mod
    else:
        print(comb%mod)

Solution (Python):
class Factorial:
    def __init__(self,n,mod):
        self.f=[1]
        self.mod=mod
        for i in range(1,n+1):
            self.f.append(self.f[-1]*i%mod)
        self.i=[pow(self.f[-1],mod-2,mod)]
        for i in range(1,n+1)[::-1]:
            self.i.append(self.i[-1]*i%mod)
        self.i.reverse()
    def factorial(self,i):
        return self.f[i]
    def ifactorial(self,i):
        return self.i[i]
    def comb(self,n,k):
        return self.f[n]*self.i[n-k]%self.mod*self.i[k]%self.mod if n>=k else 0
from collections import*
M=10**9+7
n,*a=map(int,open(0).read().split())
v,_=Counter(a).most_common(1)[0]
l=-1
for i,b in enumerate(a):
  if b==v:
    if l<0:l=i
    else:r=n-i
c=Factorial(n+1,M).comb
for k in range(n+1):print((c(n+1,k+1)-c(l+r,k))%M)

Solution (Python):
class Factorial:
    def __init__(self,n,mod):
        self.f=[1]
        self.mod=mod
        for i in range(1,n+1):
            self.f.append(self.f[-1]*i%mod)
        self.i=[pow(self.f[-1],mod-2,mod)]
        for i in range(1,n+1)[::-1]:
            self.i.append(self.i[-1]*i%mod)
        self.i.reverse()
    def factorial(self,i):
        return self.f[i]
    def ifactorial(self,i):
        return self.i[i]
    def comb(self,n,k):
        return self.f[n]*self.i[n-k]%self.mod*self.i[k]%self.mod if n>=k else 0
from collections import*
M=10**9+7
n,*a=map(int,open(0).read().split())
v,_=Counter(a).most_common(1)[0]
l=-1
for i,b in enumerate(a):
  if b==v:
    if l<0:l=i
    else:r=n-i
c=Factorial(n+1,M).comb
for k in range(n+1):print((c(n+1,k+1)-c(l+r,k))%M)

Solution (Python):
import collections

N = int(input())
a = list(map(int, input().split()))

c = collections.Counter(a)
dup = c.most_common()[0][0]

id = [i for i, x in enumerate(a) if x == dup]
L = id[0]
R = id[1]

MOD = 10**9 +7
factorial = [1]
inverse = [1]

for i in range(1, N+2):
    factorial.append(factorial[i-1] * i % MOD)
    inverse.append(pow(factorial[i], MOD-2, MOD))
    

def C(n, r):
    if n < r:
        return 0
    return (factorial[n] * inverse[r] * inverse[n-r]) % MOD

print(N)
for i in range(2, N+2):
    ans = (C(N+1, i) - C(L+(N-R), i-1)) % MOD
    print(ans)

Solution (Python):
mod=10**9+7
n=int(input())
a=list(map(int,input().split()))
d=sum(a)-sum(range(n+1))
i1=a.index(d)
i2=i1+1+a[i1+1:].index(d)

g1=[1,1]
g2=[1,1]
inverse=[0,1]
for i in range(2,n+2):
    g1.append((g1[-1]*i)%mod)
    inverse.append((-inverse[mod % i]*(mod//i))%mod)
    g2.append((g2[-1]*inverse[-1])%mod)

h1=[1,1]
h2=[1,1]
iinverse=[0,1]
for i in range(2,n-i2+i1+1):
    h1.append((h1[-1]*i)%mod)
    iinverse.append((-iinverse[mod % i]*(mod//i))%mod)
    h2.append((h2[-1]*iinverse[-1])%mod)

for i in range(n+1):
    print((g1[n+1]*g2[i+1]*g2[n-i]%mod-(h1[n-i2+i1]*h2[i]*h2[n-i2+i1-i] if n-i2+i1>=i else 0)%mod)%mod)

Solution (Python):
from collections import defaultdict
n = int(input())
a = list(map(int, input().split()))

MOD = 10**9 + 7
MAX = n + 5
fact = [1 for _ in range(MAX)]
finv = [1 for _ in range(MAX)]
for i in range(2, MAX):
    fact[i] = fact[i - 1] * i % MOD
    finv[i] = pow(fact[i], MOD-2, MOD)

def comb(n: int, k: int) -> int:
    if n < k or n < 0 or k < 0:
        return 0
    return (fact[n] * finv[k] % MOD) * finv[n-k] % MOD


d = defaultdict(list)
for i in range(n+1):
    d[a[i]].append(i)
    if len(d[a[i]]) == 2:
        i1, i2 = sorted(d[a[i]])
        m1 = i1
        m2 = i2 - i1 - 1
        m3 = n - i2


ans = []
for k in range(1, n+2):
    ansi = comb(n+1, k) - comb(m1+m3, k-1)
    ansi = (ansi + MOD) % MOD
    ans.append(ansi)

for ansi in ans:
    print(ansi)

Solution (Python):
import sys
input = sys.stdin.readline

def main():
    N = int(input())
    a = list(map(int, input().split()))

    kai = [1] * (N+2)
    MOD = int(1e9) + 7
    for i in range(1, N+2):
        kai[i] *= kai[i-1] * i
        kai[i] %= MOD
    
    dic = {}
    for i in range(N+1):
        if a[i] in dic:
            left = dic[a[i]]
            right = N - i
        else:
            dic[a[i]] = i
    
    for i in range(1, N+2):
        tmp = kai[N+1] * pow(kai[N+1-i], MOD-2, MOD) * pow(kai[i], MOD-2, MOD)
        tmp %= MOD
        if i - 1 <= left + right:
            tmp2 = kai[left+right] * pow(kai[left+right+1-i], MOD-2, MOD) * pow(kai[i-1], MOD-2, MOD)
            tmp2 %= MOD
            tmp = (tmp + MOD - tmp2) % MOD
        print(tmp)

if __name__ == "__main__":
    main()

Solution (Python):
n = int(input())
A = list(map(int,input().split()))
mod = 10**9 + 7

IND = [-1] * (n+1)
for i in range(n+1):
    if IND[A[i]] != -1:
        bet = i - IND[A[i]] - 1
        break
    else:
        IND[A[i]] = i



M = [1]
mul = 1
for i in range(1, n+3):
    mul = (mul * i) % mod
    M.append(mul)



def inv(a, p):
    pp = p
    p -= 2
    ans = 1
    mul = a
    while p > 0:        
        if p % 2 == 1:
            ans = (ans * mul) % pp
            
        mul = (mul ** 2) % pp
        p //= 2
    return ans % pp



I = [1] + [inv(i, mod) for i in range(1, n+3)]
MI = [1]
mul = 1
for i in range(1, n+3):
    mul = (mul * I[i]) % mod
    MI.append(mul)




D = [0, 0, 1]
for i in range(3, n+3):
    D.append((D[-1] * (n+1-(i-1)) * I[i-2]) % mod)

def C(x, y):
    if x < y or x < 0 or y < 0:
        return 0
    elif x == 0 or y == 0:
        return 1
    else:
        ans = M[x]
        ans = (ans * MI[y]) % mod
        ans = (ans * MI[x-y]) % mod
        return ans



for k in range(1, n+1):
    ans = C(n-1, k)
    ans = (ans - C(n-1-bet, k-1)) % mod
    ans = (ans + 2 * C(n-1, k-1)) % mod
    ans = (ans + C(n-1, k-2)) % mod
    print(ans)
print(1)

Solution (Python):
def main():
    N = int(input())
    A = [int(a) for a in input().split()]
    div = pow(10, 9) + 7

    
    d = dict()
    for i in range(N+1):
        if A[i] not in d: d[A[i]] = [i]
        else: d[A[i]].append(i)

    i1, i2 = 0, 0
    for a in d:
        if len(d[a]) == 2:
            i1, i2 = d[a]
            break
    M = i1 + N-i2
    

    
    pow1 = [1, 1]
    for i in range(2, N+2):
        pow1.append(pow1[-1]*i % div)

    pow2 = []
    j = powquick(pow1[-1], div-2, div)
    pow2.append(j)
    for i in range(N, -1, -1):
        pow2.append(pow2[-1]*(i+1) % div)
    pow2 = pow2[::-1]


    
    
    
    

    
    
    
    
    

    for l in range(1, N+2):
        v = (pow1[N+1]*pow2[l]*pow2[N+1-l]) % div
        
        if l <= M+1:
            v -= (pow1[M]*pow2[l-1]*pow2[M-l+1]) % div
        print(v % div)

def powquick(x, y, div):
        if y == 0: return 1
        if y == 1: return x % div
        if y % 2 == 0: return pow(powquick(x, y // 2, div), 2) % div
        if y % 2 == 1: return pow(powquick(x, y// 2, div), 2) * x % div


if __name__ == '__main__':
    main()

Solution (Python):

def main():
    N = int(input())
    A = [int(a) for a in input().split()]
    div = pow(10, 9) + 7

    
    d = dict()
    for i in range(N+1):
        if A[i] not in d: d[A[i]] = [i]
        else: d[A[i]].append(i)

    i1, i2 = 0, 0
    for a in d:
        if len(d[a]) == 2:
            i1, i2 = d[a]
            break
    M = i1 + N-i2
    

    
    pow1 = [1, 1]
    for i in range(2, N+2):
        pow1.append(pow1[-1]*i % div)

    
    
    
    

    pow2 = [1, 1]
    inv = [0, 1]
    for i in range(2, N+2):
        inv.append((-inv[div % i]) *(div // i) % div)
        pow2.append(pow2[-1] * inv[-1] % div)

    for l in range(1, N+2):
        v = (pow1[N+1]*pow2[l]*pow2[N+1-l]) % div
        
        if l <= M+1:
            v -= (pow1[M]*pow2[l-1]*pow2[M-l+1]) % div
        print(v % div)








if __name__ == '__main__':
    main()

Solution (Python):
def main():
    N = int(input())
    A = [int(a) for a in input().split()]
    div = pow(10, 9) + 7

    
    d = dict()
    for i in range(N+1):
        if A[i] not in d: d[A[i]] = [i]
        else: d[A[i]].append(i)

    i1, i2 = 0, 0
    for a in d:
        if len(d[a]) == 2:
            i1, i2 = d[a]
            break
    M = i1 + N-i2
    

    
    pow1 = [1, 1]
    for i in range(2, N+2):
        pow1.append(pow1[-1]*i % div)

    
    
    
    

    pow2 = [1, 1]
    inv = [0, 1]
    for i in range(2, N+2):
        inv.append((-inv[div % i]) *(div // i) % div)
        pow2.append(pow2[-1] * inv[-1] % div)

    for l in range(1, N+2):
        v = (pow1[N+1]*pow2[l]*pow2[N+1-l]) % div
        
        if l <= M+1:
            v -= (pow1[M]*pow2[l-1]*pow2[M-l+1]) % div
        print(v % div)

def powquick(x, y, div):
        if y == 0: return 1
        if y == 1: return x % div
        if y % 2 == 0: return pow(powquick(x, y // 2, div), 2) % div
        if y % 2 == 1: return pow(powquick(x, y// 2, div), 2) * x % div


if __name__ == '__main__':
    main()

Solution (Python):

from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
import itertools
sys.setrecursionlimit(10**5)
stdin = sys.stdin
bisect_left = bisect.bisect_left
bisect_right = bisect.bisect_right
def LI(): return list(map(int, stdin.readline().split()))
def LF(): return list(map(float, stdin.readline().split()))
def LI_(): return list(map(lambda x: int(x)-1, stdin.readline().split()))
def II(): return int(stdin.readline())
def IF(): return float(stdin.readline())
def LS(): return list(map(list, stdin.readline().split()))
def S(): return list(stdin.readline().rstrip())
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = float('INF')


def A():
    a, b, c = LI()
    print(min(a+b,b+c,c+a))
    return


def B():
    def check(s):
        x = len(s)
        if x % 2:
            return False
        if s[:x // 2] == s[x // 2:]:
            return True
    s = S()
    for i in range(1,len(s)):
        if check(s[: - i]):
            print(len(s) - i)
            return


def C():
    II()
    a = LI()
    ans1 = a[-1::-2]
    ans2 = a[-2::-2][::-1]
    ans = ans1 + ans2
    print(*ans)
    return


def D():
    def power_func(a, b):
        """ a^b mod p を求める """
        """ bを2進数分解して高速累乗 """

        if b == 0: return 1
        if b % 2 == 0:
            d = power_func(a, b // 2)
            return d * d % mod
        if b % 2 == 1:
            return (a * power_func(a, b - 1)) % mod

    def combination_mod(n, k):
        """ power_funcを用いて(nCk) mod p を求める """ 
        """ nCk = n!/((n-k)!k!)を使用 """

        if n < 0 or k < 0 or n < k: return 0
        if n == 0 or k == 0: return 1
        a = factorial[n]
        b = invfactorial[k]
        c = invfactorial[n - k]
        return (a * b * c) % mod

    n = II() + 1
    a = LI()
    d = [0] * n
    for i in range(n):
        if d[a[i]]:
            a = d[a[i]] - 1
            c = n - i - 1
            break
        d[a[i]] = i + 1
    factorial = [1] * (n + 1)
    invfactorial = [1] * (n + 1)
    for i in range(1, n + 1):
        factorial[i] = (factorial[i - 1] * i) % mod
        invfactorial[i] = power_func(i, mod - 2) * invfactorial[i-1] % mod
    for i in range(1, n + 1):
        ans = combination_mod(n, i) - combination_mod(a + c, i - 1)
        print(ans%mod)
    return


if __name__ == '__main__':
    D()

Solution (Python):
from collections import Counter


class Mint:
    MOD = 1000000007  
    CACHE_FACTORIALS = [1, 1]

    def __init__(self, v):
        if self.__isally(v):
            self.v = v.v % self.MOD
        else:
            self.v = v % self.MOD

    @property
    def inv(self):
        return Mint(self.__minv(self.v))

    @classmethod
    def factorial(cls, v):
        for i in range(len(cls.CACHE_FACTORIALS), int(v) + 1):
            cls.CACHE_FACTORIALS.append(cls.CACHE_FACTORIALS[-1] * i % cls.MOD)
        return Mint(cls.CACHE_FACTORIALS[int(v)])

    @classmethod
    def perm(cls, n, r):
        if n < r or r < 0:
            return 0
        return cls.factorial(n) // cls.factorial(n - r)

    @classmethod
    def comb(cls, n, r):
        if n < r or r < 0:
            return 0
        return cls.perm(n, r) // cls.factorial(r)

    @classmethod
    def __isally(cls, v) -> bool:
        return isinstance(v, cls)

    @classmethod
    def __minv(cls, v) -> int:
        return pow(v, cls.MOD - 2, cls.MOD)

    @classmethod
    def __mpow(cls, v, w) -> int:
        return pow(v, w, cls.MOD)

    def __str__(self):
        return str(self.v)
    __repr__ = __str__

    def __int__(self):
        return self.v

    def __eq__(self, w):
        return self.v == w.v if self.__isally(w) else self.v == w

    def __add__(self, w):
        return Mint(self.v + w.v) if self.__isally(w) else Mint(self.v + w)
    __radd__ = __add__

    def __sub__(self, w):
        return Mint(self.v - w.v) if self.__isally(w) else Mint(self.v - w)

    def __rsub__(self, u):
        return Mint(u.v - self.v) if self.__isally(u) else Mint(u - self.v)

    def __mul__(self, w):
        return Mint(self.v * w.v) if self.__isally(w) else Mint(self.v * w)
    __rmul__ = __mul__

    def __floordiv__(self, w):
        return Mint(self.v * self.__minv(w.v)) if self.__isally(w) else \
            Mint(self.v * self.__minv(w))

    def __rfloordiv__(self, u):
        return Mint(u.v * self.__minv(self.v)) if self.__isally(u) else \
            Mint(u * self.__minv(self.v))

    def __pow__(self, w):
        return Mint(self.__mpow(self.v, w.v)) if self.__isally(w) else \
            Mint(self.__mpow(self.v, w))

    def __rpow__(self, u):
        return Mint(self.__mpow(u.v, self.v)) if self.__isally(u) else \
            Mint(self.__mpow(u, self.v))


N = int(input())
A = [int(s) for s in input().split()]
v = Counter(A).most_common(1)[0][0]
i = A.index(v)
j = A.index(v, i+1)
m = j - i - 1
for k in range(1, N + 2):
    ans = Mint.comb(N + 1, k) - Mint.comb(N - m - 1, k - 1)
    print(ans)

Solution (Python):
from collections import Counter


class Mint:
    MOD = 1000000007  
    CACHE_FACTORIALS = [1, 1]

    def __init__(self, v):
        if self.__isally(v):
            self.v = v.v % self.MOD
        else:
            self.v = v % self.MOD

    @property
    def inv(self):
        return Mint(self.__minv(self.v))

    @classmethod
    def factorial(cls, v):
        for i in range(len(cls.CACHE_FACTORIALS), int(v) + 1):
            cls.CACHE_FACTORIALS.append(cls.CACHE_FACTORIALS[-1] * i % cls.MOD)
        return Mint(cls.CACHE_FACTORIALS[int(v)])

    @classmethod
    def perm(cls, n, r):
        if n < r or r < 0:
            return 0
        return cls.factorial(n) // cls.factorial(n - r)

    @classmethod
    def comb(cls, n, r):
        if n < r or r < 0:
            return 0
        return cls.perm(n, r) // cls.factorial(r)

    @classmethod
    def __isally(cls, v) -> bool:
        return isinstance(v, cls)

    @classmethod
    def __minv(cls, v) -> int:
        return pow(v, cls.MOD - 2, cls.MOD)

    @classmethod
    def __mpow(cls, v, w) -> int:
        return pow(v, w, cls.MOD)

    def __str__(self):
        return str(self.v)
    __repr__ = __str__

    def __int__(self):
        return self.v

    def __eq__(self, w):
        return self.v == w.v if self.__isally(w) else self.v == w

    def __add__(self, w):
        return Mint(self.v + w.v) if self.__isally(w) else Mint(self.v + w)
    __radd__ = __add__

    def __sub__(self, w):
        return Mint(self.v - w.v) if self.__isally(w) else Mint(self.v - w)

    def __rsub__(self, u):
        return Mint(u.v - self.v) if self.__isally(u) else Mint(u - self.v)

    def __mul__(self, w):
        return Mint(self.v * w.v) if self.__isally(w) else Mint(self.v * w)
    __rmul__ = __mul__

    def __floordiv__(self, w):
        return Mint(self.v * self.__minv(w.v)) if self.__isally(w) else \
            Mint(self.v * self.__minv(w))

    def __rfloordiv__(self, u):
        return Mint(u.v * self.__minv(self.v)) if self.__isally(u) else \
            Mint(u * self.__minv(self.v))

    def __pow__(self, w):
        return Mint(self.__mpow(self.v, w.v)) if self.__isally(w) else \
            Mint(self.__mpow(self.v, w))

    def __rpow__(self, u):
        return Mint(self.__mpow(u.v, self.v)) if self.__isally(u) else \
            Mint(self.__mpow(u, self.v))


N = int(input())
A = [int(s) for s in input().split()]
v = Counter(A).most_common(1)[0][0]
i = A.index(v)
j = A.index(v, i+1)
l = i
m = j - i - 1
n = N - j
for k in range(1, N + 2):
    ans = Mint.comb(l + m + n, k) + Mint.comb(l + m + n, k - 1) * \
        2 - Mint.comb(l + n, k - 1) + Mint.comb(l + m + n, k - 2)
    print(ans)

Solution (Python):
n = int(input())
As = list(map(int, input().split()))
M = [-1]*n
p, q = 0, 1
for i in range(n+1):
  A = As[i]
  A = A-1
  if not(M[A] < 0):
    p, q = M[A], i
    break
  M[A] = i


MAX = 200000
MOD = 1000000007
fac = [0]*MAX
finv = [0]*MAX
inv = [0]*MAX
fac[0] = 1
fac[1] = 1
finv[0] = 1
finv[1] = 1
inv[1] = 1
for i in range(2, MAX):
  fac[i] = fac[i-1]*i%MOD
  inv[i] = MOD - inv[MOD%i]*(MOD//i)%MOD
  finv[i] = finv[i-1]*inv[i]%MOD
def COM(n, k):
  if n < 0 or k < 0 or n < k:
    return 0
  return fac[n]*(finv[k]*finv[n-k]%MOD)%MOD

for k in range(1, n+2):
  
  r1 = COM(n+1, k)
  r2 = COM(n+p-q, k-1)
  r = (r1-r2)%MOD
  print(r)

Solution (Python):
n = int(input())
a = [int(i) for i in input().split()]

mod = 10 ** 9 + 7
fac = [1]
inv = [1]
for i in range(1, n + 2) :
    fac.append(fac[-1] * i % mod)
    inv.append(pow(fac[-1], mod-2, mod))

visited = [-1] * (n + 1)
for i, aa in enumerate(a) :
    if visited[aa] < 0 :
        visited[aa] = i
    else :
        l, r = visited[aa], i
        break

def comb(n, r) :
    if n < r or r < 0 :
        return 0
        
    return fac[n] * inv[n-r] * inv[r] % mod

for i in range(1, n + 2) :
    print((comb(n+1, i)-comb(n+l-r, i-1))%mod)

Solution (Python):

import sys
from collections import Counter
INF = float("inf")

MOD = 1000000007  


class Combination(object):
    def __init__(self, N, mod):
        self.N = N
        self.MOD = mod
        self.fac = [0] * (N+1)
        self.finv = [0] * (N+1)
        self.inv = [0] * (N+1)
        self.cmb_init()

    def cmb_init(self):
        self.fac[0] = 1
        self.fac[1] = 1
        self.finv[0] = 1
        self.finv[1] = 1
        self.inv[1] = 1
        for i in range(2, self.N+1):
            self.fac[i] = self.fac[i-1]*i % self.MOD
            self.inv[i] = -self.inv[self.MOD % i]*(self.MOD//i) % self.MOD
            self.finv[i] = self.finv[i-1]*self.inv[i] % self.MOD

    def __call__(self, n, k):
        if n < k:
            return 0
        if n < 0 or k < 0:
            return 0
        return self.fac[n] * (self.finv[k]*self.finv[n-k] % self.MOD) % self.MOD


def solve(n: int, a: "List[int]"):
    (m, _), = Counter(a).most_common(1)
    left = a.index(m)
    right = a.index(m, left+1)
    cmb = Combination(n+1, MOD)
    for i in range(1, n+2):
        print((cmb(n+1, i)-cmb(n-right+left, i-1)) % MOD)
    return


def main():

    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    n = int(next(tokens))  
    a = [int(next(tokens)) for _ in range(n+1)]  
    solve(n, a)


if __name__ == '__main__':
    main()

Solution (Python):
N = int(input())
A = list(map(int, input().split()))
MOD = 10**9 + 7

fact = [1 for _ in range(N + 10)]
invFact = [0 for _ in range(N + 10)]

def modInv(a):
    b = MOD
    u = 1
    v = 0
    while b :
        t = a // b
        a -= t * b
        a, b = b, a
        u -= t * v
        u, v = v, u
    u %= MOD
    return u

for i in range(1, N + 10):
    fact[i] = (fact[i - 1] * i) % MOD
    invFact[i] = modInv(fact[i])

index = [[] for _ in range(N + 1)]

for i, a in enumerate(A):
    index[a].append(i)

left = 0
right = 0
for count in index:
    if len(count) == 2:
        left = min(count)
        right = max(count)

def comb(n, r):
    if 0 < r < n:
        return (fact[n] * invFact[r] % MOD) * invFact[n - r] % MOD
    if r == 0 or r == n:
        return 1
    return 0

les = left + (N - right)

for k in range(1, N + 2):
    r = comb(les, k - 1)
    ans = comb(N + 1, k) - r
    print(ans % MOD)

Solution (Python):
import collections
n=int(input())
A=[int(i) for i in input().split()]
a=collections.Counter(A).most_common()[0][0]
AA=[i for i, x in enumerate(A) if x==a]
a1,a2,d=AA[0],AA[1],AA[1]-AA[0]

mod=10**9+7
n_max=2*10**5
F,FI=[0]*(n_max+1),[0]*(n_max+1)
F[0],FI[0]=1,1
for i in range(n_max):
  F[i+1]=(F[i]*(i+1))%mod
  FI[i+1]=pow(F[i+1],mod-2,mod)
def comb(x,y):
  return (F[x]*FI[x-y]*FI[y])%mod

for i in range(n+1):
  ans=comb(n+1,i+1)%mod
  if 0<=i<=a1+n-a2:
    ans-=comb(a1+n-a2,i)
  print(ans%mod)

Solution (Python):
import collections
n=int(input())
A=[int(i) for i in input().split()]
a=collections.Counter(A).most_common()[0][0]
AA=[i for i, x in enumerate(A) if x==a]
a1,a2,d=AA[0],AA[1],AA[1]-AA[0]

mod=10**9+7
n_max=2*10**5
F,FI=[0]*(n_max+1),[0]*(n_max+1)
F[0],FI[0]=1,1
for i in range(n_max):
  F[i+1]=(F[i]*(i+1))%mod
  FI[i+1]=pow(F[i+1],mod-2,mod)
def comb(x,y):
  return (F[x]*FI[x-y]*FI[y])%mod

for i in range(n+1):
  ans=comb(n+1,i+1)%mod
  if 0<=i<=a1+n-a2:
    ans-=comb(a1+n-a2,i)
  print(ans%mod)

Solution (Python):
import sys
input=sys.stdin.readline
n=int(input())
a_list=list(map(int,input().split()))
num=[[] for i in range(n)]
for i in range(n+1):
    num[a_list[i]-1].append(i)
for i in num:
    if len(i)==2:
        x=i[0]
        y=n-i[1]
INF=10**9+7
z=x+y
def modinv(a,m):
    b=m
    (x,lastx)=(0,1)
    (y,lasty)=(1,0)
    while not b==0:
        q=a//b
        (a,b)=(b,a%b)
        (x, lastx) = (lastx - q * x, x)
        (y, lasty) = (lasty - q * y, y)
    return lastx%m
a=n+1
b=1
for i in range(n+1):
    print((a-b)%INF)
    a=(a*(n-i)*modinv(i+2,INF))%INF
    b=(b*(z-i)*modinv(i+1,INF))%INF