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:
from operator import mul
from functools import reduce

def cmb(n,r):
    r = min(n-r,r)
    if r == 0: return 1
    over = reduce(mul, range(n, n - r, -1))
    under = reduce(mul, range(1,r + 1))
    return over // under

mod=10**9+7
n=int(input())
a=list(map(int,input().split()))
data=[0]*(n+1)
for i in range(n+1):
    data[a[i]]+=1
for i in range(1,n+1):
    if data[i]==2:
        b=i
        break
l=[]
for i in range(n+1):
    if a[i]==b:
        l.append(i)
c=l[1]-l[0]+1
for k in range(1,n+3-c):
    ans=cmb(n+1,k)%mod-cmb(n+1-c,k-1)
    print(ans%mod)

Submission status: Wrong Answer

Solution code:
MOD = 10 ** 9 + 7
n = int(input())
a = list(map(int, input().split()))
lst = [-1] * n

# O(N)
for i in range(n + 1):
    if lst[a[i] - 1] != -1:
        first = lst[a[i] - 1]
        second = i
        break
    lst[a[i] - 1] = i

print (first, second)    
left = first
right = n - second

U = 10 ** 5 + 1
def power_mod(a, n):
    if n == 0:
        return 1
    x = power_mod(a//2)

def make_fact(fact, fact_inv):
    for i in range(1, U + 1):
        fact[i] = (fact[i - 1] * i) % MOD
    fact_inv[U] = pow(fact[U], MOD - 2, MOD)
    for i in range(U, 0, -1):
        fact_inv[i - 1] = (fact_inv[i] * i) % MOD

def comb(n, k):
    print ('A')
    if k < 0 or n < k:
        return 0
    x = fact[n]
    x *= fact_inv[k]
    x %= MOD
    x *= fact_inv[n - k]
    x %= MOD
    return x

fact = [1] * (U + 1)
fact_inv = [1] * (U + 1)
make_fact(fact, fact_inv)

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

Submission status: Wrong Answer

Solution code:
MOD = 10 ** 9 + 7
n = int(input())
a = list(map(int, input().split()))
lst = [-1] * n

# O(N)
for i in range(n + 1):
    if lst[a[i] - 1] != -1:
        first = lst[a[i] - 1]
        second = i
        break
    lst[a[i] - 1] = i

# print (first, second)    
left = first
right = n - second
# print (left, right)

N = n + 1
tmp1 = 1
tmp2 = 1
# O(N ^ 2)
for i in range(1, n + 2):
    tmp1 = (tmp1 * (N + 1 - i))//i
    if i == 1:
        tmp2 = 1
    elif left + right < i - 1:
        tmp2 = 0
    else:
        tmp2 = (tmp2 * (left + right + 1 - (i - 1))) // (i - 1)
    print (tmp1 - tmp2)

Submission status: Wrong Answer

Solution code:
import sys
from collections import defaultdict
from math import factorial
input = sys.stdin.buffer.readline
mod = 10**9+7

# comb init
nmax = 10 ** 5 + 1  # change here
fac = [0] * (nmax + 1)
finv = [0] * (nmax + 1)
inv = [0] * (nmax + 1)
fac[0] = 1
fac[1] = 1
finv[0] = 1
finv[1] = 1
inv[1] = 1
for i in range(2, nmax):
    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 comb(n, r):
    if n < r:
        return 0
    else:
        return (fac[n] * ((finv[r] * finv[n - r]) % mod)) % mod


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

pos = defaultdict(lambda: -1)
for i in range(N+1):
    if pos[a[i]] == -1:
        pos[a[i]] = i
    else:
        same = (pos[a[i]], i)
        break

for k in range(1, N+2):
    print((comb(N+1, k) - comb(same[0] + (N-same[1]), k-1))%mod)

Submission status: Wrong Answer

Solution code:
import sys
from collections import defaultdict
from math import factorial
input = sys.stdin.buffer.readline
mod = 10**9+7

# comb init
nmax = 10 ** 5 + 1  # change here
fac = [0] * (nmax + 1)
finv = [0] * (nmax + 1)
inv = [0] * (nmax + 1)
fac[0] = 1
fac[1] = 1
finv[0] = 1
finv[1] = 1
inv[1] = 1
for i in range(2, nmax):
    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 comb(n, r):
    if n < r:
        return 0
    else:
        return (fac[n] * ((finv[r] * finv[n - r]) % mod)) % mod


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

pos = defaultdict(lambda: -1)
for i in range(N+1):
    if pos[a[i]] == -1:
        pos[a[i]] = i
    else:
        same = (pos[a[i]], i)
        break

for k in range(1, N+2):
    print(comb(N+1, k) - comb(same[0] + (N-same[1]), k-1))

Submission status: Wrong Answer

Solution code:
def find_power(n):
    # 0!からn!までのびっくりを出してくれる関数
    powlist=[0]*(n+1)
    powlist[0]=1
    powlist[1]=1
    for i in range(2,n+1):
        powlist[i]=powlist[i-1]*i%(10**9+7)
    return powlist

def find_inv_power(n):
    #0!からn!までの逆元を10**9+7で割ったあまりリストを作る関数
    powlist=find_power(n)
    check=powlist[-1]
    first=1
    uselist=[0]*(n+1)
    secondlist=[0]*30
    secondlist[0]=check
    secondlist[1]=check**2
    for i in range(28):
        secondlist[i+2]=(secondlist[i+1]**2)%(10**9+7)
    a=format(10**9+5,"b")
    for j in range(30):
        if a[29-j]=="1":
            first=(first*secondlist[j])%(10**9+7)
    uselist[n]=first
    for i in range(n,0,-1):
        uselist[i-1]=(uselist[i]*i)%(10**9+7)
    return uselist

n=int(input())
lists=list(map(int,input().split()))
import collections
c=collections.Counter(lists)
d=c.most_common()
number=d[0][0]
listss=[]
for i in range(n+1):
    if lists[i]==number:
        listss.append(i+1)
a,b=listss[0],listss[1]


powlist=find_power(n+1)
invlist=find_inv_power(n+1)

def combi(n,r):
    a=powlist
    b=invlist
    if n<r:
        return 0
    elif n>=r:
        return (a[n]*b[r]*b[n-r])%(10**9+7)
    
for i in range(1,n+2):
    if i==1:
        print(n)
    elif 2<=i and i<=n+1-(b-a):
        print(combi(n-1,i)+combi(n-1,i-2)+2*combi(n-1,i-1)-combi(n+a-b,i-1))
    else:
        print(combi(n+1,i))

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int, input().split()))
F = []
P = []
for i in range(N + 1):
    F.append(True)

