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:
n = int(input())
a = list(map(int,input().split()))

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**7+7 #出力の制限
N = 10**4
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 )


sorted_a=sorted(a)
for i in range(n):
  if sorted_a[i]==sorted_a[i+1]:
    num = sorted_a[i]
    break

flag = True
for i in range(n+1):
  if a[i]==num:
    if flag:
      first = i
      flag = False
    else:
      second = i

#combination=[0]*(n+2)
#combination[0]=1
#for i in range(1,n+2):
#  combination[i] =combination[i-1]*(n+2-i)//i
#combination2=[0]*(n+2)
#combination2[0]=0
#combination2[1]=1
#for i in range(2,n+2):
#  combination2[i] =combination2[i-1]*(first+n-second+1-(i-1))//(i-1)

#for i in range(1,n+2):
  #ans = comb(n-1,i) + 2*comb(n-1,i-1)-comb(first+n-second,i-1) +comb(n-1,i-2)
  #ans = comb(n+1,i) - comb(first+n-second,i-1)
  #ans = (combination[i]%1000000007-combination2[i]%1000000007)%1000000007
  #print(ans)  
  
for i in range(1,n+2):
  ans = cmb(n+1,i,mod) - cmb(first+n-second,i-1,mod)
  print(ans)

Submission status: Wrong Answer

Solution code:
from collections import defaultdict
import sys
sys.setrecursionlimit(1000000)
MOD = 1000000007

n = int(input())
alst = list(map(int, input().split()))
dic = defaultdict(list)
for i in range(n + 1):
    dic[alst[i]].append(i)

for v in dic.values():
    if len(v) == 2:
        left, right = v
        break

rem = n + 1 - (right - left + 1)


factMem = {}
def fact(x):
    if x <= 0:return 1
    if x in factMem:return factMem[x]
    factMem[x] = x * fact(x - 1) % MOD
    return factMem[x]

for x in range(n + 1):
    fact(x)

inverseMem = {}
def inverse(x):
    if x in inverseMem:return inverseMem[x]
    inverseMem[x] = pow(x, MOD - 2, MOD)
    return inverseMem[x]

def comb(x, y):
    if x < y or y < 0:return 0
    if y == 0:return 1
    return (fact(x) * inverse(fact(y)) * inverse(fact(x - y))) % MOD

for i in range(n + 1):
    print(comb(n + 1, i + 1) - comb(rem, i))

Submission status: Wrong Answer

Solution code:
from collections import defaultdict
import sys
sys.setrecursionlimit(1000000)
MOD = 1000000007

n = int(input())
alst = list(map(int, input().split()))
dic = defaultdict(list)
for i in range(n + 1):
    dic[alst[i]].append(i)

for v in dic.values():
    if len(v) == 2:
        left, right = v
        break

factMem = {}
def fact(x):
    if x <= 0:return 1
    if x in factMem:return factMem[x]
    factMem[x] = x * fact(x - 1) % MOD
    return factMem[x]

for x in range(n + 1):
    fact(x)

inverseMem = {}
def inverse(x):
    if x in inverseMem:return inverseMem[x]
    inverseMem[x] = pow(x, MOD - 2, MOD)
    return inverseMem[x]

def comb(x, y):
    if x < y or y < 0:return 0
    return (fact(x) * inverse(fact(y)) * inverse(fact(x - y))) % MOD


for i in range(n + 1):
    print(comb(n + 1, i + 1) - comb(n - right + left, i))

Submission status: Wrong Answer

Solution code:
from collections import defaultdict
import sys
sys.setrecursionlimit(1000000)
MOD = 1000000007

n = int(input())
alst = list(map(int, input().split()))
dic = defaultdict(list)
for i in range(n + 1):
    dic[alst[i]].append(i)

for v in dic.values():
    if len(v) == 2:
        left, right = v
        break

