Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
n, m = map(int, input().split())

l = list()
la = list()
ln = list()
for i in range(m):
    a, b = map(int, input().split())
    l.append([a, b])
    if 1 in [a, b]:
        la.append(a*b)
    if n in [a, b]:
        if a == n:
            ln.append(b)
        else:
            ln.append(a)

for i in la:
    if i in ln:
        print("POSSIBLE")
        exit()

print("IMPOSSIBLE")

Fixed submission:
n, m = map(int, input().split())

l = list()
la = [0] * (n+1)
ln = [0] * (n+1)

for i in range(m):
    a, b = map(int, input().split())
    if a == 1:
        la[b] = 1
    elif b == 1:
        la[a] = 1
    if a == n:
        ln[b] = 1
    elif b == n:
        ln[a] = 1

for i in range(n+1):
    if la[i]*ln[i] == 1:
        print("POSSIBLE") 
        exit()

print("IMPOSSIBLE")

Buggy python submission (verdict: Time Limit Exceeded):
n, m = map(int, input().split())

l = list()
la = list()
ln = list()
for i in range(m):
    a, b = map(int, input().split())
    l.append([a, b])
    if 1 in [a, b]:
        la.append(a*b)
    if n in [a, b]:
        if a == n:
            ln.append(b)
        else:
            ln.append(a)

for i in ln:
    if i in la:
        print("POSSIBLE")
        exit()

print("IMPOSSIBLE")

Fixed submission:
n, m = map(int, input().split())

l = list()
la = [0] * (n+1)
ln = [0] * (n+1)

for i in range(m):
    a, b = map(int, input().split())
    if a == 1:
        la[b] = 1
    elif b == 1:
        la[a] = 1
    if a == n:
        ln[b] = 1
    elif b == n:
        ln[a] = 1

for i in range(n+1):
    if la[i]*ln[i] == 1:
        print("POSSIBLE") 
        exit()

print("IMPOSSIBLE")

Buggy python submission (verdict: Time Limit Exceeded):
def LIST():
    return list(map(int, input().split()))

n, m = map(int, input().split())

l = list()
la = list()
ln = list()
for i in range(m):
    a, b = map(int, input().split())
    l.append([a, b])
    if 1 in [a, b]:
        la.append(a*b)
    if n in [a, b]:
        ln.append(a*b/n)

for i in la:
    if i in ln:
        print("POSSIBLE")
        exit()

print("IMPOSSIBLE")

Fixed submission:
n, m = map(int, input().split())

l = list()
la = [0] * (n+1)
ln = [0] * (n+1)

for i in range(m):
    a, b = map(int, input().split())
    if a == 1:
        la[b] = 1
    elif b == 1:
        la[a] = 1
    if a == n:
        ln[b] = 1
    elif b == n:
        ln[a] = 1

for i in range(n+1):
    if la[i]*ln[i] == 1:
        print("POSSIBLE") 
        exit()

print("IMPOSSIBLE")
Buggy python submission (verdict: Time Limit Exceeded):
import itertools

N = int(input())

l = list()
for i in range(N):
    l.append(int(input()))

lsum = list()

for i in range(N+1):
    lc = list(itertools.combinations(l, i))
    lsum.extend(list(map(sum, lc)))

lsum = sorted(lsum, reverse=True)


for i in range(len(lsum)):
    if lsum[i] % 10 != 0:
        print(lsum[i])
        break
    elif lsum[i] == 0:
        print(0)
        break

Fixed submission:
import itertools

N = int(input())

l = list()
lm = list()
for i in range(N):
    x = int(input())
    l.append(x)
    if x % 10 != 0:
        lm.append(x)

lm = sorted(lm)

a = sum(l)
if a % 10 == 0:
    if lm == []:
        print(0)
    else:
        print(a - lm[0])
else:
    print(a)
Buggy python submission (verdict: Time Limit Exceeded):
n,m = map(int, input().split())