for i in range(len(A)):
    tmp = A[i]
    if F[tmp]:
        F[tmp] = False
    else:
        D = tmp

for i in range(len(A)):
    if D == A[i] :
        P.append(i)


R = P[0] - 0 + (N - 1) - P[1]

def Factorial(a):
    ans = 1
    for i in range(1, a + 1):
        ans *= i
    return ans

def Comb(n, r):
    return int(Factorial(n) / (Factorial(r) * Factorial(n - r)))

for i in range(1, N + 2):
    print(Comb(N + 1, i) - Comb(R, i - 1))

Submission status: Wrong Answer

Solution code:
from collections import Counter

mod = 10**9 + 7

def init(n):
    # 階乗とその逆元をグローバルに定義
    global factorial, inverse
    # 0-indexedでそれぞれ１で初期化
    factorial = [1]*(n+1)
    inverse = [1]*(n+1)

    fact = 1
    for p in range(1,n+1):
        fact *= p
        fact %= mod
        factorial[p] = fact

    inv = pow(fact, mod-2, mod)
    inverse[n] = inv
    for p in range(2,n+1)[::-1]:
        inv *= p
        inv %= mod
        inverse[p-1] = inv

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

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

b = Counter(a).most_common()[0][0]
pos = []
for i, ai in enumerate(a):
    if ai == b:
        pos.append(i)

l, r = pos
L, R = l, n-r

init(n+1)

for k in range(1, n+2):
    ans = comb(n+1, k) - comb(L+R, k-1)
    print(ans)

Submission status: Wrong Answer

Solution code:
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
import math
import bisect
import random
from itertools import permutations, accumulate, combinations, product
import sys
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, floor
from operator import mul
from functools import reduce


INF = float('inf')
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return sys.stdin.readline().strip()
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]
mod = 1000000007


n = I() + 1
A = LI()
D = defaultdict(lambda:-1)
for i in range(n):
    if D[A[i]] != -1:
        l = D[A[i]]
        r = n - i - 1
        break
    else:
        D[A[i]] = i


