Harryxun/GPT-100-sft-dataset huggingface dataset:
Problem p03013 (python)

Fixed submission:
import sys

mod = 10 ** 9 + 7
n, m, *a = [int(x) for x in sys.stdin.read().split()]

safe = sorted(set(range(1,n+1)) - set(a))
dp = [0] * (n + 2)
dp[0] = 0
dp[1] = 1
for i in safe:
    dp[i+1] = (dp[i] + dp[i-1]) % mod

print(dp[-1])

Buggy submission (verdict: Runtime Error):
# 2019-11-14 10:01:24(JST)
import sys
# import collections
# import math
# from string import ascii_lowercase, ascii_uppercase, digits
# from bisect import bisect_left as bi_l, bisect_right as bi_r
# import itertools
from functools import reduce
# import operator as op
# from scipy.misc import comb # float
# import numpy as np 

mod = 10 ** 9 + 7
def main():
    n, m, *broken_treads = [int(x) for x in sys.stdin.read().split()]
    safe = sorted((set(range(1, n+1)) - set(broken_treads)))

    p = [0] * (n + 1) # p[i] は連続するi段の、1~i段目までの登り方の総パターン
    p[1] = 1
    for i in range(2, n+1):
        p[i] = p[i-1] + p[i-2]

    count = 1 # 最初に0th stepを踏んでいるので1
    sections = []
    for i in range(1, n+1):
        if i in safe:
            count += 1
        else:
            if count >= 1:
                sections.append(p[count])
                count = 0
            else: # countが0だったら一つ前も壊れている
                print(0)
                sys.exit()
    
    if count >= 1:    # if the last is not broken.
        sections.append(p[count])

    ans = reduce(lambda x, y: x * y % mod, sections)
    print(ans)

if __name__ == "__main__":
    main()
Problem p03045 (python)

Fixed submission:
import sys

n, m, *xyz = map(int, sys.stdin.read().split())
xyz = zip(*[iter(xyz)] * 3)

root = list(range(n+1))
height = [0] * (n + 1)

sys.setrecursionlimit(10**7)
def find_root(v):
    u = root[v]
    if u == v:
        return u
    w = find_root(u)
    root[v] = w
    return w

def unite(u, v):
    ru = find_root(u)
    rv = find_root(v)
    if ru == rv:
        return
    if height[u] >= height[v]:
        root[rv] = ru
        height[ru] = max(height[ru], height[rv] + 1)
    else:
        root[ru] = rv

def main():
    for x, y, z in xyz:
        unite(x, y)
    
    for i in range(1, n+1):
        find_root(i)

    return len(set(root[1:]))

if __name__ == '__main__':
    ans = main()
    print(ans)

Buggy submission (verdict: Runtime Error):
import sys

n, m, *xyz = map(int, sys.stdin.read().split())
xyz = zip(*[iter(xyz)] * 3)

root = list(range(n+1))
height = [0] * (n + 1)

def find_root(v):
    u = root[v]
    if u == v:
        return u
    w = find_root(u)
    root[v] = w
    return w

def unite(u, v):
    ru = find_root(u)
    rv = find_root(v)
    if ru == rv:
        return
    if height[u] >= height[v]:
        root[rv] = ru
        height[ru] = max(height[ru], height[rv] + 1)
    else:
        root[ru] = rv

def main():
    for x, y, z in xyz:
        unite(x, y)
    
    for i in range(1, n+1):
        find_root(i)

    return len(set(root[1:]))

if __name__ == '__main__':
    ans = main()
    print(ans)
Problem p03107 (python)

Fixed submission:
import sys

s = sys.stdin.readline().rstrip()

def main():
    return min(s.count('0'), s.count('1')) * 2

if __name__ == '__main__':
    ans = main()
    print(ans)

Buggy submission (verdict: Runtime Error):
import sys

s = sys.stdin.readline().rstrip()
n = len(s)

def main():
    c = s.cout('0')
    print(min(n-c, c) * 2)

if __name__ ==  '__main__':
    main()
Problem p03221 (python)

Fixed submission:
# 2019-11-11 14:35:02(JST)
import sys
# import collections
import math
# from string import ascii_lowercase, ascii_uppercase, digits
# from bisect import bisect_left as bi_l, bisect_right as bi_r
# import itertools
# from functools import reduce
# import operator as op
# from scipy.misc import comb # float
# import numpy as np 
from copy import deepcopy

