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.



Sample input:
3
1 2 1 3


Sample output:
3
5
4
1

Submission status: Wrong Answer

Solution code:
def comb(n, r, mod):
    if (r < 0 or r > n):
        return 0
    r = min(r, n-r)
    return (g1[n] * g2[r] % mod) * g2[n-r] % mod


mod = 10**9+7  # 出力の制限
N = 10**6
g1 = [1, 1]  # 元テーブル
g2 = [1, 1]  # 逆元テーブル
inverse = [0, 1]  # 逆元テーブル計算用テーブル

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


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

appeared = set()
dup_right = 0
dup = 0
for i, x in enumerate(a):
    if x in appeared:
        dup_right = n - i
        dup = x
        break
    appeared.add(x)
dup_left = 0
for i, x in enumerate(a):
    if x == dup:
        dup_left = i
        break

for k in range(1, n + 2):
    print(comb(n + 1, k, MOD) - comb(dup_right + dup_left, k - 1, MOD) % MOD)

Submission status: Wrong Answer

Solution code:
def comb(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


mod = 10**9+7  # 出力の制限
N = 10**6
g1 = [1, 1]  # 元テーブル
g2 = [1, 1]  # 逆元テーブル
inverse = [0, 1]  # 逆元テーブル計算用テーブル

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


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

appeared = set()
dup_right = 0
dup = 0
for i, x in enumerate(a):
    if x in appeared:
        dup_right = n - i
        dup = x
        break
    appeared.add(x)
dup_left = 0
for i, x in enumerate(a):
    if x == dup:
        dup_left = i
        break

for i in range(1, n + 2):
    print(comb(n + 1, i, MOD) - comb(dup_right + dup_left, i - 1, MOD) % MOD)

Submission status: Wrong Answer

Solution code:
def comb(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


mod = 10**9+7  # 出力の制限
N = 2 * 10**5
g1 = [1, 1]  # 元テーブル
g2 = [1, 1]  # 逆元テーブル
inverse = [0, 1]  # 逆元テーブル計算用テーブル

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


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

appeared = set()
dup_right = 0
dup = 0
for i, x in enumerate(a):
    if x in appeared:
        dup_right = n - i
        dup = x
        break
    appeared.add(x)
dup_left = 0
for i, x in enumerate(a):
    if x == dup:
        dup_left = i
        break

print(n)
for i in range(2, n + 2):
    res = comb(n + 1, i, MOD)
    if dup_right + dup_left >= i - 1:
        res = res - comb(dup_right + dup_left, i - 1, MOD) % MOD
    print(res)

Submission status: Wrong Answer

Solution code:
def framod(n, mod, a=1):
    for i in range(1, n+1):
        a = a * i % mod
    return a


def power(n, r, mod):
    if r == 0:
        return 1
    if r % 2 == 0:
        return power(n*n % mod, r//2, mod) % mod
    if r % 2 == 1:
        return n * power(n, r-1, mod) % mod


def comb(n, k, mod):
    a = framod(n, mod)
    b = framod(k, mod)
    c = framod(n-k, mod)
    return (a * power(b, mod-2, mod) * power(c, mod-2, mod)) % mod


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

appeared = set()
dup_right = 0
dup = 0
for i, x in enumerate(a):
    if x in appeared:
        dup_right = n - i
        dup = x
        break
    appeared.add(x)
dup_left = 0
for i, x in enumerate(a):
    if x == dup:
        dup_left = i
        break

print("dup_right", dup_right)
print("dup_left", dup_left)

print(n)
for i in range(2, n + 2):
    res = comb(n + 1, i, MOD)
    if dup_right + dup_left >= i - 1:
        res = res - comb(dup_right + dup_left, i - 1, MOD) % MOD
    print(res)

Submission status: Wrong Answer

Solution code:
n=int(input())
l=list(map(int,input().split()))
memo={}

for i in range(n+1):
    if l[i]in memo:
        g=l[i]
        x,y=memo[g],i
        break
    memo[l[i]]=i
mod=10**9+7

fact=[1]*(n+1+1)
inv=[1]*(n+1+1)
for i in range(2,n+1+1):
    fact[i]=i*fact[i-1]%mod
inv[-1]=pow(fact[-1],mod-2,mod)
for i in range(n+1,1,-1):
    inv[i-1]=inv[i]*i%mod
def comb(x,y):return fact[x]*inv[y]%mod*inv[x-y]%mod if x>=y>=0 else 0
for i in range(1,n+2):print(comb(n+1,i)-comb(x+n-y,i-1))

Submission status: Wrong Answer

Solution code:
n=int(input())
l=list(map(int,input().split()))
memo={}

for i in range(n+1):
    if l[i]in memo:
        g=l[i]
        x,y=memo[g],i
        break
    memo[l[i]]=i
mod=10**9+7

fact=[1]*(n+1+1)
inv=[1]*(n+1+1)
for i in range(2,n+1+1):
    fact[i]=i*fact[i-1]%mod
inv[-1]=pow(fact[-1],mod-2,mod)
for i in range(n+1,1,-1):
    inv[i-1]=inv[i]*i%mod
def comb(x,y):return fact[x]*inv[y]%mod*inv[x-y]%mod if x>=y>=0 else 0
print(n)
for i in range(2,n+2):
    ans=comb(n+1,i)
    if n-y+x>=i-1:ans-=comb(x+n-y,i-1)
    else:ans-=comb(x,i-1)-comb(n-y,i-1)
    
    print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())
l=list(map(int,input().split()))
memo={}

for i in range(n+1):
    if l[i]in memo:
        g=l[i]
        x,y=memo[g],i
        break
    memo[l[i]]=i
mod=10**9+7
print(x,y)
fact=[1]*(n+1+1)
inv=[1]*(n+1+1)
for i in range(2,n+1+1):
    fact[i]=i*fact[i-1]%mod
inv[-1]=pow(fact[-1],mod-2,mod)
for i in range(n+1,1,-1):
    inv[i-1]=inv[i]*i%mod
def comb(x,y):return fact[x]*inv[y]%mod*inv[x-y]%mod if x>=y>=0 else 0
print(n)
for i in range(2,n+2):
    ans=comb(n+1,i)
    if n-y+x>=i-1:ans-=comb(x+n-y,i-1)
    else:ans-=comb(x,i-1)-comb(n-y,i-1)
    
    print(ans)

Submission status: Wrong Answer

Solution code:
from sys import stdin, setrecursionlimit
from collections import defaultdict


def initialize_cmb(m, mod=10 ** 9 + 7):
    fac = [1]
    finv = [1]
    inv = [0] * (m + 1)
    if m >= 1:
        fac.append(1)
        finv.append(1)
        inv[1] = 1
        pre_fac = 1
        pre_finv = 1
        for i in range(2, m + 1):
            pre_fac = pre_fac * i % mod
            fac.append(pre_fac)
            inv[i] = mod - inv[mod % i] * (mod // i) % mod
            pre_finv = pre_finv * inv[i] % mod
            finv.append(pre_finv)
    return fac, finv


def cmb(n, k, fac, finv, mod=10 ** 9 + 7):
    if n < k:
        return 0
    if n < 0 or k < 0:
        return 0
    return fac[n] * (finv[k] * finv[n - k] % mod) % mod


def main():
    mod = 10 ** 9 + 7
    input = stdin.buffer.readline
    n = int(input())
    a = list(map(int, input().split()))

    arr = [-1] * n

    i1 = i2 = 0

    for i in range(n + 1):
        if arr[a[i] - 1] == -1:
            arr[a[i] - 1] = i
        else:
            i1 = arr[a[i] - 1]
            i2 = i
            break

    fac, finv = initialize_cmb(n + 1, mod)

    for k in range(1, n + 2):
        ans = cmb(n + 1, k, fac, finv, mod)
        if k - 1 <= n - i2 + i1:
            ans -= cmb(n - i2 + i1, k - 1, fac, finv, mod)
        print(ans)


if __name__ == "__main__":
    setrecursionlimit(10000)
    main()

Submission status: Wrong Answer

Solution code:
from sys import stdin, setrecursionlimit
from collections import defaultdict


def initialize_cmb(m, mod=10 ** 9 + 7):
    fac = [1]
    finv = [1]
    inv = [0] * (m + 1)
    if m >= 1:
        fac.append(1)
        finv.append(1)
        inv[1] = 1
        pre_fac = 1
        pre_finv = 1
        for i in range(2, m + 1):
            pre_fac = pre_fac * i % mod
            fac.append(pre_fac)
            inv[i] = mod - inv[mod % i] * (mod // i) % mod
            pre_finv = pre_finv * inv[i] % mod
            finv.append(pre_finv)
    return fac, finv


def cmb(n, k, fac, finv, mod=10 ** 9 + 7):
    if n < k:
        return 0
    if n < 0 or k < 0:
        return 0
    return fac[n] * (finv[k] * finv[n - k] % mod) % mod


def main():
    mod = 10 ** 9 + 7
    input = stdin.buffer.readline
    n = int(input())
    a = list(map(int, input().split()))

    arr = [-1] * n

    i1 = i2 = 0

    for i in range(n + 1):
        if arr[a[i] - 1] == -1:
            arr[a[i] - 1] = i
        else:
            i1 = arr[a[i] - 1]
            i2 = i
            break

    fac, finv = initialize_cmb(n + 1, mod)

    for k in range(1, n + 2):
        ans = cmb(n + 1, k, fac, finv, mod)
        if k - 1 <= n - i2:
            ans -= cmb(n - i2, k - 1, fac, finv, mod)
        print(ans)


if __name__ == "__main__":
    setrecursionlimit(10000)
    main()

Submission status: Wrong Answer

Solution code:
n=int(input())
a=list(map(int,input().split()))
d=dict()
#コンビネーション逆元
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


mod = 10**9+7 #出力の制限
N = 10**6
g1 = [1, 1] # 元テーブル
g2 = [1, 1] #逆元テーブル
inverse = [0, 1] #逆元テーブル計算用テーブル


for i in range( 2, N + 1 ):
    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 a[i] not in d:
        d[a[i]]=i
    else:
        idx1=d[a[i]]
        idx2=i
        break
for i in range(1,n+2):
    ans=cmb(n+1,i,mod)
    ans=(ans-cmb(idx1,i-1,mod)-cmb(n-idx2,i-1,mod)+mod)%mod
    if i==1:
        ans+=1
    print(ans%mod)

Submission status: Wrong Answer

Solution code:
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(n-second, k-1)
    print((base - duplicate_pattern) % mod)

Submission status: Wrong Answer

Solution code:
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(n-second, k-1)
    print(base - duplicate_pattern)

Submission status: Wrong Answer

Solution code:
#import sys
#import numpy as np
import math
#import itertools
#from fractions import Fraction
#import itertools
from collections import deque
from collections import Counter
#import heapq
#from fractions  import gcd
#input=sys.stdin.readline
#import bisect
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
#finvに逆元、facに階乗のmod
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))

Submission status: Wrong Answer

Solution code:
n=int(input())
a=list(map(int,input().split()))
mod=pow(10,9)+7
#ans=[int(input()) for _ in range(n+1)]
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 )
# 二つあるやつの左の方の左にl個、右のやつの右のほうにr個数字がある
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)
  a-=cmb(l+r,k-1,mod)
  #print(a==ans[k-1],a,ans[k-1])
  print(a)

