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: Runtime Error

Solution code:
import sys
#import math

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

def combination(n,k):
	if k == 0:
		return 1
	elif k == n:
		return 1
	else:
		return 1:

#return math.factorial(n)/math.factorial(n-k)/math.factorial(k)

#hoge = "1 2 1 3"
#a_array = list(map(int,hoge.split(" ")))
#a_array = [2,3,1,4,5,1,6,7]
#a_array = [1,2,1,3]
#N = len(a_array)-1

#print(N)
#print(a_array)

indexes = [i for i, x in enumerate(a_array) if x == 1]
#print(indexes)
r = indexes[0] + N-indexes[1]
#print(r)

for i in range(1,N+2):
	if r >= i-1:
		print(int(combination(N+1,i)-combination(r,i-1)))
	else:
		print(int(combination(N+1,i)))

Submission status: Runtime Error

Solution code:
import sys
import math

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

def combination(n,k):
	if k == 0:
		return 1
	elif k == n:
		return 1
	else:
		return math.factorial(n)/math.factorial(n-k)/math.factorial(k)

#hoge = "1 2 1 3"
#a_array = list(map(int,hoge.split(" ")))
#a_array = [2,3,1,4,5,1,6,7]
#a_array = [1,2,1,3]
#N = len(a_array)-1

#print(N)
#print(a_array)

indexes = [i for i, x in enumerate(a_array) if x == 1]
#print(indexes)
r = indexes[0] + N-indexes[1]
#print(r)

for i in range(1,N+2):
	if r >= i-1:
		print(int(combination(N+1,i)-combination(r,i-1)))
	else:
		print(int(combination(N+1,i)))

Submission status: Runtime Error

Solution code:


def get_repeating_indexes(ax):
    elements = [-1] * (len(ax))

    for i, a in enumerate(ax):
        if elements[a] != -1:
            return elements[a], i
        else:
            elements[a] = i


MOD = 10 ** 9 + 7
memo = {}

def nck(a, b):
    if (a, b) in memo:
        return memo[(a,b)]
    elif b > a:
        return 0
    elif a == b or b == 0:
        return 1
    elif a-b < b:
        return nck(a, a-b)
    else:
        memo[(a, b)] = (nck(a - 1, b - 1) % MOD + nck(a - 1, b) % MOD) % MOD
        return memo[(a, b)]


def main():
    n = int(raw_input())
    ax = [int(x) for x in raw_input().split()]

    i, j = get_repeating_indexes(ax)
    oob = i + (len(ax) - j - 1)

#    import pdb; pdb.set_trace()

    for i in range(1, n+2):
        if i == 1:
            print n
        else:
            print nck(n + 1, i) - nck(oob, i - 1)


if __name__ == "__main__":
    main()

Submission status: Runtime Error

Solution code:
from math import factorial
from collections import Counter
n = int(input())
a = list(map(int, input().split()))
F = [(factorial(i) % (pow(10, 9)+7)) for i in range(n+2)]
G = [(pow(F[i], (pow(10, 9)+5)) % (pow(10, 9)+7)) for i in range(n+2)]

b = [key for key,val in Counter(a).items() if val > 1]
c = [i for i, x in enumerate(a) if x == b[0]]
B = c[1] - c[0] - 1
X = n + c[0] - c[1]

for k in range(1:n+2):
	if k <= X+1:
		Y = (F[n+1] * G[k] * G[n+1-k]) - (F[X] * G[k-1] * G[X-k+1])
		print(Y)
	else:
		Y = (F[n+1] * G[k] * G[n+1-k])
		print(Y)

Submission status: Runtime Error

Solution code:
N = input()
s = map(int, raw_input().split(" "))

sd=list(set(s))
daburi=sum(s)-sum(sd)

o = [ i for i, v in enumerate(s) if v == daburi]

a=[]
out=o[0]+N-o[1]

def nck(n, k):
    if n-k<k:
        k=n-k
    ko=1
    haha=1
    if k>0:
        for i in range(k):
            ko*=n
            n-=1
            haha*=(i+1)
    return ko/haha

for i in range(out+1):
    print(int((nck(N+1,i+1)-nck(out,i))%(7+1e9)))
for i in range(out+1, N+1):
    print(int(nck(N+1,i+1)%(7+1e9)))

Submission status: Runtime Error

Solution code:
N = input()
s = map(int, raw_input().split(" "))

sd=list(set(s))
daburi=sum(s)-sum(sd)

o = [ i for i, v in enumerate(s) if v == daburi]

a=[]
out=o[0]+N-o[1]

def nck(n, k):
    if n-k<k:
        k=n-k
    ko=1
    haha=1
    for i in range(k):
        ko*=n
        n-=1
        haha*=(i+1)
    return ko/haha