def main():
    n, m = (int(x) for x in sys.stdin.readline().split())
    PY = [[int(x) for x in sys.stdin.readline().split()] for _ in range(m)]
    py = sorted(deepcopy(PY))

    ids = dict()
    for i in range(m):
        p, y = py[i][0], py[i][1]
        if not p in ids:
            ids[p] = dict()
            x = 0
        x += 1
        id_i = '0' * (6 - (math.floor(math.log10(p)) + 1)) + str(p) + '0' * (6 - (math.floor(math.log10(x)) + 1)) + str(x)
        ids[p][y] = id_i
    
    for i in range(m):
        p, y = PY[i][0], PY[i][1]
        print(ids[p][y])


if __name__ == "__main__":
    main()

Buggy submission (verdict: Runtime Error):
import sys

def fill(s): return '0' * (6 - len(s)) + s
def create_id(p, o): return fill(str(p)) + fill(str(o))

n, m, *py = map(int, sys.stdin.read().split())
pyi = sorted(zip(*[iter(py)] * 2, range(m)))

def main():
    res = [None] * m
    prev = j = None
    for p, y, i in pyi:
        j = j + 1 if p == prev else 1
        res[i] = create_id(p, j)
        prev = p
    print(*res, sep='\n')
    
if __name__ ==  '__main__':
    main()

Buggy submission (verdict: Runtime Error):
import sys

def fill(s): while len(s) < 6: s = '0' + s; return s
def create_id(p, o): return fill(str(p)) + fill(str(o))

n, m, *py = map(int, sys.stdin.read().split())
pyi = sorted(zip(zip(*[iter(py)] * 2), range(m)))

def main():
    res = [None] * m
    prev = j = None
    for (p, y), i in pyi:
        j = j + 1 if p == prev else 1
        res[i] = create_id(p, j)
        prev = p
    print(*res, sep='\n')
    
if __name__ ==  '__main__':
    main()
Problem p03222 (python)

Fixed submission:
import sys

MOD = 10 ** 9 + 7

h, w, k = map(int, sys.stdin.readline().split())

def main():
    ok = []
    for i in range(2 ** (w - 1)):
        prev = False
        for j in range(w-1):
            if i >> j & 1:
                if prev:
                    break
                else:
                    prev = True
            else:
                prev = False
        else:
            ok.append(i)
        
    res = [0] * w
    res[0] = 1
    for _ in range(h):
        nex = [0] * w
        for i in ok:
            j = 0
            while j < w:
                if i >> j & 1:
                    nex[j] += res[j+1]
                    nex[j+1] += res[j] 
                    j += 2
                else:
                    nex[j] += res[j]
                    j += 1
        for j in range(w):
            nex[j] %= MOD
        res = nex
    
    return res[k-1]
    
if __name__ == '__main__':
    ans = main()
    print(ans)

Buggy submission (verdict: Runtime Error):
import sys

MOD = 10 ** 9 + 7

h, w, k = map(int, sys.stdin.readline().split())

def main():
    ok = []
    for i in range(2 ** (w - 1)):
        prev = False
        for j in range(w-1):
            if i >> j & 1:
                if prev:
                    break
                else:
                    prev = True
            else:
                prev = False
        else:
            ok.append(i)

    lcr = [(letter, 0) for letter in 'lcr']
    a = [dict(lcr) for _ in range(w)]
    for i in ok:
        j = 0
        while j < w:
            if i >> j & 1:
                a[j]['r'] += 1
                a[j+1]['l'] += 1
                j += 2
            else:
                a[j]['c'] += 1
                j += 1

    res = [0] * w
    res[0] = 1
    for _ in range(h):
        nex = [0] * w
        for j in range(w):
            if j == 0:
                nex[j] = res[j] * a[j]['c'] + res[j+1] * a[j]['r']
            elif j < w - 1:
                nex[j] = res[j-1] * a[j]['l'] + res[j] * a[j]['c'] + res[j+1] * a[j]['r']
            else:
                nex[j] = res[j-1] * a[j]['l'] + res[j] * a[j]['c']
        for j in range(w):
            nex[j] %= MOD
        res = nex
        
    return res[k-1]
    
if __name__ == '__main__':
    ans = main()
    print(ans)
Problem p03705 (python)

Fixed submission:
# 2019-11-22 16:25:33(JST)
import sys


def main():
    n, a, b = [int(x) for x in sys.stdin.readline().split()]

    min_possible = a * (n - 1) + b
    max_possible = b * (n - 1) + a

    ans = max_possible - min_possible + 1
    print(max(ans, 0))