factMem = {}
def fact(x):
    if x <= 0:return 1
    if x in factMem:return factMem[x]
    factMem[x] = x * fact(x - 1) % MOD
    return factMem[x]
for x in range(n + 1):
    fact(x)

inverseMem = {}
def inverse(x):
    if x in inverseMem:return inverseMem[x]
    inverseMem[x] = pow(x, MOD - 2, MOD)
    return inverseMem[x]

def comb(x, y):
    if x < y:return 0
    return (fact(x) * inverse(fact(y)) * inverse(fact(x - y))) % MOD

for i in range(n + 1):
    print(comb(n + 1, i + 1) - comb(n - right + left, i))

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int, input().split()))
M = 10**9+7
res = [-1] * (n+1)
for i in range(n+1):
    if res[a[i]] == -1:
        res[a[i]] = i
    else:
        d = a[i]
        l, r = res[d], n-i


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  # 出力の制限
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)


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

Submission status: Wrong Answer

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

# 重複している要素Xを探す
X_search_set = set()
for a in A:
    if a in X_search_set:
        X = a
        break
    else:
        X_search_set.add(a)

# 重複している要素のindexを取得
x_left, x_right = [i for i, a in enumerate(A) if a == X]

# 重複している要素の左側・右側にそれぞれ何個あるか
Left, Right = x_left, N - x_right

# 階乗 & 逆元計算
factorial = [1]
inverse = [1]
for i in range(1, N+2):
    factorial.append(factorial[-1] * i % mod)
    inverse.append(pow(factorial[-1], mod-2, mod))


# 組み合わせ計算
def nCr(n, r):
    if n < r or r < 0:
        return 0
    elif r == 0:
        return 1
    return factorial[n] * inverse[r] * inverse[n - r] % mod


# 計算・出力
for k in range(1, len(A) + 1):
    ans = nCr(len(A), k)

    # 重複部分を引く
    if k - 1 <= Left + Right:
        ans -= nCr(Left + Right, k - 1)

    print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int,input().split()))
w = sum(a) - n*(n+1)//2

q = 0
t = -1
for i in range(n+1):
  if a[i] == w:
    q += t*i
    t = 1
q += 1

x = n+1
y = 1
for k in range(1,n+2):
  print(x-y)
  x = x*(n+1-k)//(k+1)
  y = y*(n+2-q-k)//k

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int,input().split()))
for k in range(1,n+1):
  if a.count(k) == 2:
    break
p = [0,0]
j = 0
for i in range(2):
  while a[j] != k:
    j += 1
  p[i] = j
  j += 1
q = p[1]-p[0]+1
print(n)
if k == 1:
  exit()
x = (n+1)*n//2
y = 1
for k in range(2,n+2):
  print(x-y)
  x = x*(n+1-k)//(k+1)
  y = y*(n+1-q-k+3)//(k-1)

Submission status: Wrong Answer

Solution code:
n = int(input())
a=list(map(int,input().split()))
dic = {}
dic2 = {}
for i in range(n + 1):
    dic[a[i]] = 0
    dic2[a[i]] = []
f = 0
s = 0
for i in range(n + 1):
    dic[a[i]] += 1
    dic2[a[i]].append(i)
    if dic[a[i]] == 2:
        f = dic2[a[i]][0]
        s = i
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 = n + 1
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 k in range(1,n+2):
    if k==1:
        print(n)
    elif k>f+n-s+1:
        print(cmb(n+1,k,mod))
    else:
        print(cmb(n+1,k,mod)-cmb(f+n-s,k-1,mod))

Submission status: Wrong Answer

Solution code:
n = int(input())
a=list(map(int,input().split()))
dic = {}
dic2 = {}
for i in range(n + 1):
    dic[a[i]] = 0
    dic2[a[i]] = []