if n > (m+n)/3:
    print((m)//2)
    exit()

while n <= (n+m)/3:
    n += 1
    m -= 2

print(n-1)

Fixed submission:
n,m = map(int, input().split())

if n > (m+n)/3:
    print(m//2)
    exit()
if m > 10000000000:
    print(m//4)
    exit()

while n <= (n+m)/3:
    n += 1
    m -= 2

print(n-1)
Buggy python submission (verdict: Runtime Error):
W, H, N = map(int, input().split())
w = 0
h = 0
lx = list()
ly = list()
la = list()
for i in range(1, N+1):
    X, Y, A = map(int, input().split())
    lx.append(X)
    ly.append(Y)
    la.append(A)
    if A == 1 and w < X:
        w = X
    elif A == 2 and X < W:
        W = X
    elif A == 3 and h < Y:
        h = Y
    elif A == 4 and Y < H:
        H = Y
S = (W - w)*(H - h)
if S < 0:
    S = 0
print(S)

Fixed submission:
a, b, c = map(int, input().split())
if a+b == c or b+c == a or c+a == b:
    print("Yes")
else:
    print("No")
Buggy python submission (verdict: Runtime Error):
ls = list()
lt = list()
la = list()
LS = list()
LT = list()
LA = list()
N = int(input())
for i in range(1, N+1):
    T, A = map(int, input().split())
    X = T + A
    ls.append(X)
    lt.append(T)
    la.append(A)
    LS.append(X)
    LT.append(T)
    LA.append(A)
print(lt, la, LT, LA)
for j in range(1, N):
    while ls[j] < ls[j-1]:
        ls[j] += LS[j]
    while lt[j] < lt[j-1] or la[j] < la[j-1]:
        lt[j] += LT[j]
        la[j] += LA[j]
    print(lt[j], la[j], LT[j], LA[j])
print(lt[N-1] + la[N-1])

Fixed submission:
a, b, c = map(int, input().split())
d = a - b
e = b - c
f = c - a
if d != 0 and e != 0 and f != 0:
    print(3)
elif d == 0 and e != 0 and f != 0:
    print(2)
elif d != 0 and e == 0 and f != 0:
    print(2)
elif d != 0 and e != 0 and f == 0:
    print(2)
elif d == 0 and e == 0 and f == 0:
    print(1)
Buggy python submission (verdict: Runtime Error):
sa = str(input()) + "d"
sb = str(input()) + "d"
sc = str(input()) + "d"
s = sa
sa = sa[1:]
while s != "d":
	x = s[0]
	if x == "a":
		sa = sa[1:]
		s = sa
	elif x == "b":
		sb = sb[1:]
		s = sb
	elif x == "c":
		sc = sc[1:]
		s = sc
if sa == "d":
	print("A")
elif sb == "d":
	print("B")
elif sc == "d":
	print("C")


Fixed submission:
s = {i: list(input()) for i in "abc"}
x = "a"
while s[x]:
    x = s[x].pop(0)
print(x.upper())
Buggy python submission (verdict: Runtime Error):
a, b, c = map(int, input().split())
if a == 5 and b == 5 and C == 7:
    print("YES")
elif a == 5 and b == 7 and C == 5:
    print("YES")
elif a == 7 and b == 5 and c == 5:
    print("YES")
else:
    print("NO")

Fixed submission:
a, b, c = map(int, input().split())
if a == 5 and b == 5 and c == 7:
    print("YES")
elif a == 5 and b == 7 and c == 5:
    print("YES")
elif a == 7 and b == 5 and c == 5:
    print("YES")
else:
    print("NO")
Buggy python submission (verdict: Runtime Error):
N, M, Q = map(int, input().split())
abcd = [list(map(int, input().split())) for _ in range(Q)]

q = []
def dp(arg):
    global N
    if len(arg) == N:
        q.append(arg)
    else:
        tmp = 0 if len(arg) == 0 else arg[-1]
        for i in range(arg[-1], M + 1):
            dp(arg + [i])

dp([])

ans = 0
for A_tmp in q:
    ans_tmp = 0
    for j, (aj, bj, cj, dj) in enumerate(abcd):
        if A_tmp[bj - 1] - A_tmp[aj - 1] == cj:
            ans_tmp += dj
    #
    ans = max(ans, ans_tmp)

print(ans)

Fixed submission:
N, M, Q = map(int, input().split())
abcd = [list(map(int, input().split())) for _ in range(Q)]

As = []
q = [[]]
while len(q) > 0:
    arg = q.pop()
    if len(arg) == N:
        As.append(arg)
    else:
        A_str = 1 if len(arg) == 0 else arg[-1]
        for i in range(A_str, M + 1):
            q.append(arg + [i])

ans = 0
for A in As:
    ans_tmp = 0
    for j, (aj, bj, cj, dj) in enumerate(abcd):
        if A[bj - 1] - A[aj - 1] == cj:
            ans_tmp += dj
    #
    ans = max(ans, ans_tmp)

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
H, W, K = map(int, input().split())
S = [list(map(int, input())) for _ in range(H)]

sum_tab = [[0] for _ in range(H)]
for i in range(H):
    sum_tmp = 0
    for j in range(W):
        sum_tmp += S[i][j]
        sum_tab[i].append(sum_tmp)

ans = 1000000007
for case in range(1 << (H - 1)):
    t = 0
    divs = []
    case_tmp = case
    for i in range(1, H):
        if case_tmp % 2 > 0:
            divs.append((t, i))
            t = i
        case_tmp >>= 1
    else:
        divs.append((t, H))
    #
    # print("#", divs)
    ans_tmp = len(divs) - 1
    l = 0
    for x in range(W):
        cnt_max = 0
        for y_str, y_end in divs:
            cnt_tmp = sum([sum_tab[y][x + 1] - sum_tab[y][l] for y in range(y_str, y_end)])
            cnt_max = max(cnt_tmp, cnt_max)
        #
        if cnt_max > K:
            ans_tmp += 1
            # print("##", cnt_max, x)
            l = x
    #
    ans = min(ans, ans_tmp)

print(ans)

Fixed submission:
H, W, K = map(int, input().split())
S = [list(map(int, list(input()))) for _ in range(H)]

tab_h = [[0] * (W + 1) for _ in range(H)]
for i in range(H):
    cnt = 0
    for j in range(W):
        cnt += S[i][j]
        tab_h[i][j + 1] = cnt

# tab_v = [[0] * (H + 1) for _ in range(W)]
# for j in range(W):
#     cnt = 0
#     for i in range(H):
#         cnt += S[i][j]
#         tab_v[i + 1][j] = cnt

ans = 1000000007
for case in range(2 ** (H - 1)):
    case_tmp = case
    iscut_v = []
    for i in range(H - 1):
        iscut_v.append(case_tmp % 2)
        case_tmp >>= 1
    #
    parts = []
    vsrc = 0
    for vdst in range(1, H + 1):
        if vdst == H:
            parts.append((vsrc, vdst))
            break
        elif iscut_v[vdst - 1] == 1:
            parts.append((vsrc, vdst))
            vsrc = vdst
        else:
            continue
    #
    possible = False
    hsrc = 0
    iscut_h = [0] * (W - 1)
    for hdst in range(1,  W + 1):
        num_1 = 0
        for vsrc, vdst in parts:
            num_1_tmp = 0
            for i in range(vsrc, vdst):
                num_1_tmp += tab_h[i][hdst] - tab_h[i][hsrc]
            num_1 = max(num_1, num_1_tmp)
            # print("##", hdst, (vsrc, vdst), num_1_tmp)
        #
        if num_1 > K:
            if hdst == 1 or hdst - 1 == hsrc:
                break
            else:
                iscut_h[hdst - 2] = 1
                hsrc = hdst - 1
        else:
            continue
    else:
        possible = True
    #
    if possible:
        ans_tmp = sum(iscut_v) + sum(iscut_h)
        # print("#", iscut_v, iscut_h, ans_tmp)
        ans = min(ans, ans_tmp)

print(ans)
Buggy python submission (verdict: Runtime Error):
A, B, M = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
xyc = [list(map(int, input().split())) for _ in range(M)]

ans = min(a) + min(b)
for i, (xi, yi, ci) in enumerate(xyc):
    ans = min(ans, a[xi - 1] + a[yi - 1] - ci)

print(ans)

Fixed submission:
A, B, M = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
xyc = [list(map(int, input().split())) for _ in range(M)]

ans = min(a) + min(b)
for i, (xi, yi, ci) in enumerate(xyc):
    ans = min(ans, max(0, a[xi - 1] + b[yi - 1] - ci))

print(ans)
Buggy python submission (verdict: Runtime Error):
A = list(map(int, input().split()))

A.sort()
sumtab = [0] * (N + 1)
tmp_tab = 0
for i, Ai in enumerate(A):
    tmp_tab += Ai
    sumtab[i + 1] = tmp_tab

l = 0
r = N
while True:
    i = l + (r - l) // 2
    # print("#", l, r, i)
    #
    B = list(A)
    # everyone vote: i
    score_i = A[i] + M
    B[i] += M
    M_tmp = M * (V - 1)
    #
    rslt = False
    # print("#", i, B)
    for j in list(range(N))[::-1]:
        # print("##", j, M_tmp, B)
        if j == i:
            continue # me
        elif j > N - P:
            # make stronger problems stronger as possible
            tmp = min(M, M_tmp)
            #
            M_tmp -= tmp
            B[j] += tmp
        else:
            # make weaker problems weaker as possible
            if A[j] + M <= score_i:
                tmp = min(M, M_tmp)
            else:
                tmp = min(score_i - A[j], M_tmp)
            #
            M_tmp -= tmp
            B[j] += tmp
        #
        if M_tmp <= 0: break
    #
    # print("##", 'e', M_tmp, B)
    if M_tmp <= 0 and score_i >= B[N - P]:
        r = i
    else:
        l = i + 1
    #
    if l >= r: break
        
print(N - l)

Fixed submission:
N, M, V, P = map(int, input().split())
A = list(map(int, input().split()))

A.sort()
sumtab = [0] * (N + 1)
tmp_tab = 0
for i, Ai in enumerate(A):
    tmp_tab += Ai
    sumtab[i + 1] = tmp_tab

l = 0
r = N
while True:
    i = l + (r - l) // 2
    # print("#", l, r, i)
    #
    B = list(A)
    # everyone vote: i
    score_i = A[i] + M
    B[i] += M
    M_tmp = M * (V - 1)
    #
    rslt = False
    # print("#", i, B)
    for j in list(range(N))[::-1]:
        # print("##", j, M_tmp, B)
        if j == i:
            continue # me
        elif j > N - P:
            # make stronger problems stronger as possible
            tmp = min(M, M_tmp)
            #
            M_tmp -= tmp
            B[j] += tmp
        else:
            # make weaker problems weaker as possible
            if A[j] > score_i:
                break
            if A[j] + M <= score_i:
                tmp = min(M, M_tmp)
            else:
                tmp = min(score_i - A[j], M_tmp)
            #
            M_tmp -= tmp
            B[j] += tmp
        #
        if M_tmp <= 0: break
    #
    # print("##", 'e', M_tmp, B)
    if i >= N - P:
        r = i
    elif M_tmp <= 0 and score_i >= B[N - P]:
        r = i
    else:
        l = i + 1
    #
    if l >= r: break
        
print(N - l)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())

ab = [list(map(int, input().split())) for _ in range(N - 1)]

graph = [[] for _ in range(N)]

for ai, bi in ab:
    graph[ai - 1].append(bi - 1)
    graph[bi - 1].append(ai - 1)

from collections import deque

ans = []
col_max = 1
q = deque([(0, -1, 0)])
while len(q) > 0:
    col = 1
    src, prev, col_prev = q.popleft()
    # print("#", src)
    for dst in graph[src]:
        if dst == prev: continue
        #
        if col == col_prev: col += 1
        # print("##", dst)
        # ans[src][dst] = col
        ans.append((dst, src, col))
        q.append((dst, src, col))
        col_max = max(col, col_max)
        col += 1
        
ans.sort(key=lambda x: x[0] * N + x[1])
        
print(col_max)
for ai, bi in ab:
    l = 0
    r = N - 2
    # print("#", ai, bi)
    while l < r:
        m = l + (r - l + 1) // 2
        tmp = ans[m][0] * N + ans[m][1]
        # print("#", (l, r), m, tmp)
        if tmp <= (bi - 1) * N + (ai - 1):
            l = m
        else:
            r = m - 1
    #
    # print("#", l, ans)
    print(ans[l][2])

Fixed submission:
N = int(input())

ab = [list(map(int, input().split())) for _ in range(N - 1)]

graph = [[] for _ in range(N)]

for ai, bi in ab:
    graph[ai - 1].append(bi - 1)
    graph[bi - 1].append(ai - 1)

from collections import deque

ans = []
col_max = 1
q = deque([(0, -1, 0)])
while len(q) > 0:
    col = 1
    src, prev, col_prev = q.popleft()
    # print("#", src)
    for dst in graph[src]:
        if dst == prev: continue
        #
        if col == col_prev: col += 1
        # print("##", dst)
        # ans[src][dst] = col
        ans.append((dst, src, col))
        q.append((dst, src, col))
        col_max = max(col, col_max)
        col += 1
        
ans.sort(key=lambda x: x[0] * N + x[1])
        
print(col_max)
for ai, bi in ab:
    l = 0
    r = N - 2
    # print("#", ai, bi)
    while l < r:
        m = l + (r - l + 1) // 2
        tmp = ans[m][0] * N + ans[m][1]
        # print("#", (l, r), m, tmp)
        if tmp <= (bi - 1) * N + (ai - 1):
            l = m
        else:
            r = m - 1
    #
    # print("#", l, ans)
    print(ans[l][2])
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
S = [list(map(int, list(input()))) for _ in range(N)]

graph = [[] for _ in range(N)]
for i in range(N):
    for j in range(N):
        if S[i][j] == 1: graph[i].append(j)

from collections import deque

ans_tmp = 0
possible = True
for home in range(N):
    iswhite = [None] * N
    q = deque([(home, False, 0)])
    while len(q) > 0:
        src, white, depth = q.popleft()
        # print("##", src, white, depth)
        iswhite[src] = white
        ans_tmp = max(ans_tmp, depth)
        for dst in graph[src]:
            # print("###", dst, iswhite[dst])
            if iswhite[dst] == None:
                q.append((dst, (white != True), depth + 1))
            elif white == iswhite[dst]:
                possible = False
                break
            else:
                continue
        #
        if possible == False:
            break
    
if possible:
    print(ans_tmp + 1)
else:
    # print("#", iswhite)
    print(-1)

Fixed submission:
N = int(input())
S = [list(map(int, list(input()))) for _ in range(N)]

graph = [[] for _ in range(N)]
for i in range(N):
    for j in range(N):
        if S[i][j] == 1: graph[i].append(j)

from collections import deque

ans_tmp = 0
possible = True
for home in range(N):
    iswhite = [None] * N
    q = deque([(home, False, 0)])
    iswhite[home] = False
    while len(q) > 0:
        src, white, depth = q.popleft()
        # print("##", src, white, depth)
        if depth > ans_tmp:
            # home = src
            ans_tmp = depth
        #
        for dst in graph[src]:
            # print("###", dst, iswhite[dst])
            if iswhite[dst] == None:
                white_dst = (white != True)
                q.append((dst, white_dst, depth + 1))
                iswhite[dst] = white_dst
            elif white == iswhite[dst]:
                possible = False
                break
            else:
                continue
        #
        if possible == False:
            break
    
if possible:
    print(ans_tmp + 1)
else:
    # print("#", iswhite)
    print(-1)
Buggy python submission (verdict: Time Limit Exceeded):
A, B = map(int, input().split())

def mygcd(a, b):
    if a < b:
        return mygcd(b, a)
    elif b == 0:
        return a
    else:
        return mygcd(b, a % b)

gcd = mygcd(A, B)

pfac = {}
gcd_tmp = gcd
for p in range(2, gcd + 1):
    if gcd_tmp < 2: break
    if gcd_tmp % p == 0:
        i_p = 0
        while gcd_tmp % p == 0:
            gcd_tmp //= p
            i_p += 1
        #
        pfac[str(p)] = i_p

# print("#", pfac)
        
print(1 + len(pfac))

Fixed submission:
A, B = map(int, input().split())

def mygcd(a, b):
    if a < b:
        return mygcd(b, a)
    elif b == 0:
        return a
    else:
        return mygcd(b, a % b)

gcd = mygcd(A, B)

import math

pfac = {}
gcd_tmp = gcd
for p in range(2, int(math.sqrt(gcd)) + 1):
    if gcd_tmp < 2: break
    if gcd_tmp % p == 0:
        i_p = 0
        while gcd_tmp % p == 0:
            gcd_tmp //= p
            i_p += 1
        #
        pfac[str(p)] = i_p
else:
    if gcd_tmp > 1: pfac[str(gcd_tmp)] = 1
    
# print("#", pfac)
        
print(1 + len(pfac))

Buggy python submission (verdict: Time Limit Exceeded):
A, B = map(int, input().split())

def mygcd(a, b):
    if a < b:
        return mygcd(b, a)
    elif b == 0:
        return a
    else:
        return mygcd(b, a % b)

gcd = mygcd(A, B)

pfac = {}
gcd_tmp = gcd
for p in range(2, gcd + 1):
    if gcd_tmp % p == 0:
        i_p = 0
        while gcd_tmp % p == 0:
            gcd_tmp //= p
            i_p += 1
        #
        pfac[str(p)] = i_p

# print("#", pfac)
        
print(1 + len(pfac))

Fixed submission:
A, B = map(int, input().split())

def mygcd(a, b):
    if a < b:
        return mygcd(b, a)
    elif b == 0:
        return a
    else:
        return mygcd(b, a % b)

gcd = mygcd(A, B)

import math

pfac = {}
gcd_tmp = gcd
for p in range(2, int(math.sqrt(gcd)) + 1):
    if gcd_tmp < 2: break
    if gcd_tmp % p == 0:
        i_p = 0
        while gcd_tmp % p == 0:
            gcd_tmp //= p
            i_p += 1
        #
        pfac[str(p)] = i_p
else:
    if gcd_tmp > 1: pfac[str(gcd_tmp)] = 1
    
# print("#", pfac)
        
print(1 + len(pfac))
Buggy python submission (verdict: Runtime Error):
2
100 1 1
1 100

Fixed submission:
inf = 10 ** 18
P = 10 ** 9 + 7

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

A_all = sum(A)

xi = min(A[0], B[0])
A[0] -= xi
B[0] -= xi
for i in range(N):
    yi = min(B[i], A[i + 1])
    A[1 + i] -= yi
    B[i] -= yi
    #
    if i < N - 1:
        xi = min(A[1 + i], B[1 + i])
        A[1 + i] -= xi
        B[1 + i] -= xi
    #
    # print("#", A, B, A_all - sum(A))
    
A_r = list(reversed(A))
B_r = list(reversed(B))


xi = min(A_r[0], B_r[0])
A_r[0] -= xi
B_r[0] -= xi
for i in range(N):
    yi = min(B_r[i], A_r[i + 1])
    A_r[1 + i] -= yi
    B_r[i] -= yi
    #
    if i < N - 1:
        xi = min(A_r[1 + i], B_r[1 + i])
        A_r[1 + i] -= xi
        B_r[1 + i] -= xi
    #
    # print("#", A, B, A_all - sum(A))

print(A_all - sum(A))
Buggy python submission (verdict: Runtime Error):
# encoding: utf-8
import sys
# input = sys.stdin.readline
P = 10 ** 9 + 7

N, K = map(int, input().split())

# molec = 1
# for i in range(K - 1):
#     molec = (molec * (i + 1)) % P

power = 10 ** 9 + 5
digits = []
for i in range(64):
    digits.append(power % 2)
    power >>= 1

def modinv(b):
    binv = 1
    val = b % P
    for i, digit in enumerate(digits):
        if digit == 1:
            binv = (binv * val) % P
        val = (val * val) % P
    # print("##", b, binv)
    return binv

molec = 1
tab_nck = [1]
for i in range(1, K - 1):
    molec = (molec * (K - i)) % P
    molec = (molec * modinv(i)) % P
    tab_nck.append(molec)
tab_nck.append(1)

molec = 1
tab_nck2 = [1]
for i in range(1, N - K + 1):
    molec = (molec * (N - K + 2 - i)) % P
    molec = (molec * modinv(i)) % P
    tab_nck2.append(molec)
tab_nck2.append(1)

# print("#", tab_nck)
# print("#", tab_nck2)

def nck(a, b):
    # a = K - 1
    return tab_nck[b]

def nck2(a, b):
    # a = N - K + + 1
    return tab_nck2[b]

for i in range(1, K + 1):
    ans = 1
    #
    ans = (ans * nck(K - 1, i - 1)) % P
    # print("#", nck(K - 1, i - 1))
    ans = (ans * nck2(N - K + i - 1, i)) % P
    # print("#", nck2(N - K + i - 1, i))
    #
    print(ans)

Fixed submission:
# encoding: utf-8
import sys
# input = sys.stdin.readline
P = 10 ** 9 + 7

N, K = map(int, input().split())

# molec = 1
# for i in range(K - 1):
#     molec = (molec * (i + 1)) % P

power = 10 ** 9 + 5
digits = []
for i in range(64):
    digits.append(power % 2)
    power >>= 1

def modinv(b):
    binv = 1
    val = b % P
    for i, digit in enumerate(digits):
        if digit == 1:
            binv = (binv * val) % P
        val = (val * val) % P
    # print("##", b, binv)
    return binv

molec = 1
tab_nck = [1]
for i in range(1, K - 1):
    molec = (molec * (K - i)) % P
    molec = (molec * modinv(i)) % P
    tab_nck.append(molec)
tab_nck.append(1)

molec = 1
tab_nck2 = [1]
for i in range(1, N - K + 1):
    molec = (molec * (N - K + 2 - i)) % P
    molec = (molec * modinv(i)) % P
    tab_nck2.append(molec)
tab_nck2.append(1)

# print("#", tab_nck)
# print("#", tab_nck2)

def nck(a, b):
    # a = K - 1
    if b < 0: return 0
    elif b > K - 1: return 0
    else: return tab_nck[b]

def nck2(a, b):
    # a = N - K + 1
    if b < 0: return 0
    elif b > N - K + 1: return 0
    else: return tab_nck2[b]

for i in range(1, K + 1):
    ans = 1
    #
    ans = (ans * nck(K - 1, i - 1)) % P
    ans = (ans * nck2(N - K + i - 1, i)) % P
    #
    print(ans)
Buggy python submission (verdict: Runtime Error):
import sys
# input = sys.stdin.readline

N = int(input())
AB = [list(map(int, input().split())) for _ in range(N)]


ans = 0
ans += B // C
ans -= (A - 1) // C
# print("#", ans)
ans += B // D
ans -= (A - 1) // D
# print("#", ans)
#
ans -= B // (C * D)
ans += (A - 1) // (C * D)
# print("#", ans)

ans = (B - A + 1) - ans
print(ans)

Fixed submission:
import sys
# input = sys.stdin.readline

A, B, C, D = map(int, input().split())

def div(a, b):
    return a // b

def gcd(a, b):
    if b > a: return gcd(b, a)
    elif b == 0: return a
    else: return gcd(b, a % b)

ans = 0
ans += div(B, C)
ans -= div(A - 1, C)
# print("#", ans)
ans += div(B, D)
ans -= div(A - 1, D)
# print("#", ans)
#
E = (C * D) // gcd(C, D)
ans -= div(B, E)
ans += div(A - 1, E)
# print("#", ans)

ans = (B - A + 1) - ans
print(ans)