Submission status: Wrong Answer

Solution code:
n=int(input())
a=list(map(int,input().split()))
mod=pow(10,9)+7
#ans=[int(input()) for _ in range(n+1)]
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
print(n)
for k in range(2,n+2):
  a=cmb(n+1,k,mod)
  if l+r>=k-1:
    a-=cmb(l+r,k-1,mod)
  #print(a==ans[k-1],a,ans[k-1])
  print(a)

Submission status: Wrong Answer

Solution code:
n=int(input())
a=list(map(int,input().split()))
mod=pow(10,9)+7
#ans=[int(input()) for _ in range(n+1)]
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):
  ai=a[i]
  if f[ai]==-1:
    f[ai]=i
  else:
    l=f[ai]
    r=n-i
    break
print(n)
for k in range(2,n+2):
  a=cmb(n+1,k,mod)
  if l+r>=k-1:
    a-=cmb(l+r,k-1,mod)
  #print(a==ans[k-1],a,ans[k-1])
  print(a)

Submission status: Wrong Answer

Solution code:
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):
  ai=a[i]
  if f[ai]==-1:
    f[ai]=i
  else:
    l=f[ai]
    r=n-i
    break
print(n)
for k in range(2,n+2):
  a=cmb(n+1,k,mod)
  if l+r>=k-1:
    a-=cmb(l+r,k-1,mod)
  if l>=k-1:
    a+=cmb(r,k-1,mod)
  if r>=k-1:
    a+=cmb(l,k-1,mod)
  print(a)