f = 0
s = 0
for i in range(n + 1):
    dic[a[i]] += 1
    dic2[a[i]].append(i)
    if dic[a[i]] == 2:
        f = dic2[a[i]][0]
        s = i
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 = n + 1
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 k in range(1,n+2):
    if k==1:
        print(n)
    elif k>f+N-s+1:
        print(cmb(n+1,k,mod))
    else:
        print(cmb(n+1,k,mod)-cmb(f+n-s,k-1,mod))

Submission status: Wrong Answer

Solution code:
n = int(input())
a=list(map(int,input().split()))
dic = {}
dic2 = {}
for i in range(n + 1):
    dic[a[i]] = 0
    dic2[a[i]] = []
f = 0
s = 0
for i in range(n + 1):
    dic[a[i]] += 1
    dic2[a[i]].append(i)
    if dic[a[i]] == 2:
        f = dic2[a[i]][0]
        s = i
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 = n + 1
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 k in range(1,n+2):
    if k==1:
        print(n)
    elif k>f+1+N-s-1:
        print(cmb(n+1,k,mod))
    else:
        print(cmb(n+1,k,mod)-cmb(f+n-s,k-1,mod))

Submission status: Wrong Answer

Solution code:
import sys
from collections import deque
import copy
import math
def get_read_func(fileobject):
    if fileobject == None :
        return raw_input
    else:
        return fileobject.readline

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

class comb_calclator():
    def __init__(self, N, p):
        self.N = N
        self.p = p
        self.frac_N = [0 for i in range(N + 1)]
        self.frac_N[0] = 1L
        #self.comb_N = {}
        self.power_N = {}
        for i in range(1, N + 1):
            self.frac_N[i] = (self.frac_N[i - 1] * i ) % p

    def comb(self, n, r):
        if n<0 or r<0 or n<r: return 0
        if n==0 or r==0: return 1
        #if (n, r) in self.comb_N:
        #    return self.comb_N[(n, r)]
        a = self.frac_N[n]
        b = self.frac_N[r]
        c = self.frac_N[n - r]
        if r not in self.power_N:
            self.power_N[r] = power_func(b,self.p-2,self.p)
        if n - r not in self.power_N:
            self.power_N[n - r] = power_func(c,self.p-2,self.p)
        return (a*self.power_N[r]*self.power_N[n - r])% self.p
        #self.comb_N[(n, n - r)] = self.comb_N[(n, r)]
        #return self.comb_N[(n, r)]

def main():
    if len(sys.argv) > 1:
        f = open(sys.argv[1])
    else:
        f = None
    read_func = get_read_func(f);
    input_raw = read_func().strip().split()
    [n] = [int(input_raw[0])]
    input_raw = read_func().strip().split()
    A = []
    N = n + 1   
    idx_dic = {}
    second_idx = 0
    first_idx = 0
    twice_a = 0
    for i in range(N):
        #A.append(int(input_raw[i]))
        A = int(input_raw[i])
        if A not in idx_dic:
            idx_dic[A] = i
        else:
            first_idx = idx_dic[A]
            second_idx = i
            break

    cc = comb_calclator(N, 1000000007)
    sub_N = N - second_idx + first_idx
    for k in range(1, N + 1):
        if k <= sub_N:
          print (cc.comb(N, k) -  cc.comb(sub_N - 1, k - 1)) %  1000000007  
        else:
          print (cc.comb(N, k)) + 1

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import sys
from collections import deque
import copy
import math
def get_read_func(fileobject):
    if fileobject == None :
        return raw_input
    else:
        return fileobject.readline

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

class comb_calclator():
    def __init__(self, N, p):
        self.N = N
        self.p = p
        self.frac_N = [0 for i in range(N + 1)]
        self.frac_N[0] = 1L
        self.comb_N = {}
        for i in range(1, N + 1):
            self.frac_N[i] = (self.frac_N[i - 1] * i ) % p

    def comb(self, n, r):
        if n<0 or r<0 or n<r: return 0
        if n==0 or r==0: return 1
        if (n, r) in self.comb_N:
            return self.comb_N[(n, r)]
        a = self.frac_N[n]
        b = self.frac_N[r]
        c = self.frac_N[n - r]
        self.comb_N[(n, r)] = (a*power_func(b,self.p-2,self.p)*power_func(c,self.p-2, self.p))% self.p
        self.comb_N[(n, n - r)] = self.comb_N[(n, r)]
        return self.comb_N[(n, r)]