fac = [1] * (n + 1)
inv = [1] * (n + 1)
i = 1
for j in range(1, n + 1):
    i = i * j % mod
    fac[j] = i
    inv[j] = pow(i, mod - 2, mod)



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


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

Submission status: Wrong Answer

Solution code:
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
import math
import bisect
import random
from itertools import permutations, accumulate, combinations, product
import sys
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, floor
from operator import mul
from functools import reduce


INF = float('inf')
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return sys.stdin.readline().strip()
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]
mod = 1000000007


n = I() + 1
A = LI()
D = defaultdict(lambda:-1)
for i in range(n):
    if D[A[i]] != -1:
        l = D[A[i]]
        r = n - i - 1
        break
    else:
        D[A[i]] = i


fac = [1] * (n + 1)
inv = [1] * (n + 1)
i = 1
for j in range(1, n + 1):
    i = i * j % mod
    fac[j] = i
    inv[j] = pow(i, mod - 2, mod)



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


for j in range(1, n + 1):
    print(comb(n, j) - comb(r + l, j - 1))

Submission status: Wrong Answer

Solution code:
n=int(input())
a=[int(j) for j in input().split()]
mod=10**9+7
l=[-1]*(n+1)
ind=[]
for i in range(n+1):
    if l[a[i]]!=-1:
        ind=[l[a[i]],i]
        break
    l[a[i]]=i
U = 2*10**5
MOD = 10**9+7
 
fact = [1]*(U+1)
fact_inv = [1]*(U+1)
 
for i in range(1,U+1):
  fact[i] = (fact[i-1]*i)%MOD
fact_inv[U] = pow(fact[U],MOD-2,MOD)
 
for i in range(U,0,-1):
	fact_inv[i-1] = (fact_inv[i]*i)%MOD
 
def comb(n,k):
  if k < 0 or k > n:
    return 0
  x = fact[n]
  x *= fact_inv[k]
  x %= MOD
  x *= fact_inv[n-k]
  x %= MOD
  return x

i,j=ind
for k in range(1,n+2):
    if k==1:
        print(n)
    else:
        print(comb(n+1,k)-comb(i+n-j,k-1))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
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):
  if table[a[i]] != -1:
    d = [table[a[i]], i]
    break
  table[a[i]] = i
print(N)
for i in range(2, N + 1):
  x = f.combi(N + 1, i)
  y = 0
  z = 0
  w = 0
  if N + d[0] + 1 - d[1] >= i:
    w = f.combi(d[0] + N - d[1] + 1, i)
    if d[0] >= i:
      w -= f.combi(d[0], i)
    if N + d[0] - d[1] >= i:
      w -= f.combi(d[0] + N - d[1], i)
  print(x - w)
print(1)

Submission status: Wrong Answer

Solution code:
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):
  if table[a[i]] != -1:
    d = [table[a[i]], i]
    break
  table[a[i]] = i
print(N)
for i in range(2, N + 1):
  x = f.combi(N + 1, i)
  y = 0
  z = 0
  w = 0
  if N + d[0] + 1 - d[1] >= i:
    w = f.combi(d[0] + N - d[1] + 1, i) 
    if N + d[0] - d[1] >= i:
      w -= f.combi(d[0] + N - d[1], i)
  print(x - w)
print(1)

Submission status: Wrong Answer

Solution code:
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):
  if table[a[i]] != -1:
    d = [table[a[i]], i]
    break
  table[a[i]] = i
print(N)
for i in range(2, N + 1):
  x = f.combi(N + 1, i)
  y = 0
  z = 0
  w = 0
  if N - d[1] + 1 >= i:
    #print(N - d[1], i - 1)
    y = f.combi(N - d[1] + 1, i)
  if d[0] >= i:
    z = f.combi(d[0], i)
  if N + d[0] + 1 - d[1] >= i:
    w = f.combi(d[0] + N - d[1] + 1, i)
    w -= y + z
  print(x - w)
print(1)

Submission status: Wrong Answer

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


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

mc = ModComb(210000)

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))

Submission status: Wrong Answer