Submission status: Wrong Answer

Solution code:
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):
  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)
  a-=cmb(l+r,k,mod)-cmb(r,k,mod)-cmb(l,k,mod)
  print(a)

Submission status: Wrong Answer

Solution code:
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  # N は必要分だけ用意する
fact = [1, 1]  # fact[n] = (n! mod p)
factinv = [1, 1]  # factinv[n] = ((n!)^(-1) mod p)
inv = [0, 1]  # factinv 計算用
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)

#cmb(n, c, p)

duble.sort()
left=duble[0]
right=duble[1]
#print(left,middle,right)
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)

Submission status: Wrong Answer

Solution code:
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  # N は必要分だけ用意する
fact = [1, 1]  # fact[n] = (n! mod p)
factinv = [1, 1]  # factinv[n] = ((n!)^(-1) mod p)
inv = [0, 1]  # factinv 計算用
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)

#cmb(n, c, p)

duble.sort()
left=duble[0]
right=duble[1]
#print(left,middle,right)
for i in range(1,n+2):
    if i==1:
        print(n)
    else:
        ans=cmb(n+1,i,p)-cmb(n+1-2-(right-1-left),i-1,p)
        print(ans)

Submission status: Wrong Answer

Solution code:
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  # N は必要分だけ用意する
fact = [1, 1]  # fact[n] = (n! mod p)
factinv = [1, 1]  # factinv[n] = ((n!)^(-1) mod p)
inv = [0, 1]  # factinv 計算用
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)