def main():
    if len(sys.argv) > 1:
        f = open(sys.argv[1])
    else:
        f = None
    read_func = get_read_func(f);
    input_raw = read_func().strip().split()
    [n] = [int(input_raw[0])]
    input_raw = read_func().strip().split()
    A = []
    N = n + 1
    for i in range(N):
        A.append(int(input_raw[i]))
    idx_dic = {}
    second_idx = 0
    first_idx = 0
    twice_a = 0
    for i in range(N):
        if A[i] not in idx_dic:
            idx_dic[A[i]] = [i]
        else:
            idx_dic[A[i]].append(i)
    for i in range(N):
        if len(idx_dic[A[i]]) >= 2:
            first_idx = min(idx_dic[A[i]])
            second_idx = max(idx_dic[A[i]])
            break

    cc = comb_calclator(N, 1000000007)
    for k in range(1, N+1):
        sub1 = 0
        sub2 = 0
        sub_N = N - second_idx + first_idx
        if k <= sub_N:
            sub1 = cc.comb(sub_N-1, k-1)#cc.comb(sub_N, k) - cc.comb(sub_N - 1, k)
##        if k <= N - second_idx:
##            sub1 = cc.comb(N - second_idx, k) - cc.comb(N - second_idx - 1, k)
##        if  k <= first_idx + 1:
##            sub2 = cc.comb(first_idx + 1, k) - cc.comb(first_idx + 1 - 1, k)
        print cc.comb(N, k) - sub1 




if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import sys
from collections import deque
import copy
import math
def get_read_func(fileobject):
    if fileobject == None :
        return raw_input
    else:
        return fileobject.readline

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

class comb_calclator():
    def __init__(self, N, p):
        self.N = N
        self.p = p
        self.frac_N = [0 for i in range(N + 1)]
        self.frac_N[0] = 1L
        self.comb_N = {}
        for i in range(1, N + 1):
            self.frac_N[i] = (self.frac_N[i - 1] * i ) % p

    def comb(self, n, r):
        if n<0 or r<0 or n<r: return 0
        if n==0 or r==0: return 1
        if (n, r) in self.comb_N:
            return self.comb_N[(n, r)]
        a = self.frac_N[n]
        b = self.frac_N[r]
        c = self.frac_N[n - r]
        self.comb_N[(n, r)] = (a*power_func(b,self.p-2,self.p)*power_func(c,self.p-2, self.p))% self.p
        self.comb_N[(n, n - r)] = self.comb_N[(n, r)]
        return self.comb_N[(n, r)]

def main():
    if len(sys.argv) > 1:
        f = open(sys.argv[1])
    else:
        f = None
    read_func = get_read_func(f);
    input_raw = read_func().strip().split()
    [n] = [int(input_raw[0])]
    input_raw = read_func().strip().split()
    A = []
    N = n + 1
    for i in range(N):
        A.append(int(input_raw[i]))
    idx_dic = {}
    second_idx = 0
    first_idx = 0
    twice_a = 0
    for i in range(N):
        if A[i] not in idx_dic:
            idx_dic[A[i]] = [i]
        else:
            idx_dic[A[i]].append(i)
    for i in range(N):
        if len(idx_dic[A[i]]) >= 2:
            first_idx = min(idx_dic[A[i]])
            second_idx = max(idx_dic[A[i]])
            break

    cc = comb_calclator(N, 1000000007)
    for k in range(1, N+1):
        sub1 = 0
        sub2 = 0
        sub_N = N - second_idx + first_idx
        if k <= sub_N:
            sub1 = cc.comb(sub_N, k) - cc.comb(sub_N - 1, k)