if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
# 2019-11-22 16:25:33(JST)
import sys


def main():
    n, a, b = [int(x) for x in sys.stdin.readline().split()]


    if a > b:
        ans = 0
    elif a == b:
        ans = 1
    elif b < a:
        if n == 1:
            ans = 0
        else:
            min_possible = a * (n - 1) + b
            max_possible = b * (n - 1) + a
            ans = max_possible - min_possible + 1
    
    print(ans)

if __name__ == '__main__':
    main()
Problem p03776 (python)

Fixed submission:
from statistics import mean
n, a, b = [int(_) for _ in input().split()]
values = [int(v) for v in input().split()]
values.sort(reverse=True)
maximum_mean = mean(values[:a])
print(maximum_mean)

min_value = values[:a][-1]
accepted = values[:a].count(min_value)
full = values.count(min_value)

# def cmb(n, r):
#     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
nCr = {}
def cmb(n, r):
    if n < r:
        return 0
    if r == 0 or r == n: return 1
    if r == 1: return n
    if (n,r) in nCr: return nCr[(n,r)]
    nCr[(n,r)] = cmb(n-1,r) + cmb(n-1,r-1)
    return nCr[(n,r)]



if min_value == maximum_mean:
    ans = 0
    for r in range(a, b+1):
        ans += cmb(full, r)
else:
    ans = cmb(full, accepted)

print(ans)

Buggy submission (verdict: Runtime Error):
import sys
from bisect import bisect_left as bi_l, bisect_right as bi_r
import scipy.special

def comb(n, r):
    return scipy.special.comb(n, r, exact=True)

n, a, b, *v = map(int, sys.stdin.read().split())

def main():
    v.sort()

    ma = v[n-a:n]
    yield sum(ma) / a

    lo = ma[0]
    hi = ma[-1]

    res = 0
    lo_cnt = bi_r(v, lo) - bi_l(v, lo)
    if lo == hi:
        for c in range(a, min(b, lo_cnt) + 1):
            res += comb(lo_cnt, c)
    else:
        allowed_cnt = bi_r(ma, lo)
        res = comb(lo_cnt, allowed_cnt)
    
    yield res

if __name__ == '__main__':
    ans = main()
    print(*ans, sep='\n')
Problem p03806 (python)

Fixed submission:
import sys

INF = float('inf')

n, ma, mb = map(int, sys.stdin.readline().split())
a, b, c = [], [], []
for _ in range(n):
    ai, bi, ci = map(int, sys.stdin.readline().split())
    a.append(ai); b.append(bi); c.append(ci)

