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: Time Limit Exceeded

Solution code:
'''
z<<~``_<<<<<<~    `  _<+zlvzOOwrvvvvvzzzzzzzzzw)`              ``<:i.``.XC~(>~~.~.~.~.~.~.~.~.~~~(~~~.~~~.~~~~~~.~~.~~.~~.~~~~~~~~~~?-~(WZZX\..`..J<;;;<_```.``..(XZyyyyyyyyyyyyyyyyyyyZyyyyyWX0OIlwXyyV
:_- ` `   ``       ` -~~~~~__<1Orrrrrrvrvvvvvvr\`` ` `  `  `    `?<(>`..C(<~.......~.........~..(:...~...~..(............~.........~~(I~?SuZ..`.->;;;;!.``.``...-duZyZZyyyZZyZyyyyyyyZyyyZZyZZXXwwXyyyyy
::<_ `  ``````````` ``````   _<1trrrrrrrrrrrrrtl`   ` `  `  ` `  .` ?_ J(!..._```   -`````` . ..J--...~._-...-..   ````````   ```_...~_1_(k%.`.(<;>;<_...!```..(wuZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZuZZ
   ````````````````` ...--(++++ztttttttrtrtrrttz`  `   `   `   ` . ``~(/` ```````  ._..~.~_J~~.(>~~~~.~~<~~~(:~.~~~~~......  ````````  _1_?{...<;>;_--?!``....(UzuuuuuuuuuuuuuuuuuuuZuuuuuuuuXOOOC7<<+1O
`  ````````.......-_(<?=llllltttltttttttttttttlz``          `  `` <-..'```` ..+_.~({~~~.~_jl~~(z~~.~.~~_z~~~_$~~.~.~(-~~~.~~.~.._.. `````_.<..z;<+?!_````.`.(JrzzzuuzuzuuuuzuuzuuuuzZOOwwOOwwO<_~. ``` _
`````` __(___-(+++zz1+zlllltlllltlllllltlltlltlz `` ` ` `    `    _..!.--..~(z>~~(v~~~~~_+w~~_jZ~~.~~.~(z~~~~v-~~~.~(z_~~~~~~~~~~.__.._.. (.;(+?~.`.`.....(ZtrrvvvvvvvvvvvvvrwrwrrrOz<<<!__~<?1z<~.````.
_-.   -__:_(<>??=lllllllllltlllllllllllllllltllz_        `    ` ``i(>~(~~~~_jt>~(zl~~.~_jCc~~(Z>~~~.~~~(z~~~~>1~~.~~_zz_~~.~.~~.~~~<~~~~~~~1j<..``.....JOltttrrtrrrrrrttttOz<<<1OOz<~ ``     .__.. . ..-
1++++++1=======llllllllllllllllllllllllllllll==z_` `  `   `     ` <<~(<~~.~(tt<_jw~~~~~(C(>~(d>>~~.~.~~(l<~~~<(:~~~~~zro~~~.~~(~~~~(<~~~~~~~Cl-.-(+z<~?1+1llllttlttlttllz<<~`__~<<<~ ``-(<<<_(((++++++zz
l============l==l====l==l======================?}`  `  `   ` `  ` (~~c~~~~(trO~(tr~~~~(C_.~~jr~>~~~.~~~jt>~~~(~(-~~~~jvrc~~~~~(;~~~_z_~~.~~~(I.`.`.`_<-~_T=11<<1=l==z<<<<_-.. ```...`  _(<+++ztttttOOwwv
==?===?==?=?=?===========?=??=?==?=??????=???=??l`            ` ``.~(:~.~~jrrI(Owl((Juf^!???U=1c~~~~.~~jrI~~~(- j-_(((Xwvx~~~~~l~~~~z>~~~~~_~j_.```.`. ?-(I><:(>???>?++++++?+<(((((((++++zOwrrrrvzvvzuuX
????????>???????>????>????>????>??>???>??>?>?>>>z`` `` ` `       `.<J~~~~(OrvI(wd3~~_v```.~(}` (~.~~~~~jrr<~~~}`_1<~~~TXUUVOJ-~1~~~~jI~~~.~>~_n--..`.``.-1j???????????=?=???===lzzOwrrrrrzuuzzzvwrrrrwXX
?>>>>>>>>>>>>>>>>>;>;>;;>;>;;>;;;>;;>;>>;>;>>;>;+`    `   `` ``  ` 1t~~~~(rvzIwvd:~~J`  `.~J```(<~(~~~~(rrG_~~<`` ?-~~(JXzvc~_?z-~~~jr<~~~~(~~j>+1,.``.``-1I?????????????=zzzOrrvvrrzwzzuXZtrrwwvwtrrrrr
Ozllzzzzzz+<>;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;:(.``   `    `  `` `O>~~.~jvzzAkzd~~(!`  `._:` ` l~(_~~~(vzvI~~(. ``(-~~1(Uvrx~~(>~~~zrI~~~~(x~(><<<1..`.`.-4>>>?>????zzzwwXuuuuuXvvvwwrttttttttrOrwwwwXX
XkwwwwOttrrOOzz+++++<;;;:::;:;;<++zzzzzyyzzz++<;(_ ` `  `        ``(<~~~~zv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HkkHHHHmgm
WWWWkbWWWWpWXuZXXXVWXXXuwrttrrXZZZyVyZZyXkXzvzXX$~{``  `  `   `  ``  l:wW+zXkzd_` `,kHSWHMOXP` ` `  ` ! ` <?tl` ``,qRWHHMHgK```,_Jduuuv<J~~~kuXSuI~~~?<-.....`._WWHWUVrrwXXWWWWWkqmHHHWbkkpfyyfbWWWbbHqm
pWWWpppWWVfWkkwuXWpkwOtrwOwvwOOrwXUWpWXuXyXZZZXX<~<` `  `  `   `   ``(-wRhOuWuv|``  zHZwXwXf! `   `     ` ` ?O<` `,HZdHH@dqD`` >JwSuuzf(W_:(Suuuuv:~~~~~~~_<<+--(kXXXwOwXUWWHkHHHHWUZyWpWWppVVWWHkqmmmgg
qqkbbbpfVVfyyZZ0ZXUUUuuXXZXuvuuXXXuXWffWWWkXZZXr~~(.` `  `  ` `  ` ``.XzWuWXXHvG``` `?4kkkV^`  `       `  ````_ ` .HZXswdXC```,jdSuuuXCJW:~JzuuuuzI~~~~~~~~~~(0wWHW0ZtOwwwXyWWWZXWWWWWkHWyyppWWWbkqqHggg
ggmHHqqkkkbpVyuvrwzzzuuyyZuuuuZXuuuuZyyWWkHWWXXl~~_;` `    `   `  ` ``UWXkuWkh?yl``` ``````` `  `` ` `   `    `  ``.4kXXXY!``.XCduuXW0jHH:(Suuuuuzv<~~~~~~~~~(0tXZXXkwXWVXZtlOwXWbpWkmggHHWHmmggmqmHqHHH
gggHHHWWWHWUUuZuuuzuzXXZZuuuZyyWXZZZuuuZyWbkkWK:~~~>`  ` `  `   `  ` `(dHWXuXWL(4,```````` `` ``  `  `  `  `  ` ``````  ` ``.v!JzuXWRuSWX:dzuuuuuuzI~~~.~~.~~~0rXWHWqHHHWXrtttwWgH0VWHHWHHH@@@HWUVWHgHXX
HHHUUuZyyXzuzXZZZyZuuXwXZZuuXVVXXZZZZZZyfppfWW$~~~~( `  `  ` `  `   ``.WZwHuuzU!` ``````````` `  `  ` `  ` ` ` `````````````` JvXXXKGSZdDJXuuuuuuuzw<~~~~~~~~~dXXkmggHHHUVtrrwXWqHkzlllzwWpHggHkz?1ZWHWW
VwXkwwzuZXXXkZOXVWuuXXZ0VXuuuWWuzzuuuuZyWWUWXX:~~~~_;``      `  ` `  ``1I:?OzzZ;`````````` ``  `  `    ` `  ` `` ` `````````.JZ=kuWX0>:(dSuuuuzuuuuvc~~~~.~~~~Jqqqmg@HWWkXwvvwWH@gHwOOwwWqgggg@Hkz>1zwWg
XrXWW0OOwXpWSwzvXXzwtwwwOwuXXwZVOOOvzuuXkXrI1$~~~~~~1` `` `   `  ` ` ` (0+~~(zvX.`````````` `` ` ` `   `  `   ` ``````````` !`.vwWSZ:~(dpKuuuuuuuuzzI~~~~~~~~~(qmmgg@HWUUUXZOXWqg@HSOOXWgg@@@H@HHkzzXWHg
tlOXXkXXZyyfWXXuuzzuXwzzttOrOzzzzzOwwuwWKIz<J<~~~~~(z-`  ` ` `  `  ` .(^/(~~~(rrl````` `` ``  `   `  `   ` ` ` ``` ``````````.c~kzzZ~~((WHuuuzuuuuuzv<~~~.~~~~(KWWHg@gH0rrrrwWqH@@HSOwWg@@HHHHHMH0Z=zwUW
kOlOwXSZtrOXXwtltOOOZXUXwtOI1zOZUWWyyyWHHkmAf~~~~~~(r$.`  `  ` ` `  __c/`.l~~:jrw<``` `  `  `  `  `   `   `   `  ``````` ``` J~(RzzI~~~(WWuuuuuzzuuuvI~~~~.~~~:WfbkHH0XrwZXkXWH@@@HkXWH@@HHHHHHMHkkXXXXw
kwwwXWWkkZOvzz=lOOzwuuXU0OOOlzzzzzwWWHkHH@MH>~~~~~(zvw-_ ` `  `` .._>.!`.:1:~~(Ovv-` ` `    ` ` `   `  `   ` `  `     ` ``` JJdWSuzI~~~(WWkuuuzuuuuuzO~~~~~~~~~dWUU0XZwXZ0XWH@@qmH@gHZWH@HHH@M@@@HWyWb0T
HHWWH@@@HkkXwwOOvzz1l=11z++zywZuUXWHMHHHHHMK~~~~~~(zzu$~~_....-.~~(J(!`.::(?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` `.~(J_<:wr[``` _.` !. ` `   ` ..?~```` ,!?1wwSuv>:(SvddvrrvrrrrdkuuuuuXKuzc~~~~~~~~~dqkHHHHHHkHHkkXy>?I?jnJ+d@HMMMMBXXHWH
H@HHHWgggggHH@@@@ggqkbpbbSwUUWHMMHHHHMH<~~~~~(zuuuzZ``` `..~..~..`` `` ` ``  ```(.~O>>~Jk$ ```  ~.`` !-..._!``` `` .,!````.dzzC~(ZtrXSrrrrrttttWuzuuuuHuzI~~~.~~~~~?0OOOz1<<1OWWqH&z+WmHHmW@M#BXXmazdMHH
@H@MmmHHMHHHHHH@@qkbWfppWI<1dWbpHHHHHHD~~~~~~jzuuuvI`` ` ...~..~. ` ` ` ` ``` ``(._(c<~(SI_`  ` ``_-.`````````` ..!  `` ``.0zZ<(<?7CHOrrrrrrtrrZkuuuuuXkuw<~~~.~~~~~Owwz><?<?1zW8HHWqHMHMM@MM&,(dAdMRW6z
HH@@gg@@MMMMHMM@@HHHHHWHHkwwWppfXWWgHW>~~~~~(wzuuuvI``` ` ...~...` ` ` ` ` ` ` `<.`.r<~((l_`` `  ``.<<-.. ..._!```  `  ``.kzwI(>```.! ?OttrrttrrXuuuuuuHuzc~~~~~.~~~?kkWAZOdHmkkdMMHMgMHHHHNezXHWM91jdSW
HHHggHMHHWUUWWWH@@@@@@@HWWyWWZWkqqHHHP~~~~~~(zuuuuzw-```  ..~..~.`` `` ``  ` ```:_` $<~<(r  `` ` `` <....... ``  ` ` ``` Jvw9(:``` :````?OtttttrwHuuuuuWuzI~~~~~~~~~~XH$ZIdHHOMMMNgMMBTM@HQZ<(NNNK++nJd#
@@HgHXXVwvrtwuXWHqHH@@gHVVWWyWWHHpfyX>~~~~~~zzuuuuuvG.```` ..~... `  ``  ` ` ```> ``I+_{.\` ` ` ` ` :.. ._:_`` `` ` ````(rZjJ!``  `  ` ``.ItrtrrrdkuuuuXKuw_~~~.~~~~~(ugd0U6Vz1JM@HWMejgMHHNHMMMHHHMHHMH
gH@HHVtlOXXXXpWHH@@@@HHqbbkXWWH@@qkHD~~~~~~(rzuuuuuuwn.`` ` ..~.._`` ` ` `. `   :`` Iv(`-```  ` ` ``>._ ~(_ `  ` ` ` ``,Z^(< ``  ` `  ````.OrvzwrrWuuuuuHuz>~~~~~~~~~(XnzWBWmyWRdQMHH@94WH#I<?TIdYWRzUXH
qqHWVwXXXfpbbkH@MHmkWWXXWHHMHHH@HHWXC~~~~~~(zuuXuuuuuWH,```` ..~__ ` `  `  ` `` !``.1I>`_` ``` ` ` `:. ..>_`` ` ` ` ``.=.?!``` `` ` `` . ``(rrzuwrwWuuuudkzI~~~~.~~~~~zWH@MMM#MM#MM90vO=dMmmgHmdH96<zuvW
ffW0rwXuZyyZWHHMgqqbWXXXWHMMMHHHHZXf~~~~~~~zzuXSuuuudHHMe.``` ..~>_`` ```  ` `` _``(z=```    ` ` ```<.`~(>`` ``  ` ` `` ````  ` ` ` ` .~```.kvzuXwvdkuuuuHuw_~~~~.~~~~?VHHM4WMmdMMMMNdMkqXMHB7TUOwueWMMM
pWpWXXOwuX0ZwXWWHHHHHHHqH@@@@HHWyWWC~~~~~~(vzuXuuuuXMHHMHS, `` ..(. `  ` . `   `` .=```  ```` ` ` ``(_ .(_``  `` ` `   `  ` ` `  ` ` `.` ```OrzuZuvrXkuuuXXz>~~~~~~~~~~wWWHHMNMMMMMNMgM#NM#M9+<1vY61dWMM
HWHSOztrrtlltwWHMMM@H@HVWMHM@HkkXWP:~~~.~~(zuXSuuuuWHHHMHXZo-`` .(-_```  .  `` ` ````` ` `  `  `   `.` ~>`` `  `` ` `` ``  ` ` `` ` ``:`  ``jrvzuZzvvXXuuXRzI~~~~.~~~~~(QxWsdHMMMNMMMNMMMMNoz6<zC+-(jdMW
@H0C<1ltvOzzUOZOXWWHHHgH@HHHMMggqq>~~~~~~~jzuXuuuuXMMHHU0XXkk,.`_~>._` ` .`  `` `   `  `` ` `` `` ``.  _> `` ``  ` ` `  `` ` ` ` ` `` :`` ``(rvzuZuzvvWXuuWuw_~~~~.~~~~(STMMM#NMMNMHM9TM871J~j+.?UkHNgS&
MSZlttI1ztzwrwOI+zVUuWH@HMHHHXkHHK~~~~~~~(wzuKuuuXHHHWHHHkH@HHh--~(_. ``._` `  ` ``  ``  ` `  ` `  ` . (_`  ` ` ` ` ` ` ` ` ` ` ` `  .` `` `.rvzzuuuvvzWuuXKzc~~~~~~~~~~dnH#NMNMMHM9<<_dWyqWgxCXkzzdMNH@
0OOOrzwvzOOC+OrOzuyXwwXkkkXXWXXUX3~~~~~~~(zuXSuuudHH@@HH@H@HHHMHe__l._` . ` ` ` ` ``  `  `` `` ` ` ` _-( `` `  ` ` ` ` ` ` ` ` ` `.``.`  ```.4vzvvuuzzvuHuuWuO:~~~~.~~~~(MMMMMMHMMMHHR=<dNWMSjHIgdMQMMMM
wyOCzOXWXwttvz+OXyWUkO+?wkAwXHyfK:~~~~~~~jzuXuuuXHmggggHHH@@H@H@HNJj_.` . `  ` `   ` ` `  `  ` ` `` `:.;`` ` `` ` `  ``  ` `  ` ` _``;``  ``.<1vvvXyuzzzXHuXkv<~~~~~~~~~(SX9WXWM#MM6WmgdMS3jHHY<udW9TNgH
HkXW0I&zZC1jQkQ0>+1zvwZk<dWUHXXX3~~~~~~~_zuuKuuudg@@@@g@HMHHH@HHH#HNc~_ .```  ` ``  ` ` `  `  `   ```<_}`` `  ` ` ` `  `` ` ` ` ``~`.! ``  ` : 1rvwXuuzzzXHZHz>~~~~~~~~~~z>(dNHMMHRWN#HHKddHK<<(Z1z&dHD<
kzZ1OXCwzjwXWXXI(zwwAwZwv<+XHHXK:~~~~~~~(zuXRuuXH@gmHHHH@@HHHHMM#NNHN__..`` `` ` `` ` ` ``` `` ``  ``((:``` `` ` ` ` `` `  ` `` ``_`.`` ```` :``jXwrvuXXkuXHWXI:~~~~~~~~:J4HHMMNdMMNXMMHM@D<?1XWHHmHHMHH
'''