##        if k <= N - second_idx:
##            sub1 = cc.comb(N - second_idx, k) - cc.comb(N - second_idx - 1, k)
##        if  k <= first_idx + 1:
##            sub2 = cc.comb(first_idx + 1, k) - cc.comb(first_idx + 1 - 1, k)
        print cc.comb(N, k) - sub1 




if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import sys
from collections import deque
import copy
import math
def get_read_func(fileobject):
    if fileobject == None :
        return raw_input
    else:
        return fileobject.readline

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

class comb_calclator():
    def __init__(self, N, p):
        self.N = N
        self.p = p
        self.frac_N = [0 for i in range(N + 1)]
        self.frac_N[0] = 1L
        self.comb_N = {}
        for i in range(1, N + 1):
            self.frac_N[i] = (self.frac_N[i - 1] * i ) % p

    def comb(self, n, r):
        if n<0 or r<0 or n<r: return 0
        if n==0 or r==0: return 1
        if (n, r) in self.comb_N:
            return self.comb_N[(n, r)]
        a = self.frac_N[n]
        b = self.frac_N[r]
        c = self.frac_N[n - r]
        self.comb_N[(n, r)] = (a*power_func(b,self.p-2,self.p)*power_func(c,self.p-2, self.p))% self.p
        self.comb_N[(n, n - r)] = self.comb_N[(n, r)]
        return self.comb_N[(n, r)]

def main():
    if len(sys.argv) > 1:
        f = open(sys.argv[1])
    else:
        f = None
    read_func = get_read_func(f);
    input_raw = read_func().strip().split()
    [n] = [int(input_raw[0])]
    input_raw = read_func().strip().split()
    A = []
    N = n + 1
    for i in range(N):
        A.append(int(input_raw[i]))
    idx_dic = {}
    second_idx = 0
    first_idx = 0
    twice_a = 0
    for i in range(N):
        if A[i] not in idx_dic:
            idx_dic[A[i]] = [i]
        else:
            idx_dic[A[i]].append(i)
    for i in range(N):
        if len(idx_dic[A[i]]) >= 2:
            first_idx = min(idx_dic[A[i]])
            second_idx = max(idx_dic[A[i]])
            break

    cc = comb_calclator(N, 1000000007)
    for k in range(1, N+1):
        sub1 = 0
        sub2 = 0
        sub_N = N - second_idx + first_idx
        if k <= sub_N:
            sub1 = cc.comb(sub_N, k) - cc.comb(sub_N - 1, k)
##        if k <= N - second_idx:
##            sub1 = cc.comb(N - second_idx, k) - cc.comb(N - second_idx - 1, k)
##        if  k <= first_idx + 1:
##            sub2 = cc.comb(first_idx + 1, k) - cc.comb(first_idx + 1 - 1, k)
        print cc.comb(N, k) - sub1

Submission status: Wrong Answer

Solution code:
N = int(input())
A = [int(_) for _ in input().split()]
mod = 10**9+7


def comb(x, y):
    if y > x:
        return 0
    elif y * 2 > x:
        y = x - y
    result = 1
    for j in range(1, y + 1):
        result *= (x + j - y) * pow(j, mod - 2, mod)
        result %= mod
    return result


dupl = sum(A)-N*(N+1)//2
ds = []
for _ in range(N+1):
    if A[_] == dupl:
        ds += [_]
i, j = ds

print(N)
for k in range(2, N+2):
    print((comb(N+1, k)-comb(N-1+i-j, k-1)) % mod)

Submission status: Wrong Answer

Solution code:
#import itertools
import math
n = int(input())
a = input().split()
a = [int(m) for m in a]
dic = {}
dic2 = {}
for i in range(n + 1):
    dic[a[i]] = 0
    dic2[a[i]] = []