Solution code:
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[-1] * i % mod)
            inv.append(mod - inv[mod % i] * (mod // i) % mod)
            finv.append(finv[-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


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

mc = ModComb(10 ** 5 + 10)

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))

Submission status: Wrong Answer

Solution code:
#D問題
mod = 10**9+7
N = int(input())
A = list(map(int,input().split()))
ind = [-1 for i in range(N)]
indset = []
for i in range(N+1):
    if ind[A[i]-1] == -1:
        ind[A[i]-1] = i
    else:
        indset = [ind[A[i]-1],i]

left = indset[0]
right = N-indset[1]
tan = left+right
#print(tan)
fact = [1]
for i in range(N+1):
    fact.append(fact[-1]*(i+1))

for i in range(N+1):
    if i == 0:
        print(N+1)
    else:
        I = i+1
        total = fact[N+1]//(fact[I]*fact[N+1-I])
        if tan >= i:
            deg = fact[tan]//(fact[i]*fact[tan-i])
        else:
            deg = 0
        #print(total,deg)
        print((total-deg)%mod)

Submission status: Wrong Answer

Solution code:
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
c = p + n - q
for i in range(n+1):
    comb = comb*(n+1-i)//(i+1)
    if c >= i:
        comb2 = 1
        for j in range(i):
            comb2 = comb2*(c-j)//(j+1)
            print((comb-comb2)%mod)
    else:
        print(comb%mod)

Submission status: Wrong Answer

Solution code:
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*
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,10**9+7).comb
for k in range(n+1):print(c(n+1,k+1)-c(l+r,k))

Submission status: Wrong Answer

Solution code:
from math import factorial
n = int(input())
length = n+1
li = list(map(int,input().split()))
dup = [x for x in set(li) if li.count(x) == 2].pop()
be, af = [i for i, x in enumerate(li) if x==dup]
soto = be + length - af - 1

for k in range(1, n+2):
    if k == 1:
        print(n)
    elif k == n+1:
        print(1)
    else:
        zyouhukuari = factorial(length) // (factorial(k)*factorial(length-k))
        if soto - k + 1 < 0:
            zyouhuku = 0
        else:
            zyouhuku = factorial(soto) // (factorial(k-1)*factorial(soto-k+1))
        print(zyouhukuari - zyouhuku)

Submission status: Wrong Answer

Solution code:
mod=10**9+7
def mkmodtable(n):
    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)
    return g1,inverse,g2

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)
a1,_,b1=mkmodtable(n+1)
def cmb1(r):
    if r<0 or n+1<r:return 0
    return a1[n+1]*b1[r]*b1[n+1-r]%mod
a2,_,b2=mkmodtable(n-i2+i1)
def cmb2(r):
    if r<0 or n-i2+i1<r:return 0
    return a2[n-i2+i1]*b2[r]*b2[n-i2+i1-r]%mod
for i in range(n+1):
    print(cmb1(i+1)-cmb2(i))

Submission status: Wrong Answer

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

    # print(A)
    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
    # print(N, i1, i2)

    B = [1]
    v = 1
    for i in range(1, N+2):
        v = (v*(N-i+2))//i
        v  = v % div
        B.append(v)
    # print(B)

    C = [1]
    v = 1
    for i in range(1, M+1):
        v = (v*(M-i+1))//i
        v = v % div
        C.append(v)

    for l in range(1, N+2):
        if l <= M+1:
            print((B[l] - C[l-1]) % div)
        else:
            print(B[l])

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

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

def modInv(a, MOD=1000000007):
    b = MOD
    u = 1
    v = 0
    while b :
        t = a // b
        a -= t * b
        u -= t * v
        a, b = b, a
        u, v = v, u
    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 n < r:
        return 1
    return (fact[n] * invFact[r] % MOD) * invFact[n - r] % MOD

les = left + N - right - 1

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

Submission status: Wrong Answer

Solution code:
MOD = 10 ** 9 + 7


n = int(input())
seq = list(map(int, input().split()))


num_set = set()
for i in range(n):
    if seq[i] in num_set:
        break
    num_set.add(seq[i])
right = i
left = seq.index(seq[i])


def mod_combination(n, r, mod=10**9+7):
    if r > n:
        return 0
    fact = 1
    for i in range(n-r+1, n+1):
        fact = fact * i
    divisor = 1
    for j in range(1, r+1):
        divisor = divisor * j
    return fact//divisor%mod


for k in range(1, n+2):
    print(mod_combination(n+1, k) - mod_combination(n - (right - left), k-1)%MOD)

Submission status: Wrong Answer

Solution code:
mod = 10**9+7
fact = [1]*(10**5+2)
for n in range(1,10**5+2):
    fact[n] = n*fact[n-1]%mod