for i in range(out+1):
    print(int((nck(N+1,i+1)-nck(out,i))%(7+1e9)))
for i in range(out+1, N+1):
    print(int(nck(N+1,i+1)%(7+1e9)))

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-
import scipy.misc as scm
n = input()
a = map(int, raw_input().split())
mod = 10**9+7
acnt =[0]*(n+1)
for i in range(n+1):
    acnt[a[i]] += 1
    if(acnt[a[i]]==2):
        same = a[i]
        break
lr = []
for i in range(n+1):
    if(a[i]==same):
        lr.append(i)
     
left = lr[0]
right = n-lr[1]
print(n)
for i in range(1,n+1):
    c = int(scm.comb(n+1,i+1)%mod)
    plc = int(scm.comb(left+right,i)) if left+right>=i else 0
    ans = (c-plc)%mod
    print(ans)

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-
import numpy as np
import scipy.misc as scm
n = input()
a = map(int, raw_input().split())
mod = 10**9+7
acnt =[0]*(n+1)
for i in range(n+1):
    acnt[a[i]] += 1
    if(acnt[a[i]]==2):
        same = a[i]
        break
lr = []
for i in range(n+1):
    if(a[i]==same):
        lr.append(i)
     
left = lr[0]
right = n-lr[1]
print(n)
for i in range(1,n+1):
    c = int(scm.comb(n+1,i+1)%mod)
    if(i==0):
        plc,leftc,rightc=0,0,0
    else:
        plc = int(scm.comb(left+right,i)) if left+right>=i else 0
    ans = (c-plc)%mod
    print(ans)

Submission status: Runtime Error

Solution code:
from scipy.misc import comb
n = int(input())
a = [int(i) for i in input().split(' ')]
b = []

for i in range(1, n+1):
    if a[i] in b:
        l = a[i]
        break
    b.append(a[i])

for i in range(1, n+1):
    print((comb(n, i) - comb(l, i-1)) / (10**9+7))

Submission status: Runtime Error

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

import math

flag = [a.count(a[i])-1 for i in range(n+1) ]

