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:
#!/usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
import itertools
sys.setrecursionlimit(10**5)
stdin = sys.stdin
bisect_left = bisect.bisect_left
bisect_right = bisect.bisect_right
def LI(): return list(map(int, stdin.readline().split()))
def LF(): return list(map(float, stdin.readline().split()))
def LI_(): return list(map(lambda x: int(x)-1, stdin.readline().split()))
def II(): return int(stdin.readline())
def IF(): return float(stdin.readline())
def LS(): return list(map(list, stdin.readline().split()))
def S(): return list(stdin.readline().rstrip())
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = float('INF')

#A
def A():
    a, b, c = LI()
    print(min(a+b,b+c,c+a))
    return

#B
def B():
    def check(s):
        x = len(s)
        if x % 2:
            return False
        if s[:x // 2] == s[x // 2:]:
            return True
    s = S()
    for i in range(1,len(s)):
        if check(s[: - i]):
            print(len(s) - i)
            return

#C
def C():
    II()
    a = LI()
    ans1 = a[-1::-2]
    ans2 = a[-2::-2][::-1]
    ans = ans1 + ans2
    print(*ans)
    return

#D
def D():
    def power_func(a, b, mod):
        """ a^b mod p を求める """
        """ bを2進数分解して高速累乗 """

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

    def combination_mod1(n, k, mod):
        """ power_funcを用いて(nCk) mod p を求める """ 
        """ nCk = n!/((n-k)!k!)を使用 """

        if n < 0 or k < 0 or n < k: return 0
        if n == 0 or k == 0: return 1
        a = factorial[n]
        b = factorial[k]
        c = factorial[n - k]
        return (a * power_func(b, mod - 2, mod) * power_func(c, mod - 2, mod)) % mod

    def combination_mod2(n, k, mod):
        """ power_funcを用いて(nCk) mod p を求める """ 
        """ nCk = n!/((n-k)!k!)を使用 """

        
        if n <= 0 or k <= 0 or n < k: return 0
        if n == 0 or k == 0: return 1
        a = factorial[n]
        b = factorial[k]
        c = factorial[n - k]
        return (a * power_func(b, mod - 2, mod) * power_func(c, mod - 2, mod)) % mod
    n = II() + 1
    a = LI()
    d = defaultdict(int)
    for i in range(n):
        if d[a[i]]:
            a = d[a[i]] - 1
            c = n - i - 1
            break
        d[a[i]] = i + 1
    factorial = [1] * (n + 1)
    for i in range(1, n + 1):
        factorial[i] = (factorial[i - 1] * i) % mod
    for i in range(1, n + 1):
        ans = combination_mod1(n - 2, i, mod)
        ans += combination_mod1(n - 2, i - 1, mod) * 2
        ans += combination_mod1(n - 2, i - 2, mod)
        ans -= combination_mod2(c + a, i - 1, mod)
        ans -= combination_mod2(1, i, mod)
        print(ans%mod)
    return

#Solve
if __name__ == '__main__':
    D()

Submission status: Time Limit Exceeded

Solution code:
#!/usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
import itertools
sys.setrecursionlimit(10**5)
stdin = sys.stdin
bisect_left = bisect.bisect_left
bisect_right = bisect.bisect_right
def LI(): return list(map(int, stdin.readline().split()))
def LF(): return list(map(float, stdin.readline().split()))
def LI_(): return list(map(lambda x: int(x)-1, stdin.readline().split()))
def II(): return int(stdin.readline())
def IF(): return float(stdin.readline())
def LS(): return list(map(list, stdin.readline().split()))
def S(): return list(stdin.readline().rstrip())
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = float('INF')

#A
def A():
    a, b, c = LI()
    print(min(a+b,b+c,c+a))
    return

#B
def B():
    def check(s):
        x = len(s)
        if x % 2:
            return False
        if s[:x // 2] == s[x // 2:]:
            return True
    s = S()
    for i in range(1,len(s)):
        if check(s[: - i]):
            print(len(s) - i)
            return

#C
def C():
    II()
    a = LI()
    ans1 = a[-1::-2]
    ans2 = a[-2::-2][::-1]
    ans = ans1 + ans2
    print(*ans)
    return

#D
def D():
    def power_func(a, b, mod):
        """ a^b mod p を求める """
        """ bを2進数分解して高速累乗 """

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

    def combination_mod1(n, k, mod):
        """ power_funcを用いて(nCk) mod p を求める """ 
        """ nCk = n!/((n-k)!k!)を使用 """

        if n < 0 or k < 0 or n < k: return 0
        if n == 0 or k == 0: return 1
        a = factorial[n]
        b = factorial[k]
        c = factorial[n - k]
        return (a * power_func(b, mod - 2, mod) * power_func(c, mod - 2, mod)) % mod

    def combination_mod2(n, k, mod):
        """ power_funcを用いて(nCk) mod p を求める """ 
        """ nCk = n!/((n-k)!k!)を使用 """

        
        if n <= 0 or k <= 0 or n < k: return 0
        if n == 0 or k == 0: return 1
        a = factorial[n]
        b = factorial[k]
        c = factorial[n - k]
        return (a * power_func(b, mod - 2, mod) * power_func(c, mod - 2, mod)) % mod
    from math import factorial
    n = II() + 1
    a = LI()
    d = defaultdict(int)
    for i in range(n):
        if d[a[i]]:
            a = d[a[i]] - 1
            c = n - i - 1
            break
        d[a[i]] = i + 1
    factorial = [1] * (n + 1)
    for i in range(1, n + 1):
        factorial[i] = (factorial[i - 1] * i) % mod
    for i in range(1, n + 1):
        ans = combination_mod1(n - 2, i, mod)
        ans += combination_mod1(n - 2, i - 1, mod) * 2
        ans += combination_mod1(n - 2, i - 2, mod)
        ans -= combination_mod2(c + a, i - 1, mod)
        ans -= combination_mod2(1, i, mod)
        print(ans%mod)
    return

#Solve
if __name__ == '__main__':
    D()

Submission status: Time Limit Exceeded

Solution code:
#!/usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
import itertools
sys.setrecursionlimit(10**5)
stdin = sys.stdin
bisect_left = bisect.bisect_left
bisect_right = bisect.bisect_right
def LI(): return list(map(int, stdin.readline().split()))
def LF(): return list(map(float, stdin.readline().split()))
def LI_(): return list(map(lambda x: int(x)-1, stdin.readline().split()))
def II(): return int(stdin.readline())
def IF(): return float(stdin.readline())
def LS(): return list(map(list, stdin.readline().split()))
def S(): return list(stdin.readline().rstrip())
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = float('INF')

#A
def A():
    a, b, c = LI()
    print(min(a+b,b+c,c+a))
    return

#B
def B():
    def check(s):
        x = len(s)
        if x % 2:
            return False
        if s[:x // 2] == s[x // 2:]:
            return True
    s = S()
    for i in range(1,len(s)):
        if check(s[: - i]):
            print(len(s) - i)
            return

#C
def C():
    II()
    a = LI()
    ans1 = a[-1::-2]
    ans2 = a[-2::-2][::-1]
    ans = ans1 + ans2
    print(*ans)
    return

#D
def D():
    def power_func(a, b, mod):
        """ a^b mod p を求める """
        """ bを2進数分解して高速累乗 """

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

    def combination_mod1(n, k, mod):
        """ power_funcを用いて(nCk) mod p を求める """ 
        """ nCk = n!/((n-k)!k!)を使用 """

        from math import factorial
        if n < 0 or k < 0 or n < k: return 0
        if n == 0 or k == 0: return 1
        a = factorial(n) % mod
        b = factorial(k) % mod
        c = factorial(n - k) % mod
        return (a * power_func(b, mod - 2, mod) * power_func(c, mod - 2, mod)) % mod

    def combination_mod2(n, k, mod):
        """ power_funcを用いて(nCk) mod p を求める """ 
        """ nCk = n!/((n-k)!k!)を使用 """

        
        if n <= 0 or k <= 0 or n < k: return 0
        if n == 0 or k == 0: return 1
        a = factorial[n]
        b = factorial[k]
        c = factorial[n - k]
        return (a * power_func(b, mod - 2, mod) * power_func(c, mod - 2, mod)) % mod
    from math import factorial
    n = II() + 1
    a = LI()
    d = defaultdict(int)
    for i in range(n):
        if d[a[i]]:
            a = d[a[i]] - 1
            c = n - i - 1
            break
        d[a[i]] = i + 1
    factorial = [1] * (n + 1)
    for i in range(1, n + 1):
        factorial[i] = (factorial[i - 1] * i) % mod
    for i in range(1, n + 1):
        ans = combination_mod1(n - 2, i, mod)
        ans += combination_mod1(n - 2, i - 1, mod) * 2
        ans += combination_mod1(n - 2, i - 2, mod)
        ans -= combination_mod2(c + a, i - 1, mod)
        ans -= combination_mod2(1, i, mod)
        print(ans%mod)
    return

#Solve
if __name__ == '__main__':
    D()

Submission status: Time Limit Exceeded

Solution code:
#!/usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
import itertools
sys.setrecursionlimit(10**5)
stdin = sys.stdin
bisect_left = bisect.bisect_left
bisect_right = bisect.bisect_right
def LI(): return list(map(int, stdin.readline().split()))
def LF(): return list(map(float, stdin.readline().split()))
def LI_(): return list(map(lambda x: int(x)-1, stdin.readline().split()))
def II(): return int(stdin.readline())
def IF(): return float(stdin.readline())
def LS(): return list(map(list, stdin.readline().split()))
def S(): return list(stdin.readline().rstrip())
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = float('INF')

#A
def A():
    a, b, c = LI()
    print(min(a+b,b+c,c+a))
    return

#B
def B():
    def check(s):
        x = len(s)
        if x % 2:
            return False
        if s[:x // 2] == s[x // 2:]:
            return True
    s = S()
    for i in range(1,len(s)):
        if check(s[: - i]):
            print(len(s) - i)
            return

#C
def C():
    II()
    a = LI()
    ans1 = a[-1::-2]
    ans2 = a[-2::-2][::-1]
    ans = ans1 + ans2
    print(*ans)
    return

#D
def D():
    def power_func(a, b, mod):
        """ a^b mod p を求める """
        """ bを2進数分解して高速累乗 """

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

    def combination_mod1(n, k, mod):
        """ power_funcを用いて(nCk) mod p を求める """ 
        """ nCk = n!/((n-k)!k!)を使用 """

        from math import factorial
        if n < 0 or k < 0 or n < k: return 0
        if n == 0 or k == 0: return 1
        a = factorial(n) % mod
        b = factorial(k) % mod
        c = factorial(n - k) % mod
        return (a * power_func(b, mod - 2, mod) * power_func(c, mod - 2, mod)) % mod

    def combination_mod2(n, k, mod):
        """ power_funcを用いて(nCk) mod p を求める """ 
        """ nCk = n!/((n-k)!k!)を使用 """

        
        if n <= 0 or k <= 0 or n < k: return 0
        if n == 0 or k == 0: return 1
        a = factorial[n] % mod
        b = factorial[k] % mod
        c = factorial[n - k] % mod
        return (a * power_func(b, mod - 2, mod) * power_func(c, mod - 2, mod)) % mod
    from math import factorial
    n = II() + 1
    a = LI()
    d = defaultdict(int)
    for i in range(n):
        if d[a[i]]:
            a = d[a[i]] - 1
            c = n - i - 1
            break
        d[a[i]] = i + 1
    factorial = [factorial(i) for i in range(n+1)]
    for i in range(1, n + 1):
        ans = combination_mod1(n - 2, i, mod)
        ans += combination_mod1(n - 2, i - 1, mod) * 2
        ans += combination_mod1(n - 2, i - 2, mod)
        ans -= combination_mod2(c + a, i - 1, mod)
        ans -= combination_mod2(1, i, mod)
        print(ans%mod)
    return

#Solve
if __name__ == '__main__':
    D()

Submission status: Time Limit Exceeded

Solution code:
#!/usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
import itertools
sys.setrecursionlimit(10**5)
stdin = sys.stdin
bisect_left = bisect.bisect_left
bisect_right = bisect.bisect_right
def LI(): return list(map(int, stdin.readline().split()))
def LF(): return list(map(float, stdin.readline().split()))
def LI_(): return list(map(lambda x: int(x)-1, stdin.readline().split()))
def II(): return int(stdin.readline())
def IF(): return float(stdin.readline())
def LS(): return list(map(list, stdin.readline().split()))
def S(): return list(stdin.readline().rstrip())
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = float('INF')

#A
def A():
    a, b, c = LI()
    print(min(a+b,b+c,c+a))
    return

#B
def B():
    def check(s):
        x = len(s)
        if x % 2:
            return False
        if s[:x // 2] == s[x // 2:]:
            return True
    s = S()
    for i in range(1,len(s)):
        if check(s[: - i]):
            print(len(s) - i)
            return

#C
def C():
    II()
    a = LI()
    ans1 = a[-1::-2]
    ans2 = a[-2::-2][::-1]
    ans = ans1 + ans2
    print(*ans)
    return

#D
def D():
    def power_func(a, b, mod):
        """ a^b mod p を求める """
        """ bを2進数分解して高速累乗 """

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

    def combination_mod1(n, k, mod):
        """ power_funcを用いて(nCk) mod p を求める """ 
        """ nCk = n!/((n-k)!k!)を使用 """

        from math import factorial
        if n < 0 or k < 0 or n < k: return 0
        if n == 0 or k == 0: return 1
        a = factorial(n) % mod
        b = factorial(k) % mod
        c = factorial(n - k) % mod
        return (a * power_func(b, mod - 2, mod) * power_func(c, mod - 2, mod)) % mod

    def combination_mod2(n, k, mod):
        """ power_funcを用いて(nCk) mod p を求める """ 
        """ nCk = n!/((n-k)!k!)を使用 """

        from math import factorial
        if n <= 0 or k <= 0 or n < k: return 0
        if n == 0 or k == 0: return 1
        a = factorial(n) % mod
        b = factorial(k) % mod
        c = factorial(n - k) % mod
        return (a * power_func(b, mod - 2, mod) * power_func(c, mod - 2, mod)) % mod

    n = II() + 1
    a = LI()
    d = defaultdict(int)
    for i in range(n):
        if d[a[i]]:
            a = d[a[i]] - 1
            c = n - i - 1
            break
        d[a[i]] = i + 1
    for i in range(1, n + 1):
        ans = combination_mod1(n - 2, i, mod)
        ans += combination_mod1(n - 2, i - 1, mod) * 2
        ans += combination_mod1(n - 2, i - 2, mod)
        ans -= combination_mod2(c + a, i - 1, mod)
        ans -= combination_mod2(1, i, mod)
        print(ans%mod)
    return

#Solve
if __name__ == '__main__':
    D()

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter


class Mint:
    MOD = 1000000007  # Must be a prime
    CACHE_FACTORIALS = [1, 1]

    def __init__(self, v):
        if self.__isally(v):
            self.v = v.v % self.MOD
        else:
            self.v = v % self.MOD

    @property
    def inv(self):
        return Mint(self.__minv(self.v))

    @classmethod
    def factorial(cls, v):
        for i in range(len(cls.CACHE_FACTORIALS), int(v) + 1):
            cls.CACHE_FACTORIALS.append(cls.CACHE_FACTORIALS[-1] * i % cls.MOD)
        return Mint(cls.CACHE_FACTORIALS[int(v)])

    @classmethod
    def perm(cls, n, r):
        if n < r or r < 0:
            return 0
        return cls.factorial(n) // cls.factorial(n - r)

    @classmethod
    def comb(cls, n, r):
        if n < r or r < 0:
            return 0
        return cls.perm(n, r) // cls.factorial(r)

    @classmethod
    def __isally(cls, v) -> bool:
        return isinstance(v, cls)

    @classmethod
    def __minv(cls, v) -> int:
        return pow(v, cls.MOD - 2, cls.MOD)

    @classmethod
    def __mpow(cls, v, w) -> int:
        return pow(v, w, cls.MOD)

    def __str__(self):
        return str(self.v)
    __repr__ = __str__

    def __int__(self):
        return self.v

    def __eq__(self, w):
        return self.v == w.v if self.__isally(w) else self.v == w

    def __add__(self, w):
        return Mint(self.v + w.v) if self.__isally(w) else Mint(self.v + w)
    __radd__ = __add__

    def __sub__(self, w):
        return Mint(self.v - w.v) if self.__isally(w) else Mint(self.v - w)

    def __rsub__(self, u):
        return Mint(u.v - self.v) if self.__isally(u) else Mint(u - self.v)

    def __mul__(self, w):
        return Mint(self.v * w.v) if self.__isally(w) else Mint(self.v * w)
    __rmul__ = __mul__

    def __floordiv__(self, w):
        return Mint(self.v * self.__minv(w.v)) if self.__isally(w) else \
            Mint(self.v * self.__minv(w))

    def __rfloordiv__(self, u):
        return Mint(u.v * self.__minv(self.v)) if self.__isally(u) else \
            Mint(u * self.__minv(self.v))

    def __pow__(self, w):
        return Mint(self.__mpow(self.v, w.v)) if self.__isally(w) else \
            Mint(self.__mpow(self.v, w))

    def __rpow__(self, u):
        return Mint(self.__mpow(u.v, self.v)) if self.__isally(u) else \
            Mint(self.__mpow(u, self.v))


N = int(input())
A = [int(s) for s in input().split()]
v = Counter(A).most_common(1)[0][0]
i = A.index(v)
j = A.index(v, i+1)
m = j - i - 1
for k in range(1, N + 2):
    ans = Mint.comb(N + 1, k) - Mint.comb(N - m - 1, k - 1)
    print(ans)

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter


class Mint:
    MOD = 1000000007  # Must be a prime
    CACHE_FACTORIALS = [1, 1]

    def __init__(self, v):
        if self.__isally(v):
            self.v = v.v % self.MOD
        else:
            self.v = v % self.MOD

    @property
    def inv(self):
        return Mint(self.__minv(self.v))

    @classmethod
    def factorial(cls, v):
        for i in range(len(cls.CACHE_FACTORIALS), int(v) + 1):
            cls.CACHE_FACTORIALS.append(cls.CACHE_FACTORIALS[-1] * i % cls.MOD)
        return Mint(cls.CACHE_FACTORIALS[int(v)])

    @classmethod
    def perm(cls, n, r):
        if n < r or r < 0:
            return 0
        return cls.factorial(n) // cls.factorial(n - r)

    @classmethod
    def comb(cls, n, r):
        if n < r or r < 0:
            return 0
        return cls.perm(n, r) // cls.factorial(r)

    @classmethod
    def __isally(cls, v) -> bool:
        return isinstance(v, cls)

    @classmethod
    def __minv(cls, v) -> int:
        return pow(v, cls.MOD - 2, cls.MOD)

    @classmethod
    def __mpow(cls, v, w) -> int:
        return pow(v, w, cls.MOD)

    def __str__(self):
        return str(self.v)
    __repr__ = __str__

    def __int__(self):
        return self.v

    def __eq__(self, w):
        return self.v == w.v if self.__isally(w) else self.v == w

    def __add__(self, w):
        return Mint(self.v + w.v) if self.__isally(w) else Mint(self.v + w)
    __radd__ = __add__

    def __sub__(self, w):
        return Mint(self.v - w.v) if self.__isally(w) else Mint(self.v - w)

    def __rsub__(self, u):
        return Mint(u.v - self.v) if self.__isally(u) else Mint(u - self.v)

    def __mul__(self, w):
        return Mint(self.v * w.v) if self.__isally(w) else Mint(self.v * w)
    __rmul__ = __mul__

    def __floordiv__(self, w):
        return Mint(self.v * self.__minv(w.v)) if self.__isally(w) else \
            Mint(self.v * self.__minv(w))

    def __rfloordiv__(self, u):
        return Mint(u.v * self.__minv(self.v)) if self.__isally(u) else \
            Mint(u * self.__minv(self.v))

    def __pow__(self, w):
        return Mint(self.__mpow(self.v, w.v)) if self.__isally(w) else \
            Mint(self.__mpow(self.v, w))

    def __rpow__(self, u):
        return Mint(self.__mpow(u.v, self.v)) if self.__isally(u) else \
            Mint(self.__mpow(u, self.v))


N = int(input())
A = [int(s) for s in input().split()]
v = Counter(A).most_common(1)[0][0]
i = A.index(v)
j = A.index(v, i+1)
l = i
m = j - i - 1
n = N - j
for k in range(1, N + 2):
    ans = Mint.comb(l + m + n, k) + Mint.comb(l + m + n, k - 1) * \
        2 - Mint.comb(l + n, k - 1) + Mint.comb(l + m + n, k - 2)
    print(ans)

Submission status: Time Limit Exceeded

Solution code:
#!/usr/bin/env python3
import sys
from collections import Counter
INF = float("inf")

MOD = 1000000007  # type: int


def cmb(n, r):
    r = min(r, n-r)
    if r < 0 or r > n:
        return 0
    if r == 0:
        return 1
    if r == 1:
        return n

    numer = [n - r + k + 1 for k in range(r)]
    denom = [k + 1 for k in range(r)]

    for p in range(2, r+1):
        pivot = denom[p - 1]
        if pivot > 1:
            offset = (n - r) % p
            for k in range(p-1, r, p):
                numer[k - offset] /= pivot
                denom[k] /= pivot

    result = 1
    for k in range(r):
        if numer[k] > 1:
            result *= int(numer[k])

    return result


def solve(n: int, a: "List[int]"):
    (m, _), = Counter(a).most_common(1)
    left = a.index(m)
    right = a.index(m, left+1)
    for i in range(1, n+2):
        print((cmb(n+1, i)-cmb(n-right+left, i-1)) % MOD)
    return


def main():

    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    n = int(next(tokens))  # type: int
    a = [int(next(tokens)) for _ in range(n+1)]  # type: "List[int]"
    solve(n, a)


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
import itertools

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

for i in range(1,n+2):
    print(len(set(itertools.combinations(li,i)))%1000000007)

Submission status: Time Limit Exceeded

Solution code:
import sys
input = sys.stdin.readline
N, mod = 10**5+1, 10**9+7
fac = [1, 1] + [None] * N
inv = [0, 1] + [None] * N
facInv = [1, 1] + [None] * N
for i in range(2, N+1):
    fac[i] = i * fac[i-1] % mod
    inv[i] = mod-(inv[mod%i]*(mod//i))%mod
    facInv[i] = facInv[i-1]*inv[i]%mod
def modCom(n, k):
    return 0 if n < k else fac[n] * facInv[k] * facInv[n-k] % mod
n = int(input())
a = list(map(int, input().split()))
for x in range(1, n+1):
    if a.count(x) == 2: break
fi = a.index(x) + 1
si = a[fi:].index(x) + fi + 1
print(n)
for k in range(2, n+1):
    print((modCom(n+1, k) - modCom(fi+n-si, k-1)) % mod)
print(1)

Submission status: Time Limit Exceeded

Solution code:
import sys
input = sys.stdin.readline
N, mod = 10**5+2, 10**9+7
def extGcd(a, b):
    if b == 0:
        return a, 1, 0
    else:
        d, x, y = extGcd(b, a % b)
        x -= (a // b) * y
        return d, y, x
def modInv(a):
    return extGcd(a, mod)[1] % mod
fac = [1] + [None] * N
for i in range(1, N+1):
    fac[i] = i * fac[i-1] % mod
facInv = [1] + [None] * N
for i in range(1, N+1):
    facInv[i] = modInv(fac[i])
def modCom(n, k):
    return 0 if n < k else fac[n] * pow(fac[k],mod-2,mod) * pow(fac[n-k],mod-2,mod) % mod
n = int(input())
a = list(map(int, input().split()))
for x in range(1, n+1):
    if a.count(x) == 2: break
fi = a.index(x) + 1
si = a[fi:].index(x) + fi + 1
print(n)
for k in range(2, n+1):
    print((modCom(n+1, k) - modCom(fi+n-si, k-1)) % mod)
print(1)

Submission status: Time Limit Exceeded

Solution code:
import sys
input = sys.stdin.readline
N, mod = 10**5+2, 10**9+7
fac = [1] + [None] * N
for i in range(1, N+1):
    fac[i] = i * fac[i-1] % mod
def modCom(n, k):
    return 0 if n < k else fac[n] * pow(fac[k],mod-2,mod) * pow(fac[n-k],mod-2,mod) % mod
n = int(input())
a = list(map(int, input().split()))
for x in range(1, n+1):
    if a.count(x) == 2: break
fi = a.index(x) + 1
si = a[fi:].index(x) + fi + 1
print(n)
for k in range(2, n+1):
    print((modCom(n+1, k) - modCom(fi+n-si, k-1)) % mod)
print(1)

Submission status: Time Limit Exceeded

Solution code:
N, mod = 10**5+2, 10**9+7
fac = [1] + [None] * N
for i in range(1, N+1):
    fac[i] = i * fac[i-1] % mod
facInv = [1] + [None] * N
for i in range(1, N+1):
    facInv[i] = pow(fac[i], mod-2, mod)

def modCom(n, k):
    if n < k: return 0
    return fac[n] * facInv[k] * facInv[n-k] % mod

n = int(input())
a = list(map(int, input().split()))
for x in range(1, n+1):
    if a.count(x) == 2: break
fi, si = [i+1 for i in range(n+1) if a[i] == x]
print(n)
for k in range(2, n+1):
    print(modCom(n+1, k) - modCom(fi+n-si, k-1))
print(1)

Submission status: Time Limit Exceeded

Solution code:
def cmb(n, r):
    if r > n: return 0
    if n - r < r: r = n - r
    if r == 0: return 1
    if r == 1: return n

    numerator = [n - r + k + 1 for k in range(r)]
    denominator = [k + 1 for k in range(r)]

    for p in range(2,r+1):
        pivot = denominator[p - 1]
        if pivot > 1:
            offset = (n - r) % p
            for k in range(p-1,r,p):
                numerator[k - offset] /= pivot
                denominator[k] /= pivot

    result = 1
    for k in range(r):
        if numerator[k] > 1:
            result *= int(numerator[k])

    return result

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

mod = 10**9 + 7

DB = [x for x in range(1, N+1) if A.count(x) > 1]
ind = [i for i, x in enumerate(A) if x == DB[0]]
a = ind[0]
b = N - ind[1]
for i in range(1, N+2):
    ans = cmb(N+1, i)
    dif = 0
    for j in range(i):
         dif += cmb(a, j)*cmb(b, i-j-1)

         if a + b + 1 < i:
             break
    print((ans - dif) % mod)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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)
    for i in range(c):
        ret //= (c-i)
    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)