Problem p03674 (python)

Fixed submission:
from collections import defaultdict

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

Buggy submission (verdict: Runtime Error):
from collections import defaultdict
import sys
sys.setrecursionlimit(100001)
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]

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

Buggy submission (verdict: Runtime Error):
from collections import defaultdict

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]

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

Buggy submission (verdict: Runtime Error):
from collections import defaultdict

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)
    return factMem[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))