k = 0
j = 0
for i in range(n + 1):
    dic[a[i]] += 1
    dic2[a[i]].append(i)
    if dic[a[i]] == 2:
        j = dic2[a[i]][0]
        k = i
        
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 = n + 1
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 )

#a = cmb(10**9,80,mod)

for i in range(n + 1):
    if i == 0:
        print(n)
    else:
        if j + n - k >= i:
            print(cmb(n + 1, i + 1, mod) - cmb(j + n - k, i, mod))
        else:
            print(cmb(n + 1, i + 1, mod))

Submission status: Wrong Answer

Solution code:
mod=10**9+7
N=int(input())
Factorial=[1]*(N+1)
for i in range(1,N+1):
  Factorial[i]=Factorial[i-1]*(i)%mod
def power(x,y):
  if y==0:
    return 1
  elif y==1:
    return x%mod
  elif y%2==0:
    return power(x,y//2)**2%mod
  else:
    return (power(x,y//2)**2)*x%mod

inverseFactorial=[1]*(N+1)
inverseFactorial[N]=power(Factorial[N],mod-2)
for i in range(0,N)[::-1]:
  inverseFactorial[i]=(inverseFactorial[i+1]*(i+1))%mod
  
def comb(x,y):
  if x<y or y<0:
    return 0
  else:
    return (Factorial[x]*inverseFactorial[y]*inverseFactorial[x-y])%mod

list=[-1]*N
n=0
for i in input().split():
  if list[int(i)-1]<0:
    list[int(i)-1]=n
    n+=1
  else:
    a=list[int(i)-1]
    b=n-a-1
    c=N-n
for m in range(1,N+2):
    print(comb(a+b+c,m)+2*comb(a+b+c,m-1)-comb(a+c,m-1)+comb(a+b+c,m-2))

Submission status: Wrong Answer

Solution code:
mod = 10 ** 9 + 7

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

combi = [[0] * (n + 2) for i in range(n)]

for i in range(n):
    for j in range(i + 1):
        if i == 0 or j == 0:
            combi[i][j] = 1
        else:
            combi[i][j] = (combi[i - 1][j] + combi[i - 1][j - 1]) % mod

twice = sum(a) - n * (n + 1) // 2

l = a.index(twice)
r = a.index(twice, l + 1)

a = l
b = r - l - 1
c = (n + 1) - r - 1

for k in range(1, n + 2, 1):
    ans = 0
    if a + b + c >= k:
        ans = (ans + combi[a + b + c][k]) % mod
    if k <= 2:
        ans = (ans + 1) % mod
    if k >= 2:
        if a + b >= k - 1:
            ans = (ans + combi[a + b][k - 1]) % mod
        if b + c >= k - 1:
            ans = (ans + combi[b + c][k - 1]) % mod
        if k >= 3 and a + b + c >= k - 2:
            ans = (ans + combi[a + b + c][k - 2]) % mod

    print(ans)

Submission status: Wrong Answer

Solution code:
mod = 10 ** 9 + 7

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

combi = [[0] * (i + 2) for i in range(n)]

for i in range(n):
    for j in range(i + 1):
        if i == 0 or j == 0:
            combi[i][j] = 1
        else:
            combi[i][j] = (combi[i - 1][j] + combi[i - 1][j - 1]) % mod

twice = sum(a) - n * (n + 1) // 2

l = a.index(twice)
r = a.index(twice, l + 1)

a = l
b = r - l - 1
c = (n + 1) - r - 1

for k in range(1, n + 2, 1):
    ans = 0
    if a + b + c >= k:
        ans = (ans + combi[a + b + c][k]) % mod
    if k <= 2:
        ans = (ans + 1) % mod
    if k >= 2:
        if a + b >= k - 1:
            ans = (ans + combi[a + b][k - 1]) % mod
        if b + c >= k - 1:
            ans = (ans + combi[b + c][k - 1]) % mod
        if k >= 3 and a + b + c >= k - 2:
            ans = (ans + combi[a + b + c][k - 2]) % mod

    print(ans)

Submission status: Wrong Answer

Solution code:
def gcd(a, b):
	while b:
		a, b = b, a % b
	return a

def egcd(a, b):
    (x, lastx) = (0, 1)
    (y, lasty) = (1, 0)
    while b != 0:
        q = a // b
        (a, b) = (b, a % b)
        (x, lastx) = (lastx - q * x, x)
        (y, lasty) = (lasty - q * y, y)
    return (lastx, lasty, a)

N = 10**9+7
R = 10**5+10
modfact = [0]*(R+1)
def modfact_memo(n,N):
    r = 1
    modfact[0] = 1
    for i in range(1,n+1):
        r = r % N * i % N
        modfact[i] = r
modfact_memo(10**5,N)

# ax ≡ 1 (mod m)
modinv=[0]*(R+1)
def modinv_memo(a,m):
    for i in range(a+1):
        j = modfact[i]
        (inv, q, gcd_val) = egcd(j, m)
        modinv[i] = inv % m
modinv_memo(R,N)

def modconb(n,r,N):
    p = modfact[n]
    q1 = modinv[r]
    q2 = modinv[n-r]
    return p*q1%N*q2%N


n = int(input())
a = list(map(int,input().split()))
b=[0]*n
for i in range(n+1):
    b[a[i]-1] += 1
w = b.index(2)+1
index = []
for i in range(n+1):
    if a[i] == w:
        index.append(i)
l = index[0]
r = n - index[1]

for i in range(n+1):
    ans = modconb(n+1,i+1,N)
    if l+r >= i:
        ans -= modconb(l+r,i,N)
        ans %= N
    print(ans)

Submission status: Wrong Answer

Solution code:
def Pow(i, n):
    if n == 0:
        return 1
    else:
        ans = Pow(i * i % mod, n//2)
        if n % 2 == 1:
            ans *= i
            ans %= mod
        return ans

N = int(input())
A = [int(i) for i in input().split()]
mod = 7 + 10 ** 9
num = [-1 for i in range(N)]
for i, a in enumerate(A):
    if num[a-1] == -1:
        num[a-1] = i
    else:
        Double = [num[a-1], i]

Nfact = [1]
for i in range(1, N+2):
    Nfact.append((Nfact[i-1] * (i)) % mod)
NfactRev = [Pow(Nfact[N+1], mod-2)]
for i in range(1, N+1):
    NfactRev.append(NfactRev[i-1] * (N+2-i) % mod)
NfactRev.append(1)

doublearray = N - (Double[1] - Double[0])
for i in range(1, N+2):
    whole = Nfact[N+1] * NfactRev[-(N+2-i)] * NfactRev[-(i+1)] % mod
    if i <= doublearray+1:
        double = Nfact[doublearray] * NfactRev[-(doublearray-i+2)] * NfactRev[-i] % mod
    else:
        double = 0
    print(whole - double)

Submission status: Wrong Answer

Solution code:
import sys
stdin = sys.stdin

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


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

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


from collections import Counter

MOD = 10**9+7

n = ni()
a = list(li())

# 被っている数の後にある数の個数を把握
cnt = Counter(a)
db = 0
for k,v in cnt.items():
    if v == 2:
        db = k
        
front = a.index(db)
back = a[::-1].index(db)

# 二項係数の準備
inv = inv_mod(n+1,MOD)
fac = fact(n+1, MOD)
facInv = fact_inv(n+1,inv,MOD)

# 出力
for k in range(1, n+2):
    ans = nCr(n+1,k,MOD,fac,facInv) - nCr(front+back,k-1,MOD,fac,facInv)
        
    print(ans)

Submission status: Wrong Answer

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

index2 = 0
for i in range(n+1):
    if a[i] in s:
        index2 = i
    s.add(a[i])

index1 = 0
for i in range(n+1):
    if a[i] == a[index2]:
        index1 = i
        break

#combination---
m = 10**9 + 7
fac = [1, 1]
inv = [1, 1]
finv = [1, 1]
for i in range(2, n+5):
    fac.append(fac[i-1] * i % m)
    inv.append(m - inv[m%i] * (m//i) % m)
    finv.append(finv[i-1] * inv[i] % m)

def nck(n, k):
    if n < k:
        return 0
    if n < 0 or k < 0:
        return 0
    return fac[n] * (finv[k] * finv[n-k] % m) % m

#-----


for k in range(1, n+2):
    if k == 1:
        print(n)
    else:
        print((nck(n + 1, k) - nck(n - index2, k - 1) - nck(index1, k - 1)) % m)

Submission status: Wrong Answer

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

index2 = 0
for i in range(n+1):
    if a[i] in s:
        index2 = i
    s.add(a[i])

index1 = 0
for i in range(n+1):
    if a[i] == a[index2]:
        index1 = i
        break

#combination---
m = 10**9 + 7
fac = [1, 1]
inv = [1, 1]
finv = [1, 1]
for i in range(2, n+5):
    fac.append(fac[i-1] * i % m)
    inv.append(m - inv[m%i] * (m//i) % m)
    finv.append(finv[i-1] * inv[i] % m)

def nck(n, k):
    if n < k:
        return 0
    if n < 0 or k < 0:
        return 0
    return fac[n] * (finv[k] * finv[n-k] % m) % m

#-----


for k in range(1, n+2):
    print((nck(n+1, k) - nck(n-index2, k-1) - nck(index1, k-1)) % m)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int, input().split()))
s = set()
index = 0
for i in range(n+1):
    if a[i] in s:
        index = i
    s.add(a[i])

#combination---
m = 10**9 + 7
fac = [1, 1]
inv = [1, 1]
finv = [1, 1]
for i in range(2, n+5):
    fac.append(fac[i-1] * i % m)
    inv.append(m - inv[m%i] * (m//i) % m)
    finv.append(finv[i-1] * inv[i] % m)

def nck(n, k):
    if n < k:
        return 0
    if n < 0 or k < 0:
        return 0
    return fac[n] * (finv[k] * finv[n-k] % m) % m
#-----


for k in range(1, n+2):
    print((nck(n+1, k) - nck(n-index, k-1)) % m)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int, input().split()))
s = set()
index = 0
for i in range(n):
    if a[i] in s:
        index = i
    s.add(a[i])

#combination---
m = 10**9 + 7
fac = [1, 1]
inv = [1, 1]
finv = [1, 1]
for i in range(2, n+5):
    fac.append(fac[i-1] * i % m)
    inv.append(m - inv[m%i] * (m//i) % m)
    finv.append(finv[i-1] * inv[i] % m)

def nck(n, k):
    if n < k:
        return 0
    if n < 0 or k < 0:
        return 0
    return fac[n] * (finv[k] * finv[n-k] % m) % m

for k in range(1, n+2):
    print((nck(n+1, k) - nck(n-index, k-1)) % m)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int, input().split()))
s = set()
index = 0
for i in range(n):
    if a[i] in s:
        index = i
    s.add(a[i])

#combination---
m = 10**9 + 7
fac = [1, 1]
inv = [1, 1]
finv = [1, 1]
for i in range(2, n+5):
    fac.append(fac[i-1] * i % m)
    inv.append(m - inv[m%i] * (m//i) % m)
    finv.append(finv[i-1] * inv[i] % m)

def nck(n, k):
    if n < k:
        return 0
    if n < 0 or k < 0:
        return 0
    return fac[n] * (finv[k] * finv[n-k] % m) % m

for k in range(1, n+2):
    print(nck(n+1, k) - nck(n-index, k-1))