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):
from collections import Counter
n = int(input())
a = list(map(int,input().split()))
kasanari = Counter(a).most_common()[0][0]
mod = 10**9+7
"""
2 3 1 4 5 6 1 7 8 9
Y Y C C C C C X X X
k個選ぶ. 全部 nCk-3Ck
"""
basho = []
for cnt, i in enumerate(a):
	if i == kasanari:
		basho.append(cnt)

def cmb(n, r, mod):
	if (r < 0) or (n < r):
		return 0
	r = min(r, n-r)
	return fact[n]*factinv[r]*factinv[n-r]%mod

N = 2*10**5  
fact = [1, 1]  
factinv = [1, 1]  
inv = [0, 1]  

for i in range(2, N+1):
	fact.append((fact[-1]*i)%mod)
	inv.append((-inv[mod%i]*(mod//i))%mod)
	factinv.append((factinv[-1]*inv[-1])%mod)

for i in range(1, n+2):
	print((cmb(n+1, i, mod)-cmb(n-basho[1]+basho[0], i-1, mod))%mod)

Solution (Python):
mod = 10 ** 9 + 7

SIZE = 10 ** 5 + 5
fact = [0] * SIZE
inv = [0] * SIZE
finv = [0] * SIZE
fact[0], fact[1] = 1, 1
inv[1] = 1
finv[0], finv[1] = 1, 1
for i in range(2, SIZE):
    fact[i] = fact[i - 1] * i % mod
    inv[i] = mod - inv[mod % i] * (mod // i) % mod
    finv[i] = finv[i - 1] * inv[i] % mod


def nCr(n, r):
    if n < 0 or r < 0 or n < r:
        return 0
    return fact[n] * (finv[r] * finv[n - r] % mod) % mod


from collections import Counter


n = int(input())
A = list(map(int, input().split()))
counterA = Counter(A)
duplicate = 0
for num, count in counterA.items():
    if count == 2:
        duplicate = num
        break

duplicate_pos = []
for i, a in enumerate(A):
    if a == duplicate:
        duplicate_pos.append(i)

first, second, *_ = duplicate_pos

for k in range(1, n+2):
    base = nCr(n+1, k)
    duplicate_pattern = nCr(first + n-second, k-1)
    print((base - duplicate_pattern) % mod)

Solution (Python):

printn = lambda x: print(x,end='')
inn = lambda : int(input())
inl   = lambda: list(map(int, input().split()))
inm   = lambda:      map(int, input().split())
ins = lambda : input().strip()
DBG = True  and False
BIG = 10**18
R = 10**9 + 7

def ddprint(x):
  if DBG:
    print(x)

def modinv2(x,r):
  return pow(x,r-2,r)

def comb(n,k):
    ret = fact[n]*modinv2(fact[n-k]*fact[k],R)%R
    
    return ret

n = inn()
a = inl()
fact = [1]*(n+1)
for i in range(1,n+1):
    fact[i] = (fact[i-1]*i)%R
ddprint(fact)
c = [-1]*(n+1)
for m in range(n+1):
    x = a[m]
    if c[x]>=0:
        i = c[x]
        j = m+1
        break
    c[x] = m+1

print(n) 
for k in range(2,n):
    
    v0 = comb(n-1,k) if k<=n-1 else 0
    
    v2 = comb(n-1,k-2) if k>=2 else 0
    
    v1 = 2*comb(n-1,k-1) - \
         (0 if n-j+i<k-1 else comb(n-j+i,k-1))
    
    print((v0+v1+v2)%R)
if n>1:
    print(n if j==i+1 else n+1) 
print(1)

Solution (Python):


import math



from collections import deque
from collections import Counter




n=int(input())
a=list(map(int,input().split()))
s=set()
for i in range(n+1):
    if a[i] not in s:
        s.add(a[i])
    else:
        q=i
p=a.index(a[q])
q=n-q
Mod=10**9+7
M=n+2 
fac=[0]*M
finv=[0]*M
inv=[0]*M

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

COMinit()
for i in range(1,n+2):
    print((COM(n+1,i)-COM(p+q,i-1))%Mod)

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

def cmb(n, r, mod):
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % mod
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 )

f=[-1]*(n+1)
l,r=0,0
for i in range(n+1):
  ai=a[i]
  if f[ai]==-1:
    f[ai]=i
  else:
    l=f[ai]
    r=n-i
    break
for k in range(1,n+2):
  a=cmb(n+1,k,mod)
  if l+r>=k-1:
	  a-=cmb(l+r,k-1,mod)
  
  print(a%mod)

Solution (Python):
n = int(input())
a = list(map(int, input().split()))

b = sorted(a[::])
for i in range(n):
    if b[i] == b[i+1]:
        d = b[i]

l, r = -1, -1
for i in range(n+1):
    if l < 0:
        if a[i] == d:
            l = i
    else:
        if a[i] == d:
            r = i

f = [1 for _ in range(n+2)]
f_inv = [1 for _ in range(n+2)]
mod = 10 ** 9 + 7
for i in range(1, n+2):
    f[i] = f[i-1] * i % mod
    f_inv[i] = pow(f[i], mod-2, mod)

def comb(n, k):
    return f[n] * f_inv[k] * f_inv[n-k] % mod


for k in range(1, n+2):
    ans = 0

    if k >= 2:
        ans += comb(n-1, k-2)
        ans %= mod

    if n - 1 >= k:
        ans += comb(n-1, k)
        ans %= mod

    if n >= k:
        ans += 2 * comb(n-1, k-1)
        ans %= mod

    if n + l - r >= k - 1:
        ans -= comb(n+l-r, k-1)
        ans %= mod

    print(ans)

Solution (Python):
n=int(input())
a=list(map(int,input().split()))

dub=[-1]*(n+1)
duble=[]

for i,aa in enumerate(a):
    if dub[aa]==-1:
        dub[aa]=i
    else:
        duble=[dub[aa],i]


def cmb(n, r, p):
    if (r < 0) or (n < r):
        return 0
    r = min(r, n - r)
    return fact[n] * factinv[r] * factinv[n-r] % p
p = 10**9+7 
N = 10 ** 6  
fact = [1, 1]  
factinv = [1, 1]  
inv = [0, 1]  
for i in range(2, N + 1):
    fact.append((fact[-1] * i) % p)
    inv.append((-inv[p % i] * (p // i)) % p)
    factinv.append((factinv[-1] * inv[-1]) % p)



duble.sort()
left=duble[0]
right=duble[1]

for i in range(1,n+2):
    ans=cmb(n+1,i,p)-cmb(n+1-2-(right-1-left),i-1,p)
    print(ans%p)

Solution (Python):
class cmbs(object):
    def __init__(self, mod):
        self.mod = mod
        self.g1 = [1, 1]
        self.g2 = [1, 1]
        inverse = [0, 1]
        for i in range(2, 10 ** 6 + 1):
            self.g1.append((self.g1[-1] * i) % mod)
            inverse.append((-inverse[mod % i] * (mod // i)) % mod)
            self.g2.append((self.g2[-1] * inverse[-1]) % mod)

    def cmb(self, n, r):
        if n > 10 ** 6:
            return self.cmbl(n, r)
        return self.cmbr(n, r)

    def cmbr(self, n, r):
        if r < 0 or r > n:
            return 0
        r = min(r, n - r)
        return self.g1[n] * self.g2[r] * self.g2[n-r] % self.mod

    def cmbl(self, n, r):
        t = 1
        r = min(r, n-r)
        for i in range(n - r + 1, n + 1):
            t = t * i % self.mod
        return t * self.g2[r] % self.mod
def main():
    N = int(input())
    A = list(map(int, input().split()))
    d = {}
    dif = 0
    for i, v in enumerate(A):
        if v not in d:
            d[v] = i
        else:
            dif = i - d[v]
            break
    mod = 10**9 + 7
    c = cmbs(mod)
    print(N)
    if N == 1:
        print(N)
        return
    if dif == 1:
        for i in range(2, N):
            if N-1 >= i:
                r = c.cmb(N-1, i-2) + c.cmb(N-1, i-1) + c.cmb(N-1, i)
            else:
                r = c.cmb(N-1, i-2) + c.cmb(N-1, i-1)
            print(r % mod)
        print(N)
        print(1)
        return
    for i in range(2, N):
        r = c.cmb(N-1, i-2) + c.cmb(N-1, i-1)*2 - c.cmb(N-dif, i-1) + c.cmb(N-1, i)
        print(r % mod)
    print(N+1)
    print(1)
main()

Solution (Python):
class nCrMod():
    def __init__(self, mod):
        self.mod = mod
        self.fac = [1, 1]
        self.finv = [1, 1]
        self.inv = [0, 1]

    def prep(self, n):
        mod = self.mod
        f, fi = self.fac[-1], self.finv[-1]
        for i in range(len(self.fac), n + 1):
            fn = f * i % mod
            v = -self.inv[mod % i] * (mod // i) % mod
            fin = fi * v % mod
            f, fi = fn, fin
            self.fac.append(f)
            self.finv.append(fi)
            self.inv.append(v)

    def __call__(self, n, r):
        if len(self.fac) <= n:
            self.prep(n)
        return self.fac[n] * self.finv[r] * self.finv[n - r] % self.mod

def main():
    N = int(input())
    A = list(map(int, input().split()))
    d = {}
    f, s = 0, 0
    for i, a in enumerate(A):
        if a in d:
            break
        d[a] = i
    f, s = d[a], i
    mod = 10**9 + 7
    nCr = nCrMod(mod)
    for i in range(1, N + 2):
        if i > N + 1 - (s - f):
            print(nCr(N + 1, i))
        else:
            print((nCr(N + 1, i) - nCr(N - (s - f), i - 1)) % mod)
main()

Solution (Python):
import sys
from collections import Counter

sys.setrecursionlimit(10 ** 7)
f_inf = float('inf')
mod = 10 ** 9 + 7


class CmbMod:
    def __init__(self, n, p):
        """
        二項係数nCr(n個の区別できるものからr個のものを選ぶ組み合わせの数)をpで割った余りを求める
        """
        self.n = n
        self.p = p
        self.fact = [1, 1]
        self.factinv = [1, 1]
        self.inv = [0, 1]

    def cmb_mod(self, n, r):
        """
        二項係数nCr(mod p)をO(r)にて計算。nが大きいがrは小さい時に使用。
        """
        numer, denom = 1, 1
        for i in range(r):
            numer = (numer * (n - i)) % self.p
            denom = (denom * (i + 1)) % self.p
        return (numer * pow(denom, self.p - 2, self.p)) % self.p

    def prep(self):
        """
        二項係数nCr(mod p)をO(1)で求める為の前処理をO(N)にて実行。
        """
        for i in range(2, self.n + 1):
            self.fact.append((self.fact[-1] * i) % self.p)
            self.inv.append((-self.inv[self.p % i] * (self.p // i)) % self.p)
            self.factinv.append((self.factinv[-1] * self.inv[-1]) % self.p)

    def cmb_mod_with_prep(self, n, r):
        """
        二項係数nCr(mod p)をO(1)で求める。事前にprepを実行する事。
        """
        if (r < 0) or (n < r):
            return 0
        r = min(r, n - r)
        return self.fact[n] * self.factinv[r] * self.factinv[n - r] % self.p


def resolve():
    n = int(input())
    A = list(map(int, input().split()))

    D = Counter(A)
    dup = 0
    for k, v in D.items():
        if v == 2:
            dup = k
            break

    flg = 1
    right, left = 0, 0
    for i in range(n + 1):
        if flg and A[i] == dup:
            left = i
            flg ^= 1
        elif A[i] == dup:
            right = i
            break

    remain = n - (right - left)
    cmb = CmbMod(n + 1, mod)
    cmb.prep()
    for i in range(1, n + 2):
        res = cmb.cmb_mod_with_prep(n + 1, i) - cmb.cmb_mod_with_prep(remain, i - 1)
        print(res % mod)


if __name__ == '__main__':
    resolve()

Solution (Python):
import sys
from collections import Counter

sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline
f_inf = float('inf')
mod = 10 ** 9 + 7


def resolve():
    n = int(input())
    A = list(map(int, input().split()))
    D = Counter(A)

    for k, v in D.items():
        if v == 2:
            db = k
            break

    flg = 1
    right, left = 0, 0
    for i in range(n + 1):
        if flg and A[i] == db:
            left = i
            flg ^= 1
        elif A[i] == db:
            right = i
            break

    length = n - (right - left)

    
    def cmb(n, r, mod):
        if (r < 0) or (n < r):
            return 0
        r = min(r, n - r)
        return fact[n] * factinv[r] * factinv[n - r] % mod

    fact = [1, 1]
    factinv = [1, 1]
    inv = [0, 1]

    for i in range(2, n + 2):
        fact.append((fact[-1] * i) % mod)
        inv.append((-inv[mod % i] * (mod // i)) % mod)
        factinv.append((factinv[-1] * inv[-1]) % mod)

    def cmb_mod(n, r, mod):
        x, y = 1, 1
        for i in range(r):
            x = (x * (n - i)) % mod
            y = (y * (i + 1)) % mod
        return (x * pow(y, mod - 2, mod)) % mod

    for i in range(1, n + 2):
        res = cmb(n + 1, i, mod) - cmb(length, i - 1, mod)
        print(res % mod)


if __name__ == '__main__':
    resolve()

Solution (Python):
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush,heapify
from bisect import bisect_left,bisect_right 
import sys,math,itertools,fractions,pprint
sys.setrecursionlimit(10**8)
mod = 10**9+7
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))

n = inp()
a = inpl()
s = set()
for i in range(n+1):
    if a[i] in s:
        last = n-i
        t = a[i]
        break
    s.add(a[i])
for i in range(n+1):
    if a[i] == t:
        fir = i
        break 
soto = fir + last
class Combination:
    """
    comb = Combination(1000000)
    print(comb(5, 3))  
    """
    def __init__(self, n_max, mod=10**9+7):
        self.mod = mod
        self.modinv = self.make_modinv_list(n_max)
        self.fac, self.facinv = self.make_factorial_list(n_max)

    def __call__(self, n, r):
        return self.fac[n] * self.facinv[r] % self.mod * self.facinv[n-r] % self.mod

    def make_factorial_list(self, n):
        
        
        fac = [1]
        facinv = [1]
        for i in range(1, n+1):
            fac.append(fac[i-1] * i % self.mod)
            facinv.append(facinv[i-1] * self.modinv[i] % self.mod)
        return fac, facinv

    def make_modinv_list(self, n):
        
        modinv = [0] * (n+1)
        modinv[1] = 1
        for i in range(2, n+1):
            modinv[i] = self.mod - self.mod//i * modinv[self.mod%i] % self.mod
        return modinv

comb = Combination(2*10**5+10)

for i in range(1,n+2):
    rm = 0
    if i <= soto+1:
        rm = comb(soto,i-1)
    print((comb(n+1,i) - rm)%mod)

Solution (Python):
from math import factorial

n = int(input())
a = list(map(int,input().split()))
se = set()
mod = 10**9+7

for i,j in enumerate(a):
    if j in se:
        two = i
    else:
        se.add(j)

one = a.index(a[two])

def prepare(n, MOD):
    facts = [1]*(n+1)
    for i in range(1, n+1):
        facts[i] = facts[i-1]*i%MOD
    invs = [1]*(n+1)
    invs[n] = pow(facts[n], MOD-2, MOD)
    for i in range(0, n)[::-1]:
        invs[i] = invs[i+1] * (i+1) % MOD
    return facts, invs

facts,invs = prepare(n+1,mod)

def make_combi(facts,invs,n,r,mod):
    return facts[n] * invs[r] * invs[n - r] %mod

for i in range(1,n+2):
    point = make_combi(facts,invs,n+1,i,mod)
    if one+n-two >= i-1:
        point -= make_combi(facts,invs,one+n-two,i-1,mod)
    print(point%mod)

Solution (Python):
def cmb(n, r, p):
  if (r < 0) or (n < r):
    return 0
  r = min(r, n - r)
  return fac[n] * finv[r] * finv[n-r] % p

M = pow(10,6)+10
MOD = pow(10,9)+7

fac = [-1]*(M+1); fac[0] = 1; fac[1] = 1
finv = [-1]*(M+1); finv[0] = 1; finv[1] = 1
inv = [-1]*(M+1); inv[0] = 0; inv[1] = 1
for i in range(2,M+1):
  fac[i] = fac[i-1]*i%MOD
  inv[i] = MOD - inv[MOD%i]*(MOD//i)%MOD
  finv[i] = finv[i-1]*inv[i]%MOD




N = int(input())
A = list(map(int,input().split()))
dic = {}
for i in range(N+1):
  if A[i] not in dic:
    dic[A[i]] = i
  else:
    left = dic[A[i]]
    right = i
    break



for i in range(1,N+2): 
  kosu = i
  total = cmb(N+1,kosu,MOD)
  outside = left + N-right
  dob = cmb(outside,kosu-1,MOD)
  ans = (total - dob)%MOD
  print(ans)

Solution (Python):
class Calc:
    def __init__(self, max_value, mod):
        """combination(max_value, all)"""
        fact = [-1] * (max_value + 1)
        fact[0] = 1
        fact[1] = 1
        for x in range(2, max_value + 1):
            fact[x] = x * fact[x - 1] % mod

        invs = [1] * (max_value + 1)
        invs[max_value] = pow(fact[max_value], mod - 2, mod)
        for x in range(max_value - 1, 0, -1):
            invs[x] = invs[x + 1] * (x + 1) % mod

        self.fact = fact
        self.invs = invs
        self.mod = mod

    def nCr(self, n, r):
        r = min(n - r, r)
        if r < 0: return 0
        if r == 0: return 1
        if r == 1: return n
        return self.fact[n] * self.invs[r] * self.invs[n - r] % self.mod

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


def main():
    MOD = 10 ** 9 + 7

    N = int(input())
    A = map(int, input().split())

    B = [-1] * (N + 1)  
    d = None  
    for i, x in enumerate(A):
        if ~B[x]:
            d = B[x], i
            break
        B[x] = i

    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    

    calc = Calc(max_value=N + 1, mod=MOD)
    ans = []
    Y = d[1] - 1 - d[0]
    for k in range(1, N + 2):
        ans.append((calc.nCr(N + 1, k) - calc.nCr(N + 1 - 2 - Y, k - 1)) % MOD)

    print(*ans, sep='\n')


if __name__ == '__main__':
    main()

Solution (Python):
class Calc:
    def __init__(self, max_value, mod):
        """combination(max_value, all)"""
        fact = [-1] * (max_value + 1)
        fact[0] = 1
        fact[1] = 1
        for x in range(2, max_value + 1):
            fact[x] = x * fact[x - 1] % mod

        invs = [1] * (max_value + 1)
        invs[max_value] = pow(fact[max_value], mod - 2, mod)
        for x in range(max_value - 1, 0, -1):
            invs[x] = invs[x + 1] * (x + 1) % mod

        self.fact = fact
        self.invs = invs
        self.mod = mod

    def nCr(self, n, r):
        r = min(n - r, r)
        if r < 0: return 0
        if r == 0: return 1
        if r == 1: return n
        return self.fact[n] * self.invs[r] * self.invs[n - r] % self.mod

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


def main():
    MOD = 10 ** 9 + 7

    N = int(input())
    A = map(int, input().split())

    B = [-1] * (N + 1)  
    d = None  
    for i, x in enumerate(A):
        if ~B[x]:
            d = B[x], i
            break
        B[x] = i

    
    
    
    
    
    
    
    
    
    
    
    
    
    
    

    calc = Calc(max_value=N + 1, mod=MOD)
    ans = []
    Y = d[1] - 1 - d[0]
    div2 = pow(2, MOD - 2, MOD)
    for k in range(1, N + 2):
        t = (
                    calc.nCr(N + 1, k)
                    - (
                            calc.nCr(N + 1 - Y, k)
                            - calc.nCr(N + 1 - 2 - Y, k)
                            - calc.nCr(N + 1 - 2 - Y, k - 2)
                    ) * div2 % MOD
            ) % MOD
        ans.append(t)

    print(*ans, sep='\n')


if __name__ == '__main__':
    main()

Solution (Python):
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 9)
MOD = 10 ** 9 + 7

class Factorial:
    def __init__(self, n, mod):
        self.f = [1]
        self.mod = mod
        for j in range(1, n + 1):
            self.f.append(self.f[-1] * j % mod)
        self.i = [pow(self.f[-1], mod - 2, mod)]
        for j in range(n, 0, -1):
            self.i.append(self.i[-1] * j % mod)
        self.i.reverse()
    def factorial(self, j):
        return self.f[j]
    def ifactorial(self, j):
        return self.i[j]
    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




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

lst = [-1] * (N + 1)
for i in range(N + 1):
    a = A[i]
    if lst[a] == -1:
        lst[a] = i
    else:
        left = lst[a]
        right = i
        break

F = Factorial(N + 1, MOD).comb

for i in range(1, N + 2):
    if left + N - right >= i - 1:
        tmp = F(N + 1, i) - F(left + (N- right), i - 1)
    else:
        tmp = F(N + 1, i)
    print (tmp % MOD)

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

MAX = 10**5+100
MOD = 10**9+7
fact = [0]*MAX 
inv = [0]*MAX 
finv = [0]*MAX 
fact[0] = 1
fact[1] = 1
finv[0] = 1
finv[1] = 1
inv[1] = 1
    
for i in range(2, MAX):
    fact[i] = fact[i-1]*i%MOD
    inv[i] = MOD-inv[MOD%i]*(MOD//i)%MOD
    finv[i] = finv[i-1]*inv[i]%MOD

def C(n, r):
    if n<r:
        return 0
    if n<0 or r<0:
        return 0
    return fact[n]*(finv[r]*finv[n-r]%MOD)%MOD

n = int(input())
a = list(map(int, input().split()))
idx = defaultdict(list)

for i in range(n+1):
    idx[a[i]].append(i)

for i in range(1, n+1):
    if len(idx[i])==2:
        f = idx[i][0]
        s = idx[i][1]
        break

for k in range(1, n+2):
    print((C(n-1, k)+2*C(n-1, k-1)-C(n+f-s, k-1)+C(n-1, k-2))%MOD)

Solution (Python):
def cmb(N, r, mod):
    if ( r<0 or r>N ):
        return 0
    r = min(r, N-r)
    return g1[N] * g2[r] * g2[N-r] % mod

g1 = [1, 1] 
g2 = [1, 1] 
inverse = [0, 1] 
mod = 10 ** 9 + 7

n = int(input())
lis = list(map(int,input().split()))
li = [-1] * n

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 )

for i in range(n+1):
    if li[lis[i]-1] != -1:
        left = li[lis[i]-1]+1
        right = i+1
        break
    else:li[lis[i]-1] = i

for k in range(1,n+2):
  
    ans = cmb(n+1,k,mod)-cmb(left+n-right,k-1,mod)
    if ans < 0:
        ans += mod
    print(ans)

Solution (Python):
def cmb(N, r, mod):
    if ( r<0 or r>N ):
        return 0
    r = min(r, N-r)
    return g1[N] * g2[r] * g2[N-r] % mod

g1 = [1, 1] 
g2 = [1, 1] 
inverse = [0, 1] 
mod = 10 ** 9 + 7

n = int(input())
lis = list(map(int,input().split()))
li = [-1] * n

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 )

for i in range(n+1):
    if li[lis[i]-1] != -1:
        left = li[lis[i]-1]+1
        right = i+1
        break
    else:li[lis[i]-1] = i

for k in range(1,n+2):
  
    ans = cmb(n+1,k,mod)-cmb(left+n-right,k-1,mod)
    if ans < 0:
        ans += mod
    print(ans)

Solution (Python):
from collections import Counter

class Combination:
    def __init__(self, size):
        self.size = size + 2
        self.fact = [1, 1] + [0] * size
        self.factInv = [1, 1] + [0] * size
        self.inv = [0, 1] + [0] * size

        for i in range(2, self.size):
            self.fact[i] = self.fact[i - 1] * i % MOD
            self.inv[i] = -self.inv[MOD % i] * (MOD // i) % MOD
            self.factInv[i] = self.factInv[i - 1] * self.inv[i] % MOD

    def npr(self, n, r):
        if n < r or n < 0 or r < 0:
            return 0
        return self.fact[n] * self.factInv[n - r] % MOD

    def ncr(self, n, r):
        if n < r or n < 0 or r < 0:
            return 0
        return self.fact[n] * (self.factInv[r] * self.factInv[n - r] % MOD) % MOD

    def nhr(self, n, r):  
        return self.ncr(n + r - 1, n - 1)

N = int(input())
A = list(map(int, input().split()))
MOD = 10**9 + 7
comb = Combination(N + 100)

cntA = Counter(A)
X = [a for a, c in cntA.items() if c == 2][0]
l, r = [i for i, a in enumerate(A) if a == X]

ans = [N]
for leng in range(2, N + 2):
    M = comb.ncr(N + 1, leng)

    L = l + (N - r)
    D = comb.ncr(L, leng - 1)
    ans.append((M - D) % MOD)

print(*ans, sep='\n')

Solution (Python):
def cmb(n, r, p):
	if (r<0) or (n<r):
		return 0
	r=min(r, n-r)
	return fact[n]*factinv[r]*factinv[n-r]%p

p=10**9+7
N=10**6
fact=[1,1]
factinv=[1,1]
inv=[0,1]

for i in range(2, N+1):
	fact.append((fact[-1]*i)%p)
	inv.append((-inv[p%i]*(p//i)%p))
	factinv.append((factinv[-1]*inv[-1])%p)


N=int(input())
A=list(map(int,input().split()))
index=[-1]*N
for i,a in enumerate(A):
    if index[a-1]!=-1:
        dup_first,dup_second=index[a-1],i
        break
    index[a-1]=i

mod=10**9+7
n=dup_first
m=N-dup_second
l=n+m
for k in range(1,N+2):
    if k==1:
        print(N)
        continue
    ans=(cmb(N+1,k,mod)-cmb(l,k-1,mod))%mod
    print(ans)

Solution (Python):


import sys






























def main():
    mod = 1000000007                
    inf = float('inf')              
    
    sys.setrecursionlimit(10**6)    
    def input(): return sys.stdin.readline().rstrip()
    def ii():    return int(input())
    def mi():    return map(int, input().split())
    def mi_0():  return map(lambda x: int(x)-1, input().split())
    def lmi():   return list(map(int, input().split()))
    def lmi_0(): return list(map(lambda x: int(x)-1, input().split()))
    def li():    return list(input())
    
    def find_duplicate(L):
        n = len(L)
        table = [None] * n
        for i, num in enumerate(L):
            if table[num] is not None:
                return table[num], i
            else:
                table[num] = i

    def make_factorial_table(size, mod):
        '''
        fact_mod[i] は i! % mod を表す。fact_mod[0] ~ facto_mod[size] まで計算可能なテーブルを返す
        >>> make_factorial_table(20, 10**9+7)
        [1, 1, 2, 6, 24, 120, 720, 5040, 40320, 362880, 3628800, 39916800, 479001600, 227020758, 178290591, 674358851, 789741546, 425606191, 660911389, 557316307, 146326063]
        '''
        fact_mod = [1] * (size + 1)
        for i in range(1, size + 1):
            fact_mod[i] = (fact_mod[i - 1] * i) % mod
        return fact_mod

    def combination(n, r, mod, fact_table):
        '''
        フェルマーの小定理 
        a ^ p-1 ≡ 1 (mod p)
        a ^ p-2 ≡ 1/a (mod p) (逆元)
        nCr = (n!) / ((n-r)! * r!) だが、mod p の世界ではこの分母を逆元を用いて計算しておくことが可能
        
        >>> m = 1000000007
        >>> fact_table = make_factorial_table(100, m)
        >>> combination(10, 5, m, fact_table)
        252
        >>> combination(100, 50, m, fact_table)
        538992043
        '''
        if r > n:
            return 0
        numerator = fact_table[n]
        denominator = (fact_table[n-r] * fact_table[r]) % mod
        
        return (numerator * pow(denominator, mod-2, mod)) % mod

    n = ii()
    L = lmi_0()
    i, j = find_duplicate(L)
    fact = make_factorial_table(n+1, mod)

    for l in range(1, n+2):
        print((combination(n+1, l, mod, fact) - combination(i+n-j, l-1, mod, fact)) % mod)




if __name__ == "__main__":
    main()

Solution (Python):
def exteuc(a, b):
    
    if b == 0:
        return 1, 0, a
    y, x, v = exteuc(b, a % b)
    y -= (a//b) * x
    return x, y, v


def modinv(a, mod):
    x, _, _ = exteuc(a, mod)
    return x % mod


def main():
    MOD = 10**9 + 7
    N = int(input())
    A = list(map(int, input().split(' ')))
    
    
    dup_first_index, dup_second_index = -1, -1
    indices = [-1 for _ in range(N)]
    for i, a in enumerate(A):
        if indices[a - 1] != -1:
            dup_first_index, dup_second_index = indices[a - 1], i
            break
        indices[a - 1] = i
    
    s = dup_first_index + N - dup_second_index
    
    ans = [0 for _ in range(N + 1)]
    comb_n1, comb_s = N + 1, 1  
    for i in range(N + 1):
        ans[i] = comb_n1  
        comb_n1 *= (N + 1) - (i + 1)
        comb_n1 *= modinv(i + 2, MOD)
        comb_n1 %= MOD
        if s >= i:
            ans[i] -= comb_s  
            comb_s *= s - i
            comb_s *= modinv(i + 1, MOD)
            comb_s %= MOD
        ans[i] %= MOD
    for a in ans:
        print(a)


if __name__ == '__main__':
    main()

Solution (Python):
n = int(input())
a = list(map(int, input().split()))
mod = pow(10, 9) + 7
num = [-1] * (n + 1)
for i in range(n + 1):
    if num[a[i]] == -1:
        num[a[i]] = i
    else:
        samei, samej = num[a[i]], i
        break
x = n + samei - samej
same = 1
comb = n + 1
print(comb - 1)
for i in range(2, n + 2):
    comb = (comb * (n - i + 2) * pow(i, mod - 2, mod)) % mod
    if i - 1 <= x:
        same = (same * (x - i + 2) * pow(i - 1, mod - 2, mod)) % mod
    else:
        same = 0
    print((comb - same) % mod)

Solution (Python):

class Combination:
    def __init__(self, n, mod):
        fact = [0]*(n+1)
        ifact = [0]*(n+1)
        fact[0] = 1
        for i in range(1, n+1):
            fact[i] = (fact[i-1]*i) % mod
        
        ifact[n] = pow(fact[n], mod-2, mod)
        for i in range(n, 0, -1):
            ifact[i-1] = (ifact[i]*i) % mod

        self.n = n
        self.mod = mod
        self.fact = fact
        self.ifact = ifact

    def choose(self, n, r):
        if r < 0 or r > n:
            return 0
        ret = (self.fact[n]*self.ifact[r]) % self.mod
        return (ret*self.ifact[n-r]) % self.mod


n = int(input())
*a, = map(int, input().split())
indices = [-1]*n
l, r = 0, 0
for i in range(n+1):
    if indices[a[i]-1] != -1:
        l = indices[a[i]-1]
        r = i
        break
    indices[a[i]-1] = i

MOD = 10**9+7
n += 1
c = Combination(n, MOD)
k = n-(r-l+1)
for i in range(1, n+1):
    ans = c.choose(n, i)
    if i == 1:
        ans -= 1
    elif k >= (i-1):
        ans -= c.choose(k, i-1)
    print((ans+MOD) % MOD)

Solution (Python):

class Combination:
    def __init__(self, n, mod):
        fact = [0]*(n+1)
        ifact = [0]*(n+1)
        fact[0] = 1
        for i in range(1, n+1):
            fact[i] = (fact[i-1]*i) % mod
        
        ifact[n] = pow(fact[n], mod-2, mod)
        for i in range(n, 0, -1):
            ifact[i-1] = (ifact[i]*i) % mod

        self.n = n
        self.mod = mod
        self.fact = fact
        self.ifact = ifact

    def choose(self, n, r):
        if r < 0 or r > n:
            return 0
        ret = (self.fact[n]*self.ifact[r]) % self.mod
        return (ret*self.ifact[n-r]) % self.mod


n = int(input())
*a, = map(int, input().split())
indices = [-1]*n
l, r = 0, 0
for i in range(n+1):
    if indices[a[i]-1] != -1:
        l = indices[a[i]-1]
        r = i
        break
    indices[a[i]-1] = i

MOD = 10**9+7
c = Combination(n+2, MOD)
for i in range(1, n+2):
    ans = c.choose(n+1, i) - c.choose(l+n-r, i-1)
    ans = (ans+MOD) % MOD
    print(ans)

Solution (Python):
n = int(input())
al = list(map(int, input().split()))

import collections
c = collections.Counter(al)
cc = c.most_common()[0][0]

da = ([i for i, x in enumerate(al) if x ==cc ][0])
db = ([i for i, x in enumerate(al) if x ==cc ][1])

def cmb(n, r, p):
    if (r < 0) or (n < r):
        return 0
    r = min(r, n - r)
    return fact[n] * factinv[r] * factinv[n-r] % p

p = 10 ** 9 + 7
fact = [1, 1]  
factinv = [1, 1]  
inv = [0, 1]  
 
for i in range(2, n + 2):
    fact.append((fact[-1] * i) % p)
    inv.append((-inv[p % i] * (p // i)) % p)
    factinv.append((factinv[-1] * inv[-1]) % p)

print(n)
for i in range(2,n+2):
    print((cmb(n-1,i,p)+ cmb(n-1,i-1,p)*2 -cmb(da+n-db,i-1,p) + cmb(n-1,i-2,p)) % p)