Problem p03674 (python)

Fixed submission:
class combination():
    #素数のmod取るときのみ　速い
    def __init__(self, n, mod):
        self.n = n
        self.fac = [1] * (n + 1)
        self.inv = [1] * (n + 1)
        for j in range(1, n + 1):
            self.fac[j] = self.fac[j - 1] * j % mod

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

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

def examD(mod):
    N = I()
    a = LI()
    c = Counter(a)
    db = c.most_common()[0][0]
    curL = a.index(db)
    curR = a.index(db, curL + 1)
    L = curL; M = curR-curL-1;  R = N - curR
#    print(curL,curR)
#    print(L,M,R)
    C = combination(N+1,mod)
    ans = []
    ans.append(N)
    for i in range(2,N+2):
        cur = C.comb(N+1,i,mod)
        if N-1-M-(i-1)>=0:
            cur -= C.comb(N-1-M,i-1,mod)
        if cur<0:
            cur += mod
        ans.append(cur)
    for v in ans:
        print(v)

import sys
import copy
import bisect
import heapq
from collections import Counter,defaultdict,deque
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def S(): return sys.stdin.readline().strip()
mod = 10**9 + 7
inf = float('inf')

examD(mod)

Buggy submission (verdict: Runtime Error):
class combination2():
    def __init__(self, n, mo=10 ** 9 + 7):
        self.fac = [0] * (n + 1)
        self.inv = [1] * (n + 1)
        self.fac[0] = 1
        self.fact(n,mo)
        for i in range(2, n + 1):
            self.inv[n] *= i
            self.inv[n] %= mo
        self.inv[n] = pow(self.inv[n], mo - 2, mo)
        for i in range(1, n):
            self.inv[n - i] = self.inv[n - i + 1] * (n - i + 1) % mo
        return

    def fact(self, n, mo):
        if self.fac[n] != 0:
            return self.fac[n]
        self.fac[n] = n * self.fact(n - 1,mo) % mo
        return self.fac[n]

    def invf(self, n):
        return self.inv[n]

    def comb(self, x, y, mo):
        if y < 0 or y > x:
            return 0
        return self.fac[x] * self.inv[x - y] * self.inv[y] % mo

def examD(mod):
    N = I()
    a = LI()
    double = []
    for s in a:
        if s in double:
            cur = s
            break
        double.append(s)
    curL = a.index(cur); curR = a[curL+1:].index(cur) + (curL+1)
    L = curL; M = curR-curL-1;  R = N - curR
#    print(curL,curR)
#    print(L,M,R)
    C = combination2(N+1,mod)
    ans = []
    ans.append(N)
    for i in range(2,N+2):
        cur = C.comb(N+1,i,mod)
        if N-1-M-(i-1)>=0:
            cur -= C.comb(N-1-M,i-1,mod)
        if cur<0:
            cur += mod
        ans.append(cur)
    for v in ans:
        print(v)

import sys
import copy
import bisect
import heapq
from collections import Counter,defaultdict,deque
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def S(): return sys.stdin.readline().strip()
mod = 10**9 + 7
inf = float('inf')

examD(mod)