import sys
input = sys.stdin.readline

n = int(input())
A = tuple(map(int,input().split()))
p = 10**9+7
used = [-1]*n
for i in range(n+1):
    if used[A[i]-1]>=0:
        a = used[A[i]-1]
        b = i
        break
    used[A[i]-1] = i


#互いに素なa,bについて、a*x+b*y=1の一つの解
def extgcd(a,b):
    r = [1,0,a]
    w = [0,1,b]
    while w[2]!=1:
        q = r[2]//w[2]
        r2 = w
        w2 = [r[0]-q*w[0],r[1]-q*w[1],r[2]-q*w[2]]
        r = r2
        w = w2
    #[x,y]
    return [w[0],w[1]]

# aの逆元(mod m)を求める。(aとmは互いに素であることが前提)
def mod_inv(a,m):
    x = extgcd(a,m)[0]
    return (m+x%m)%m

######################################################


#pは素数とする

#fact[i] : i! modp (0<= i <p) O(p)
fact = [1]
k = 1
for i in range(1,n+2):
    k = k*i%p
    fact.append(k)


#n! = a p^eとしたときのeを求める (O(logp n)
def mod_e(n,p):
    res = 0
    while n >= p:
        res += n//p
        n = n//p
    return res

#n! = a p^eとしたときのa mod pを求める  (O(logp n)
def mod_fact(n,p):
    if n==0:
        return 1
    
    
    res = mod_fact(n//p,p)
    
    if n//p %2 != 0:
        return res*(p-fact[n%p])%p
    return res*fact[n%p]%p
    
######################################################

#nCk mod p
def mod_comb(n,k,p):
    if n < 0 or k < 0 or n<k:
        return 0
    e1 = mod_e(n,p)
    e2 = mod_e(k,p)
    e3 = mod_e(n-k,p)
    #pで割り切れる場合
    if e1 > e2 + e3:
        return 0

    #pで割り切れない場合
    a1 = mod_fact(n,p)
    a2 = mod_fact(k,p)
    a3 = mod_fact(n-k,p)
    return a1 * mod_inv(a2*a3%p,p) %p
#print(a,b)
for i in range(1,n+2):
    res = mod_comb(n+1,i,p)-mod_comb(a+n-b,i-1,p)
    if res < 0:
        res += p
    print(res)

Submission status: Time Limit Exceeded

Solution code:

from collections import Counter
mod=10**9+7
N=10**5+11
fac,finv,inv = [0]*N,[0]*N,[0]*N

def cmb_init():
        fac[0]=fac[1]=finv[0]=finv[1]=inv[1]=1
        for i in range(2,N):
                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 cmb_mod(n,k):
        if n<k : return 0
        return fac[n]*(finv[k]*finv[n-k]%mod)%mod

n=int(input())
a=list(map(int,input().split()))
ac = Counter(a)
sames=[i for i,x in enumerate(a) if x==ac.most_common()[0][0]]
same_len = sames[0]+(n-sames[1])
cmb_init()
print(n)

for i in range(1,n):
        print(cmb_mod(n+1,i+1) - cmb_mod(same_len,i))
print(1)

Submission status: Time Limit Exceeded

Solution code:
ai = lambda: list(map(int,input().split()))
ai_ = lambda: [int(x)-1 for x in input().split()]


n = int(input())
a = ai()
MOD = 10**9+7

from collections import Counter
dup = list(Counter(sorted(a)).values()).index(2)+1
ant = a.index(dup)
post = a[::-1].index(dup)


def nCb(n, r):
    fac = [1, 1] + [0] * n
    finv = [1, 1] + [0] * n
    inv = [0, 1] + [0] * n
    for i in range(2, n + 2):
        fac[i] = fac[i - 1] * i % MOD
        inv[i] = -inv[MOD % i] * (MOD // i) % MOD
        finv[i] = finv[i - 1] * inv[i] % MOD
        
    if n < r: return 0
    if n < 0 or r < 0: return 0
    return fac[n] * (finv[r] * finv[n - r] % MOD) % MOD


for k in range(1,n+2):
    if k == 1:
        print(n)
    else:
        ans = nCb(n+1,k)
        if ant+post+1 >= k:
            ans -= nCb(ant+post,k-1)
        print(ans)

Submission status: Time Limit Exceeded

Solution code:
ai = lambda: list(map(int,input().split()))
ai_ = lambda: [int(x)-1 for x in input().split()]


n = int(input())
a = ai()
mod = 10**9+7

from collections import Counter
dup = list(Counter(sorted(a)).values()).index(2)+1
ant = a.index(dup)
post = a[::-1].index(dup)


def nCb(n, b):
    if b > n - b:
        b = n - b
    r = 1
    for k in range(n, n-b, -1):
        r = r * k % mod
    d = 1
    for k in range(1, b+1):
        d = d * k % mod
    return r * inv(d) % mod


def inv(x):
    return pow(x, mod - 2, mod)


for k in range(1,n+2):
    if k == 1:
        print(n)
    else:
        ans = nCb(n+1,k)
        if ant+post+1 >= k:
            ans -= nCb(ant+post,k-1)
        print(ans)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
a=[int(i) for i in input().split()]
import math
import collections
m=10**9+7
def bp(a,n):
        r=1
        while(n):
           if n%2:
              r=r*a%m
           a=a*a%m
           n>>=1
        return r

c = collections.Counter(a)
b=c.most_common()[0][0]
kk=a.index(b)
k=n-a[::-1].index(b)


def C(n, r):
    return ((math.factorial(n)%m) * bp(math.factorial(n - r),10**9+5)* bp(math.factorial(r),10**9+5))%m
print(n)
for i in range(n):
 x=C(n+1,i+2)
 if kk+n-k>=i+1:x-=C(kk+n-k,i+1)
 
 print(x)

Submission status: Time Limit Exceeded

Solution code:
MOD = 10**9 + 7

fact = {i: None for i in range(10**6+1)}                 # n!
inverse = {i: None for i in range(1, 10**6+1)}       # inverse of n in the field Z/(MOD)Z
fact_inverse = {i: None for i in range(10**6+1)}  # inverse of n! in the field Z/(MOD)Z

fact[0] = fact[1] = 1
fact_inverse[0] = fact_inverse[1] = 1
inverse[1] = 1
for i in range(2, 10**6+1):
    fact[i] = i * fact[i-1] % MOD
    inverse[i] = - inverse[MOD % i] * (MOD // i) % MOD
    fact_inverse[i] = inverse[i] * fact_inverse[i-1] % MOD

def combination(n, r):
    if n < r or n < 0 or r < 0:
        return 0
    else:
        return fact[n] * (fact_inverse[r] * fact_inverse[n-r] % MOD) % MOD

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

dup_num = sum(A) - n*(n+1)//2
dup_idx = []
for i, a in enumerate(A):
    if a == dup_num:
        dup_idx.append(i)
        
left, right = dup_idx[0], dup_idx[1]
        
for k in range(1, n+2):
    print((combination(n+1, k) - combination(n + 1 - (right - left + 1), k - 1)) % MOD)

Submission status: Time Limit Exceeded

Solution code:
import sys
stdin = sys.stdin

sys.setrecursionlimit(10**5)

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

n = ni()
a = list(li())
# 2こあるものは何か
cnt = Counter(a)
two = cnt.most_common(1)[0][0]

left = a.index(two)
right = a[::-1].index(two)

# 二項係数準備
MOD = 10**9+7

inv = inv_mod(n+2,MOD)
fac = fact(n+2,MOD)
fac_inv = fact_inv(n+2,inv,MOD)

for i in range(1,n+2):
    if 1 < i < n+1:
        ans = nCr(n+1,i,MOD,fac,fac_inv)
        for j in range(i):
            if j <= left and (i-j-1) <= right:
                ans -= nCr(left,j,MOD,fac,fac_inv) * nCr(right,(i-j-1),MOD,fac,fac_inv)
                
        if ans < 0:
            ans += MOD
            
        print(ans)
        
    elif i == 1:
        print(n)
    else:
        print(1)

Submission status: Time Limit Exceeded

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

c = [1,n-1]
#c[i]:n-1 C i
for i in range(1,n+1):
    if n < i+2:
        c.append(0)
    else:
        r = (c[-1]*(n-1-i)//(i+1))
        c.append(r)
k = sum(a)- n*(n+1)//2

pp = []
for i in range(n+1):
    if a[i] == k:
        pp.append(i)
w = pp[1]-pp[0]-1

d = [1,n-w-1]
#d[i]:n-w-1 C i
for i in range(1,n+1):
    if n-w-1  < i+1:
        d.append(0)
    else:
        r = (d[-1]*(n-w-1-i)//(i+1))
        
        d.append(r)
for i in range(len(c)):
    c[i] = c[i]%(10**9+7)
    d[i] = d[i]%(10**9+7)
    

print(n)
for i in range(2,n+2):
    #nagasa k = i
    ass = 0
    ass += c[i] + c[i-1]*2 -d[i-1] + c[i-2]
    ass = ass % (10**9+7)
    print(ass)

Submission status: Time Limit Exceeded

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

c = [1,n-1]
#c[i]:n-1 C i
for i in range(1,n+1):
    if n - 1 < i+1:
        c.append(0)
    else:
        r = c[-1]*(n-1-i)//(i+1)
        c.append(r)
k = sum(a)- n*(n+1)//2
pp = []
for i in range(n+1):
    if a[i] == k:
        pp.append(i)
w = pp[1]-pp[0]-1

d = [1,n-w-1]
#d[i]:n-w-1 C i
for i in range(1,n+1):
    if n-w-1  < i+1:
        d.append(0)
    else:
        r = d[-1]*(n-w-1-i)//(i+1)
        d.append(r)

print(n)
for i in range(2,n+2):
    #nagasa k = i
    ass = 0
    ass += c[i]
    ass += c[i-1]
    ass += c[i-1]- d[i-1]
    ass += c[i-2]
    ass = ass % (10**9+7)
    print(ass)

Submission status: Time Limit Exceeded

Solution code:
from sys import exit, setrecursionlimit, stderr
from functools import reduce
from itertools import *
from collections import *
from bisect import bisect
from heapq import *

def read():
  return int(input())
 
def reads():
  return [int(x) for x in input().split()]

MOD = 10**9 + 7
 
N = read()
A = reads()

fact = [1] * N
for i in range(1, N):
  fact[i] = (fact[i-1] * i) % MOD 
invfact = [0] * N; invfact[-1] = pow(fact[-1], MOD-2, MOD)
for i in range(N-2, -1, -1):
  invfact[i] = invfact[i+1] * (i+1)
def comb(n, k):
  # print(n, k)
  return fact[n] * invfact[n-k] * invfact[k] % MOD  

cnt = Counter(A)
q = next(i for i in range(1,N+1) if cnt[i] == 2)
i1 = A.index(q); i2 = A.index(q, i1+1)
m = N - (i2 - i1)
# print(m)

print(N)
for k in range(2, N+1):
  ans = comb(N-1, k-1) * 2 + comb(N-1, k-2)
  if m >= k-1:
    ans -= comb(m, k-1)
  if k <= N-1:
    ans += comb(N-1, k)
  print(ans % MOD)
print(1)

Submission status: Time Limit Exceeded

Solution code:
import scipy.misc as scm
from statistics import mode

n=int(input())
a=[int(i) for i in input().split()]
d=mode(a)

x=0
lr=0
for i in a:
  if i==d:
    x+=1
  if x==0 or x==2:
    lr+=1
lr-=1    

for i in range(n+1):
  m=0
  if i==0:
    m+=1
  if lr >= i >=1:
    m+=int(scm.comb(lr, i, 1))
  print((int(scm.comb(n+1, i+1, 1)) - m )% (10**9 + 7) )

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter
import scipy.misc as scm

n=int(input())
a=[int(i) for i in input().split()]
c=Counter(a)
d=max([i for i,j in c.most_common() if j==2])
x=0
l=0
r=0
for i in a:
  if i==d:
    x+=1
  if x==0:
    l+=1
  elif x==2:
    r+=1
r-=1    

for i in range(n+1):
  m=0
  if i==0:
    m+=1
  if i+1 >=2:
    m+=int(scm.comb(l+r, i, 1))
  print((int(scm.comb(n+1, i+1, 1)) - m) % (10**9 + 7))

Submission status: Time Limit Exceeded

Solution code:
import math

def LI(): return list(map(int, input().split()))
def LS(): return input().split()
def I(): return int(input())
def S(): return input()
def combi(n,k):
    f = math.factorial
    return f(n) // f(k) // f(n-k)

n = I()
a = LI()

two = 0
for i in range(1, n + 1):
    if a.count(i) == 2:
        two = i
        break
L = a.index(two)
R = a[::-1].index(two)

ans = []
for k in range(1, n+2):
    all = combi(n + 1, k)
    if k == 1:
        all -= 1
    else:
        if k <= R + L + 1:
          for i in range(max(0, k-1 - R), min(k - 1, L) + 1 ):
                all -= combi(L,i)*combi(R, k-1 - i)
    #print(all)
    ans.append(all%(10**9 + 7))
for i in ans:
    print(i)

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
def inpl(): return tuple(map(int, input().split()))

n = int(input())
A = inpl()

F = [1 for _ in range(n+2)]
f = 1

for x in range(1, n+2):
    f *= x
    F[x] = f
    
def comb(n, r):
    global F
    if n < r:
        return 0
    elif r <= 0:
        return 0
    else:
        return F[n]//(F[r] * F[n-r])


C = ["" for i in range(n+1)]

for l, a in enumerate(A):
    if type(C[a]) == int:
        i, j = C[a], l
        break
    else:
        C[a] = l

print(n)

for k in range(2, n+2):
    total = comb(n+1, k)
    b = comb(n+i-j, k-1)
    res = (total-b)%(10**9 + 7)
    print(res)

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
from math import factorial
from scipy.misc import comb
def inpl(): return tuple(map(int, input().split()))

def combination(n, r):
    if n < r:
        return 0
    else:
        return factorial(n)//(factorial(r) * factorial(n-r))

n = int(input())
A = inpl()
C = ["" for i in range(n+1)]

for l, a in enumerate(A):
    if type(C[a]) == int:
        i, j = C[a], l
        break
    else:
        C[a] = l

print(n)

for k in range(2, n+2):
    total = comb(n+1, k, 1)
    b = comb(n+i-j, k-1, 1)
    res = (total-b)%(10**9 + 7)
    print(res)

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
from math import factorial
def inpl(): return tuple(map(int, input().split()))

def combination(n, r):
    if n < r:
        return 0
    else:
        return factorial(n)//(factorial(r) * factorial(n-r))

N = int(input())
A = inpl()
C = ["" for i in range(N+1)]

for l, a in enumerate(A):
    if type(C[a]) == int:
        i, j = C[a], l
        break
    else:
        C[a] = l

print(N)

X = i + N - j
for k in range(2, N+2):
    total = combination(N+1, k)
    b = combination(X, k-1)
    print((total-b)%(10**9 + 7))

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
from collections import Counter
from math import factorial
def inpl(): return tuple(map(int, input().split()))

def combination(n, r):
    if n < r:
        return 0
    elif r < 0:
        return 0
    else:
        return factorial(n)//(factorial(r) * factorial(n-r))

N = int(input())
A = inpl()
C = ["" for i in range(N+1)]

for l, a in enumerate(A):
    if type(C[a]) == int:
        i, j = C[a], l
    else:
        C[a] = l

print(N)
for k in range(2, N+2):
    total = combination(N+1, k)
    b = combination(i + (N-j), k-1)
    print((total-b)%(10**9 + 7))

Submission status: Time Limit Exceeded

Solution code:
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools

sys.setrecursionlimit(10**7)
inf = 10**20
mod = 10**9 + 7

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()


def inv(a):
    n = mod - 2
    r = 1
    while n > 0:
        if n % 2 == 1:
            r = r * a % mod
        a = a * a % mod
        n >>= 1
    return r

def nCb(n, b):
    if b > n - b:
        b = n - b
    r = 1
    for k in range(n, n-b, -1):
        r = r * k % mod
    d = 1
    for k in range(1, b+1):
        d = d * k % mod
    return r * inv(d) % mod


def main():
    n = I()
    a = LI_()
    b = [-1] * n
    t = 1
    for i in range(n+1):
        c = a[i]
        if b[c] >= 0:
            t = i - b[c]
            break
        b[c] = i

    rr = [n]
    for i in range(2,n+2):
        tr = nCb(n+1,i)
        if n-t >= i-1:
            tr -= nCb(n-t, i-1)
            tr %= mod
        rr.append(tr)
    return '\n'.join(map(str, rr))

print(main())

Submission status: Time Limit Exceeded

Solution code:
# coding: utf-8
import array, bisect, collections, copy, heapq, itertools, math, random, re, string, sys, time

sys.setrecursionlimit(10 ** 7)
INF = 10 ** 20
MOD = 10 ** 9 + 7


def II(): return int(input())
def ILI(): return list(map(int, input().split()))
def IAI(LINE): return [ILI() for __ in range(LINE)]
def IDI(): return {key: value for key, value in ILI()}


def read():
    n = II()
    a = ILI()
    return n, a


def nCr(n, r):
    if r == 0:
        ret = 1
    elif n >= r:
        ret = math.factorial(n) // (math.factorial(r) * math.factorial(n - r))
    else:
        ret = 0
    return ret


def solve(n, a):
    d_check = collections.defaultdict(int)
    ind_double = None
    for ind, ele in enumerate(a):
        if ele in d_check:
            ind_double = (d_check[ele], ind)
            break
        else:
            d_check[ele] = ind

    len_left = ind_double[0]
    len_right = n - ind_double[1]
    len_edge = len_left + len_right

    fact_table = [1, 1]
    for i in range(2, n + 2):
        ap = fact_table[i - 1] * i
        fact_table.append(ap)

    ans = []
    for i in range(1, n + 2):
        comb_all = fact_table[n + 1] // (fact_table[i] * fact_table[n + 1 - i])
        if len_edge >= i - 1:
            comb_edge = fact_table[len_edge] // (fact_table[i - 1] * fact_table[len_edge - i + 1])
        else:
            comb_edge = 0
        joined = comb_all - comb_edge
        ans.append(joined % MOD)

    ans = "\n".join(map(str, ans))
    return ans


def main():
    params = read()
    print(solve(*params))


if __name__ == "__main__":
    main()