cc = [ math.factorial(n+1)/math.factorial(i+1)/math.factorial(n-i) for i in range( n//2 )]
cc = cc + list(reversed(cc)) +[1]

for i in range(n+1):
    p = flag.index(1) + list(reversed(flag)).index(1)
    
    if ( p>=i ):
        c = cc[i] - math.factorial(p)/math.factorial(i)/math.factorial(p-i)
    else:
        c = cc[i]
    print( int(c)%(10**9+7) )

Submission status: Runtime Error

Solution code:
import itertools
def nCr(n, r):
    """
    Calculate the number of combination (nCr = nPr/r!).
    The parameters need to meet the condition of n >= r >= 0.
    It returns 1 if r == 0, which means there is one pattern
    to choice 0 items out of the number of n.
    """

    # 10C7 = 10C3
    r = min(r, n-r)

    # Calculate the numerator.
    numerator = 1
    for i in range(n, n-r, -1):
        numerator *= i

    # Calculate the denominator. Should use math.factorial?
    denominator = 1
    for i in range(r, 1, -1):
	    denominator *= i
    comb = 0
    if n >= r:
        comb = numerator // denominator
    return comb

n = int(input())
a = [int(x) for x in input().split()]
doubnum = 0
a1 = 0
a2 = 0
a3 = 0
ans = []

for i in range(n):
	if a.count(i) == 2:
		doubnum = i

j = 0
while a[j] != doubnum:
	a1 += 1
	j += 1
j += 1
while a[j] != doubnum:
	a2 += 1
	j += 1
j += 1
while j < n + 1:
	a3 += 1
	j += 1

ans.append(n)
ans.append(nCr(n + 1, 2) - a1 - a3)
for i in range(3, n + 2):
	temp = (nCr(n + 1, i) - nCr(a1 + a3, i - 1)) % (10**9 + 7)
	ans.append(temp)
ans[-1] = 1
ans[-2] = n + 1
	
	
for i in range(len(ans)):
	print(ans[i])

Submission status: Runtime Error

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

import math

flag = [a.count(a[i])-1 for i in range(n+1) ]

cc = [ math.factorial(n+1)/math.factorial(i+1)/math.factorial(n-i) for i in range( n//2 )]
cc + list(reversed(cc)) +[1]

for i in range(n+1):
    p = flag.index(1) + list(reversed(flag)).index(1)
    
    if ( p>=i ):
        c = cc[i] - math.factorial(p)/math.factorial(i)/math.factorial(p-i)
    else:
        c = cc[i]
    print( int(c)%(10**9+7) )

Submission status: Runtime Error

Solution code:
INF = 10**9+7 
import scipy.misc as scm

n = int(input())
a = list(map(int, input().split()))
s = set()
result = [x for x in a if x in s or s.add(x)]

indexes = [i for i, x in enumerate(a) if x == result[0]]
l0 = indexes[0]+1
l1 = indexes[1] +1

for i in range(1,n+2):
        print(int((scm.comb(n+1,i)-scm.comb(n-(l1-l0), i-1))%INF))

Submission status: Runtime Error

Solution code:
n = int(input())
a = map(int, input().split())
occur = [0 for i in range(100005)]
x = 0
cnt = 0
for i in a:
    cnt += 1
    if occur[i] > 0:
        x = n + 1 - cnt + occur[i]
    else:
        occur[i] = cnt
print(n)
res1 = n + 1
res2 = 1
for i in range(1, n + 1):
    res1 = res1 * (n + 1 - i) / (i + 1)
    if res2 >= 1: res2 = res2 * (x - i) / i
    print(int((res1 - res2 + 1000000007) % 1000000007))

Submission status: Runtime Error

Solution code:
INF = 10e9+7 
import scipy.misc as scm
n = int(input())
a = list(map(int, input().split()))
s = set()
result = [x for x in a if x in s or s.add(x)]
indexes = [i for i, x in enumerate(a) if x == result[0]]
l0 = indexes[0]+1
l1 = indexes[1] +1

for i in range(1,n+2):
        print(int((scm.comb(n+1,i)-scm.comb(n-(l1-l0), i-1))%INF))

Submission status: Runtime Error

Solution code:
import math

def nCr(n,r):
    f = math.factorial
    return f(n) / f(r) / f(n-r)

div = 10**9+7 

n = int(input())
al = input().split()
s = {}
for i,ai in enumerate(al):
    if (ai in s):
        k1 = s[ai]
        k2 = i+1
        break
    else:
        s[ai] = i + 1

for m in range(1,n+2):
    
    if(m == 1):
        res = n%div
    elif((k1 - 1)+(n+1 - k2) >= m - 1):
        res = int((nCr(n+1,m) - nCr((k1 - 1)+(n+1 - k2),m - 1)) % div)
    else:
        res = int(nCr(n+1,m) % div)
    
    print(res)

Submission status: Runtime Error

Solution code:
import math

def nCr(n,r):
    f = math.factorial
    return f(n) / f(r) / f(n-r)

div = 10**9+7 

n = int(input())
al = input().split()
s = {}
for i,ai in enumerate(al):
    if (ai in s):
        k1 = s[ai]
        k2 = i+1
        break
    else:
        s[ai] = i + 1

for m in range(1,n+2):
    
    if(m == 1):
        res = n%div
    elif((k1 - 1)+(n+1 - k2) >= m - 1):
        res = int((nCr(n+1,m) - nCr((k1 - 1)+(n+1 - k2),m - 1) % div))
    else:
        res = int(nCr(n+1,m) % div)
    
    print(res)

Submission status: Runtime Error

Solution code:
n = int(input())
a = map(int, input().split())
occur = [0 for i in range(n + 1)]
x = 0
cnt = 0
for i in a:
    cnt += 1
    if (occur[i] > 0):
        x = n + 1 - cnt + occur[i]
    else:
        occur[i] = cnt
print(n)
res1 = n + 1
res2 = 1
for i in range(1, n + 1):
    res1 = res1 * (n + 1 - i) / (i + 1)
    if (res2 >= 1): res2 = res2 * (x - i) / i
    print(int((res1 - res2 + 1000000007) % 1000000007))

Submission status: Runtime Error

Solution code:
n = int(input())
a = map(int, input().split())
occur = [0 for i in range(n + 1)]
x = 0
cnt = 0
for i in a:
    cnt += 1
    if (occur[i] > 0):
        x = n + 1 - cnt + occur[i]
    else:
        occur[i] = cnt
print(n)
res1 = n + 1
res2 = 1
for i in range(1, n + 1):
    res1 = int(res1 * (n + 1 - i) / (i + 1))
    res2 = int(res2 * (x - i) / i)
    print(int((res1 - res2 + 1000000007) % 1000000007))

Submission status: Runtime Error

Solution code:
n = int(input())
a = map(int, input().split())
occur = [0 for i in range(n + 1)]
x = 0
cnt = 1
for i in a:
    cnt += 1
    if (occur[i] > 0):
        x = n + 1 - cnt + occur[i]
    else:
        occur[i] = cnt
print(n)
res1 = n + 1
res2 = 1
for i in range(1, n + 1):
    res1 = res1 * (n + 1 - i) / (i + 1)
    res2 = res2 * (x - i) / i
    print(int((res1 - res2 + 1000000007) % 1000000007))