def comb(n,k):
    return fact[n]*pow(fact[k],mod-2,mod)*pow(fact[n-k],mod-2,mod)%mod

N = int(input())
a = list(map(int,input().split()))
c = [-1]*N
for j in range(N+1):
    if c[a[j]-1] != -1:
        break
    c[a[j]-1] = j
i = c[a[j]-1]
j = N-j

for k in range(1,N+2):
    if k == 1:
        print(N)
    else:
        ans = comb(N+1,k)
        if k-1<=i:
            ans -= comb(i,k-1)
        if k-1<=j:
            ans -= comb(j,k-1)
        print(ans%mod)

Submission status: Wrong Answer

Solution code:
from collections import Counter, deque, defaultdict
def inpl(): return list(map(int, input().split()))

MOD = 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
 
size = 2*10**5 + 1
g1, g2, inverse = [0]*size, [0]*size, [0]*size
 
g1[:2] = [1, 1] # 元テーブル
g2[:2] = [1, 1] #逆元テーブル
inverse[:2] = [0, 1] #逆元テーブル計算用テーブル
 
for i in range(2, size):
    g1[i] =  ( g1[i-1] * i ) % MOD 
    inverse[i] = (-inverse[MOD % i] * (MOD//i) ) % MOD 
    g2[i] =  (g2[i-1] * inverse[i]) % MOD


N = int(input())
A = inpl()
C = Counter(A)
for k, v in C.items():
    if v == 2:
        break
l = A.index(k)
r = N - A[::-1].index(k)

d = r - l - 1

print(N)
print(1 + N-1 + d + cmb(N-1, 2, MOD))
for k in range(3, N+2):
    X = cmb(N-1, k-1, MOD)
    Y = cmb(N-1-d, k-1, MOD)
    Z = X - Y
    tmp = cmb(N-1, k, MOD) + Y + 2*Z + cmb(N-1, k-2, MOD)
    print(tmp%MOD)

Submission status: Wrong Answer

Solution code:
from collections import Counter, deque, defaultdict

from math import sqrt, factorial
from sys import setrecursionlimit
setrecursionlimit(10000000)

def inpl(): return list(map(int, input().split()))

MOD = 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
 
size = 10**5 + 1
g1, g2, inverse = [0]*size, [0]*size, [0]*size
 
g1[:2] = [1, 1] # 元テーブル
g2[:2] = [1, 1] #逆元テーブル
inverse[:2] = [0, 1] #逆元テーブル計算用テーブル
 
for i in range(2, size):
    g1[i] =  ( g1[i-1] * i ) % MOD 
    inverse[i] = (-inverse[MOD % i] * (MOD//i) ) % MOD 
    g2[i] =  (g2[i-1] * inverse[i]) % MOD


N = int(input())
A = inpl()
C = Counter(A)
for k, v in C.items():
    if v == 2:
        break
l = A.index(k)
r = N - A[::-1].index(k)

d = r - l - 1

print(N)
print(1 + N-1 + d + cmb(N-1, 2, MOD))
for k in range(3, N+2):
    X = cmb(N-1, k-1, MOD)
    Y = cmb(N-1-d, k-1, MOD)
    Z = X - Y
    tmp = cmb(N-1, k, MOD) + Y + 2*Z + cmb(N-1, k-2, MOD)
    print(tmp%MOD)

Submission status: Wrong Answer

Solution code:
import math

N = int(input())
A = [int(i) for i in input().split()]

def nCr(n,r):
  numerator = math.factorial(n)
  denominator = math.factorial(r) * math.factorial(n-r)
  return numerator//denominator

A_duplicate = [x for x in set(A) if A.count(x) > 1]
A_duplicate_indexes = [i for i, x in enumerate(A) if x == A_duplicate[0]]

l = A_duplicate_indexes[0]
r = A_duplicate_indexes[1]

for i in range(1,N+2):
  l_count = 0
  r_count = 0
  if l-1 >= i-1:
    l_count = nCr(l-1,i-1)
  if N-r >= i-1:
    l_count = nCr(N-r,i-1)
  ans = nCr(N+1,i) - ( l_count + r_count )
  print(ans%(10**9+7))

Submission status: Wrong Answer

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

li = [0]*(n+1)
twice = 0
for i in range(len(a)):
    li[a[i]] += 1
    if li[a[i]] == 2:
        twice = a[i]
        break

first = -1
second = -1
for i in range(len(a)):
    if first == -1 and a[i] == twice:
        first = i
    elif a[i] == twice:
        second = i


c1 = n+1
c2 = 1
rest = n+1 - (second - first +1)
print(n)
for k in range(2, n+2):
    c1 = c1 * (n+1 - k + 1) // k
    if rest < k-1:
        c2 = 0
    else:
        c2 = c2 * (rest - (k - 1) + 1) // (k - 1)
    print(c1 - c2)

Submission status: Wrong Answer

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

def comb(n, k):
    if n < k:
        return 0
    ret = 1
    c = min(k, n-k)
    for i in range(c):
        ret *= (n-i)
        ret //= (i+1)
        ret %= 1000000007
    return ret

li = [0]*(n+1)
twice = 0
for i in range(len(a)):
    li[a[i]] += 1
    if li[a[i]] == 2:
        twice = a[i]
        break

first = -1
second = -1
for i in range(len(a)):
    if first == -1 and a[i] == twice:
        first = i
    elif a[i] == twice:
        second = i



for k in range(1, n+2):
    print((comb(n+1,k) - comb(n+1 - (second - first + 1), k-1)) % 1000000007)

Submission status: Wrong Answer

Solution code:
#import numpy as np
#from numpy import*
#from scipy.sparse.csgraph import shortest_path #shortest_path(csgraph=graph)
#from scipy.sparse.csgraph import dijkstra
#from scipy.sparse.csgraph import floyd_warshall
#from scipy.sparse import csr_matrix

from collections import* #defaultdict Counter deque appendleft
from fractions import gcd
from functools import* #reduce
from itertools import* #permutations("AB",repeat=2) combinations("AB",2) product("AB",2) groupby accumulate
from operator import mul,itemgetter
from bisect import* #bisect_left bisect_right
from heapq import* #heapify heappop heappushpop
from math import factorial,pi
from copy import deepcopy
import sys
sys.setrecursionlimit(10**8)
#input=sys.stdin.readline  #危険！基本オフにしろ！

def mod_cmb(n, k, mod):
    def ext_gcd(a, b):
        if b == 0:return a, 1, 0
        else:d,x,y = ext_gcd(b,a%b);x-=(a//b)*y 
        return d,y,x
    p,q=1,1
    for i in range(n-k+1,n+1):
        p=(p*i)%mod
    for i in range(2,k+1):
        q=(q*i)%mod
    return int(p*(ext_gcd(q, mod)[1]%mod)%mod)

def main():
    n,*a=map(int,open(0).read().split())
    mod=10**9+7
    b=Counter(a).most_common()[0][0]
    left,right=[k+1 for k,v in enumerate(a) if v==b]
    left-=1
    right=n-right+1
#    print(left,right)
    
    print(n)
    for i in range(2,n+2):
        print(mod_cmb(n+1,i,mod)-mod_cmb(i,left+right,mod))
            

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
def factorials(M):#M!までのリストｘと其の逆元のリストyを返すmod INF
    INF=int(1e9+7)
    fac=[0]*(M+1)
    finv=[0]*(M+1)
    inv=[0]*(M+1)
    fac[0]=fac[1]=1
    finv[0]=finv[1]=1
    inv[1]=1
    for i in range(2,M+1):
        fac[i]=(fac[i-1]*i)%INF
        inv[i]=INF-(inv[INF%i]*(INF//i))%INF
        finv[i]=finv[i-1]*inv[i]%INF
    return fac,finv
def nCr(n,r):
    INF=int(1e9+7)
    if n<r or r<0 or n<0 :
        return 0
    return fac[n]*(finv[r]*finv[n-r]%INF)%INF

N=int(input())
fac,finv=factorials(N+1)
A=list(map(int,input().split()))
INF=int(1e9+7)
d=[0]*(N+1)
for i in A:
    d[i]+=1
key=-1
for i in range(1,N+1):
    if d[i]==2:
        key=i
a,b,c=0,0,0
t=0
for i in range(N+1):
    if key==A[i]:
        t+=1
    elif t==0:
        a+=1
    elif t==1:
        b+=1
    elif t==2:
        c+=1
for i in range(1,N+2):
    if i==1:
        print(N)
        continue

    print(nCr(N+1,i)-nCr(a+c,i-1))