#cmb(n, c, p)

duble.sort()
left=duble[0]
middle=duble[1]-duble[0]-1
right=n-duble[1]
#print(left,middle,right)
for i in range(1,n+2):
    if i==1:
        print(n)
    else:
        ans=cmb(n+1,i,p)-cmb(left,i-1,p)-cmb(right,i-1,p)
        print(ans)

Submission status: Wrong Answer

Solution code:
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  # N は必要分だけ用意する
fact = [1, 1]  # fact[n] = (n! mod p)
factinv = [1, 1]  # factinv[n] = ((n!)^(-1) mod p)
inv = [0, 1]  # factinv 計算用
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)

#cmb(n, c, p)

duble.sort()
left=duble[0]
middle=duble[1]-duble[0]-1
right=n-duble[1]
print(left,middle,right)
for i in range(1,n+2):
    if i==1:
        print(n)
    else:
        ans=cmb(n+1,i,p)-cmb(left,i-1,p)-cmb(right,i-1,p)
        print(ans)

Submission status: Wrong Answer

Solution code:
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
    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)
    if dif == 0:
        print(N)
    else:
        print(N+1)
    print(1)
main()

Submission status: Wrong Answer

Solution code:
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 == 2:
        print(N)
        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)
    if dif == 0:
        print(N)
    else:
        print(N+1)
    print(1)
main()

Submission status: Wrong Answer

Solution code:
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))
main()

Submission status: Wrong Answer

Solution code:
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)

Submission status: Wrong Answer

Solution code:
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

#print(cmb(5, 4, 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
#print(left,right)

for i in range(1,N+2): #1個からN+1個選ぶ
  kosu = i
  total = cmb(N+1,kosu,MOD)
  outside = left + N-right
  dob = cmb(outside,kosu-1,MOD)
  ans = total - dob
  print(ans)

Submission status: Wrong Answer

Solution code:
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,5)+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

#print(cmb(5, 4, 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
#print(left,right)

for i in range(1,N+2): #1個からN+1個選ぶ
  kosu = i
  total = cmb(N+1,kosu,MOD)
  outside = left + N-right
  dob = cmb(outside,kosu-1,MOD)
  ans = total - dob
  print(ans)

Submission status: Wrong Answer

Solution code:
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,5)+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

print(cmb(5, 4, 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
#print(left,right)

for i in range(1,N+2): #1個からN+1個選ぶ
  kosu = i
  total = cmb(N+1,kosu,MOD)
  outside = left + N-right
  dob = cmb(outside,kosu-1,MOD)
  ans = total - dob
  print(ans)

Submission status: Wrong Answer

Solution code:
from math import factorial

n = int(input())
a = list(map(int,input().split()))
se = set()

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

def combination(n,r,mod=10**9+7):
    r=min(r,n-r)
    up,down=1,1
    for i in range(r):
        up=up*(n-i)%mod
        down=down*(i+1)%mod
    return up*pow(down,mod-2,mod)%mod

for i in range(1,n+2):
    point = combination(n+1,i)
    if i == 1:
        print(n)
        continue
    if n+1-key >= i:
        point -= combination(n+1-key,i)
    print(point)

Submission status: Wrong Answer

Solution code:
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):
    a = A[i]
    if lst[a] == -1:
        lst[a] = i
    else:
        left = A[a]
        right = i
        break

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

for i in range(1, N + 2):
    if i == 1:
        print (N)
        continue
    if i == N + 1:
        print (1)
        continue
    if i == 2:
        tmp = F(N - 1, i) + F(N - 1, i - 1) * 2
        print (tmp % MOD)
        continue
    if i <= N - 1:
        tmp = F(N - 1, i) + F(N - 1, i - 1) * 2 + F(N - 1, i - 2)
        print (tmp % MOD)
        continue
    if i == N:
        tmp = F(N - 1, i - 1) * 2 + F(N - 1, i - 2)
        print (tmp % MOD)
        continue

Submission status: Wrong Answer

Solution code:
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):
  #     print(nCr(n+1,k,mod),nCr(left+n-right,k-1,mod))
    print(cmb(n+1,k,mod)-cmb(left+n-right,k-1,mod))