def main():
    sa = sum(a)
    sb = sum(b)
    res = [[[INF] * (sb + 1) for _ in range(sa + 1)] for _ in range(n + 1)]
    res[0][0][0] = 0
    for i in range(n):
        for j in range(sa + 1):
            for k in range(sb + 1):
                if j >= a[i] and k >= b[i]:
                    res[i+1][j][k] = min(res[i][j-a[i]][k-b[i]] + c[i], res[i][j][k])
                else:
                    res[i+1][j][k] = res[i][j][k]
    ans = INF
    for i in range(1, min(sa//ma, sb//mb)+1):
        ans = min(ans, res[n][ma * i][mb * i])
    
    if ans == INF:
        return -1
    else:
        return ans

if __name__ == '__main__':
    ans = main()
    print(ans)

Buggy submission (verdict: Runtime Error):
import sys
import numpy as np
from copy import deepcopy

I = np.array(sys.stdin.read().split(), dtype=np.int64)
n, ma, mb = I[:3]
a, b, c = I[3:].reshape(n, 3).T

def main():
    sa = np.sum(a)
    sb = np.sum(b)

    res = [[[[0, 0] for _ in range(sb+1)] for _ in range(sb + 1)] for _ in range(n+1)]
    res[0][0][0][0] = 1
    for i in range(n):
        res[i+1] = deepcopy(res[i])
        for j in range(sa+1):
            for k in range(sb+1):
                if j >= a[i] and k >= b[i]:
                    prev =  res[i][j-a[i]][k-b[i]]
                    if prev[0]:
                        res[i+1][j][k][0] = 1
                        if res[i+1][j][k][1]:
                            res[i+1][j][k][1] = min(prev[1] + c[i], res[i+1][j][k][1])   
                        else:    
                            res[i+1][j][k][1] = prev[1] + c[i]

    for i in range(1, min(sa//ma, sb//mb)+1):
        x = res[n][ma * i][mb * i]
        if x[0]:
            return x[1]
    return -1

if __name__ == '__main__':
    ans = main()
    print(ans)
Problem p02753 (python)

Fixed submission:
N = input()
if N == "AAA" or N == "BBB":
    print("No")
else:
    print("Yes")

Buggy submission (verdict: Runtime Error):
N,A,B = map(int,input().split())
C = N//(A+B)
D = N%(A+B)
print(C*A+min(D,A))
Problem p02860 (python)

Fixed submission:
import math
N = int(input())
S = input()
if N%2 == 1:
  print("No")
else:
  if S == S[:N//2]+S[:N//2]:
      print("Yes")
  else:
      print("No")

Buggy submission (verdict: Runtime Error):
import math
N = int(input())
S = input()
if N%2 == 1:
  print(No)
else:
  if S == S[:N//2]+S[:N//2]:
      print("Yes")
  else:
      print("No")
Problem p02987 (python)

Fixed submission:
S = input()
if S[0]==S[1]==S[2]==S[3]:
	print("No")
else:
	if S[0] == S [1]:
		if S[2] == S[3]:
			print("Yes")
		else:
			print("No")
	elif S[0] == S[2]:
		if S[1] == S[3]:
			print("Yes")
		else:
			print("No")
	elif S[0] == S[3]:
		if S[1] == S[2]:
			print("Yes")
		else:
			print("No")
	else:
		print("No")

Buggy submission (verdict: Runtime Error):
S = input()
if S[0] == S [1]:
	if S[2] == S[3]:
		print("Yes")
	else:
		print("No")
elif S[0] == S[2]:
	if S[1] == S[3]:
		print("Yes")
	else:
		print("No")
elif S[0] == S[3]:
	if S[1] == S[2]:
		print("Yes")
	else:
		print("No")
else:
Problem p02990 (python)

Fixed submission:
import math
N,K= map(int,input().split())
choose_count = 1
for i in range(K):
	left = K - choose_count
	if left < 0:
		print(0)
		continue
	if N-K+1-choose_count<0:
		print(0)
		continue
	choose = math.factorial(N-K+1)//(math.factorial(choose_count)*math.factorial(N-K+1-choose_count))
	ans = choose*math.factorial(left+choose_count-1)//(math.factorial(left)*math.factorial(choose_count-1))
	print(int(ans)%1000000007)
	choose_count += 1

Buggy submission (verdict: Runtime Error):
import math
N,K= map(int,input().split())
choose_count = 1
for i in range(K):
	left = K - choose_count
	if left < 0:
		break
	choose = math.factorial(N-K+1)//(math.factorial(choose_count)*math.factorial(N-K+1-choose_count))
	if left < 0:
		break
	else:
		ans = choose*math.factorial(left+choose_count-1)//(math.factorial(left)*math.factorial(choose_count-1))
		print(int(ans)%1000000007)
	choose_count += 1

Buggy submission (verdict: Runtime Error):
import math
N,K= map(int,input().split())
choose_count = 1
for i in range(N):
	left = K - choose_count
	if left < 0:
		break
	choose = math.factorial(N-K+1)//(math.factorial(choose_count)*math.factorial(N-K+1-choose_count))
	if left < 0:
		break
	else:
		ans = choose*math.factorial(left+choose_count-1)//(math.factorial(left)*math.factorial(choose_count-1))
		print(int(ans)%1000000007)
	choose_count += 1

Buggy submission (verdict: Runtime Error):
import math
N,K= map(int,input().split())
choose_count = 1
for i in range(N):
	left = K - choose_count
	if left < 0:
		break
	choose = math.factorial(N-K+1)/(math.factorial(choose_count)*math.factorial(N-K+1-choose_count))
	if left < 0:
		break
	else:
		ans = choose*math.factorial(left+choose_count-1)/(math.factorial(left)*math.factorial(choose_count-1))
		print(int(ans)%1000000007)
	choose_count += 1
Problem p03013 (python)

Fixed submission:
N,M = map(int,input().split())
if M != 0:
    chk = int(input())
else :
    chk = 0
ans1 = 1
count = 0
if chk == 1:
    ans2 = 0
    if M != 1:
        chk = int(input())
    count += 1
else:
    ans2 = 1
for i in range(N-1):
    if chk == i+2:
        ans1 = ans2
        ans2 = 0
        count += 1
        if count != M:
            chk = int(input())
    else:
        tempo = ans2
        ans2 = ans1 + ans2
        ans1 = tempo
print(ans2%1000000007)

Buggy submission (verdict: Runtime Error):
N,M = map(int,input().split())
if M != 0:
    chk = int(input())
else :
    chk = 0
ans1 = 1
count = 0
if chk == 1:
    ans2 = 0
    chk = int(input())
    count += 1
else:
    ans2 = 1
for i in range(N-1):
    if chk == i+2:
        ans1 = ans2
        ans2 = 0
        count += 1
        if count != M:
            chk = int(input())
    else:
        tempo = ans2
        ans2 = ans1 + ans2
        ans1 = tempo
print(ans2%1000000007)

Buggy submission (verdict: Runtime Error):
N,M = map(int,input().split())
chk = int(input())
ans1 = 1
count = 0
if chk == 1:
    ans2 = 0
    chk = int(input())
    count += 1
else:
    ans2 = 1
for i in range(N-1):
    if chk == i+2:
        ans1 = ans2
        ans2 = 0
        count += 1
        if count != M:
            chk = int(input())
    else:
        tempo = ans2
        ans2 = ans1 + ans2
        ans1 = tempo
print(ans2%1000000007)
Problem p03042 (python)

Fixed submission:
S = input()
if S[:2] == "00":
  if int(S[2:]) > 12 or S[2:] == "00":
  	print("NA")
  else:
    print("YYMM")
elif S[2:] == "00":
  if int(S[:2]) > 12:
  	print("NA")
  else:
    print("MMYY")
elif int(S[:2]) > 12 and int(S[2:]) > 12:
  print("NA")
elif int(S[:2]) < 13 and int(S[2:]) < 13:
  print("AMBIGUOUS")
elif int(S[:2]) < 13:
  print("MMYY")
else:
  print("YYMM")

Buggy submission (verdict: Runtime Error):
S = input()
if S[:2] == "00":
  if S[2:] > 12:
  	print("NA")
  else:
    print("YYMM")
elif S[2:] == "00":
  if S[:2] > 12:
  	print("NA")
  else:
    print("MMYY")
elif int(S[:2]) > 12 and int(S[2:]) > 12:
  print("NA")
elif int(S[:2]) < 13 and int(S[2:]) < 13:
  print("AMBIGUOUS")
elif int(S[:2]) < 13:
  print("MMYY")
else:
  print("YYMM")

Buggy submission (verdict: Runtime Error):
S = input()
if S[:2] == "00":
  if S[2:] > 12:
  	print("NA")
  else:
    print("YYMM")
elif S[2:] == "00":
  if S[:2] > 12:
  	print("NA")
  else:
    print("MMYY")
elif int(S[:2]) > 12 and S[2:] > 12:
  print("NA")
elif int(S[:2]) < 13 and S[2:] < 13:
  print("AMBIGUOUS")
elif int(S[:2]) < 13:
  print("MMYY")
else:
  print("YYMM")
Problem p03127 (python)

Fixed submission:
import math
N = int(input())
values = [int(i) for i in input().split()]
def gcd(a, b):
	while b:
		a, b = b, a % b
	return a
c = values[0]
for i in range(N):
    c = gcd(c,values[i])
print(c)

Buggy submission (verdict: Runtime Error):
import functools
import math
N = input()
values = [int(i) for i in input().split()] 
gcd = functools.reduce(math.gcd, values)
print(gcd)
Problem p03775 (python)

Fixed submission:
import math

N = int(input())
M = int(N**0.5//1)
S = list()
for i in range(M+1):
    if i > 0 :
       if N%i == 0:
           S.append(i)
a =  S[-1]
b = N//a
print(max(len(str(a)),len(str(b))))

Buggy submission (verdict: Runtime Error):
N = map(int,input())
M = int(N**0.5//1)
S = list()
for i in range(M+1):
    if i > 0 :
       if N%i == 0:
           S.append(i)
a =  S[-1]
b = N//a
print(len(str(a))+len(str(b)))

Buggy submission (verdict: Runtime Error):
N = input()
M = int(N**0.5//1)
S = list()
for i in range(M+1):
    if i > 0 :
       if N%i == 0:
           S.append(i)
a =  S[-1]
b = N//a
print(len(str(a))+len(str(b)))
Problem p03805 (python)

Fixed submission:
N,M = map(int,input().split())
edge_list = [list() for i in range(N)]
for i in range(M):
        a,b = map(int,input().split())
        edge_list[a-1].append(b-1)
        edge_list[b-1].append(a-1)
done = [0] * N
chk = 0
def dfs(s,done):
    done = done[:]
    global chk
    done[s] = True
    if all(done):
        chk += 1
    for i in edge_list[s]:
        if not done[i]:
            dfs(i,done)
    return 0
dfs(0,done)
print(chk)

Buggy submission (verdict: Runtime Error):
N,M = map(int,input().split())
edge_list = [list() for i in range(N)]
for i in range(M):
        a,b = map(int,input().split())
        edge_list[a-1].append(b-1)
        edge_list[b-1].append(a-1)
done = [0] * n
chk = 0
def dfs(s,done):
    done = done[:]
    global chk
    done[s] = True 
    if all(done):
        chk += 1
    for i in edges[u]:
        if not done[i]:
            dfs(i.done)
    return 0
dfs(0,done)
print(chk)
Problem p02659 (python)

Fixed submission:
a,b = map(float, input().split())

a = int(a)
b = int(b*1000)

c = a*b // 1000

print(c)

Buggy submission (verdict: Runtime Error):
a, b = input().split()

a = int(a)
b = map(int, b.split("."))

c = a*b // 100

print(c)

Buggy submission (verdict: Runtime Error):
a,b = map(float, input().split())
 
c = a * (b*10**4)
c = c // 1e4
print(int(c)
Problem p02753 (python)

Fixed submission:
s = input()

if s == 'AAA' or s == 'BBB':
    print('No')
else:
    print('Yes')

Buggy submission (verdict: Runtime Error):
s = input()

if s ='AAA' or s = 'BBB':
    print('No')
else:
    print('Yes')
Problem p02831 (python)

Fixed submission:
a,b = map(int, input().split())

def gcd(x,y):
    while y:
        x, y = y, x % y
    return x

def lcm(x,y):
    return (x*y) // gcd(x,y)

print(lcm(a,b))

Buggy submission (verdict: Runtime Error):
import math
a,b = map(int, input().split())

def lcm(x,y):
    return (x*y) // math.gcd(x,y)

print(lcm(a,b))
Problem p02879 (python)

Fixed submission:
a, b = map(int, input().split())
if (1 <= a and a <= 9 and 1 <= b and b <= 9):
  print(a*b)
else:
  print(-1)

Buggy submission (verdict: Runtime Error):
A = int(input())
B = int(input())

if A >= 1 and A <= 9 and B >= 1 and B <= 9:
  print(A*B)
else:
  print(-1)
Problem p02623 (python)

Fixed submission:
n, m, k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))

x = [0]
y = [0]
for i in range(n):
    x.append(x[i] + a[i])
    
for i in range(m):
    y.append(y[i] + b[i])
    
i = 0
j = m
ans = 0
while i <= n and 0 <= j:
    if x[i] + y[j] <= k:
        ans = max(ans, i + j)
        i += 1
    else:
        j -= 1

print(ans)

Buggy submission (verdict: Runtime Error):
n, m, k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))

x = [a[0]]
y = [b[0]]
for i in range(1, n):
    x.append(x[i-1] + a[i])
for i in range(1, m):
    y.append(y[i-1] + b[i])
    
t = 0
i = 0
j = 0
ans = 0
l = 0
r = 0
while i < n or j < m:
    if i < n and x[i]-l <= y[j]-r:
        t += a[i]
        l += a[i]
        i += 1
    elif j < m:
        t += b[j]
        r += b[j]
        j += 1
    if t > k:
        break
    ans += 1

print(ans)
Problem p02990 (python)

Fixed submission:
import math

def combinations(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

n, k = map(int, input().split())
for i in range(k):
    if n-k+1 < i+1:
        print(0)
        continue
    if i == 0 or i == k-1:
        print(combinations((n - k + 1), i+1) % (10 ** 9 + 7))
    else:
        print(combinations((n - k + 1), i+1) * combinations(k-1, i) % (10 ** 9 + 7))

Buggy submission (verdict: Runtime Error):
import math

def combinations(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

n, k = map(int, input().split())
for i in range(k):
    if i == 0 or i == k-1:
        print(combinations((n - k + 1), i+1) % (10 ** 9 + 7))
    else:
        print(combinations((n - k + 1), i+1) * (k-1) % (10 ** 9 + 7))