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

Fixed submission:
def main():
    n, c = map(int, input().split())
    sushi = [None]*n
    for i in range(n):
        sushi[i] = list(map(int, input().split()))
    cal_r = [None] * n
    cal_l = [None] * n
    max_r = [None] * n
    max_l = [None] * n
    cal_r[0] = sushi[0][1] - sushi[0][0]
    max_r[0] = cal_r[0]
    for i in range(1, n):
        cal_r[i] = cal_r[i-1] + sushi[i][1] - (sushi[i][0] - sushi[i-1][0])
        max_r[i] = max(max_r[i-1], cal_r[i])
    cal_l[n-1] = sushi[n-1][1] - (c - sushi[n-1][0])
    max_l[n-1] = cal_l[n-1]
    for i in reversed(range(n-1)):
        cal_l[i] = cal_l[i+1] + sushi[i][1] - (sushi[i+1][0] - sushi[i][0])
        max_l[i] = max(max_l[i+1], cal_l[i])
    max_r_1 = max(max_r)
    max_l_1 = max(max_l)
    ans = max(0, max_r_1, max_l_1)
    cal_r_2 = [None] * n
    cal_l_2 = [None] * n
    cal_r_2[n-1] = 0
    cal_l_2[0] = 0
    for i in range(n-1):
        cal_r_2[i] = cal_r[i] - sushi[i][0] + max_l[i+1]
    for i in reversed(range(1, n)):
        cal_l_2[i] = cal_l[i] - (c - sushi[i][0]) + max_r[i-1]
    max_r_2 = max(cal_r_2)
    max_l_2 = max(cal_l_2)
    ans = max(ans, max_l_2, max_r_2)
    print(ans)

if __name__ == "__main__":
    main()

Buggy submission (verdict: Runtime Error):
def main():
    n, c = map(int, input().split())
    sushi = [None]*n
    for i in range(n):
        sushi[i] = list(map(int, input().split()))
    cal_r = [None] * n
    cal_l = [None] * n
    max_r = [None] * n
    max_l = [None] * n
    cal_r[0] = sushi[0][1] - sushi[0][0]
    max_r[0] = cal_r[0]
    for i in range(1, n):
        cal_r[i] = cal_r[i-1] + sushi[i][1] - (sushi[i][0] - sushi[i-1][0])
        max_r[i] = max(max_r[i-1], cal_r[i])
    cal_l[n-1] = sushi[n-1][1] - (c - sushi[n-1][0])
    max_l[n-1] = cal_l[n-1]
    for i in reversed(range(n-1)):
        cal_l[i] = cal_l[i+1] + sushi[i][1] - (sushi[i+1][0] - sushi[i][0])
        max_l[i] = max(max_l[i+1], cal_l[i])
    ans = max(0, *max_r, *max_l)
    cal_r_2 = [None] * n
    cal_l_2 = [None] * n
    cal_r_2[n-1] = 0
    cal_l_2[0] = 0
    for i in range(n-1):
        cal_r_2[i] = cal_r[i] - sushi[i][0] + max_l[i+1]
    for i in reversed(range(1, n)):
        cal_l_2[i] = cal_l[i] - (c - sushi[i][0]) + max_r[i-1]
    ans = max(ans, *cal_r_2, *cal_l_2)
    print(ans)

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

Fixed submission:
s = input()
if "RRR" in s:
  print(3)
elif "RR" in s:
  print(2)
elif "R" in s:
  print(1)
else:
  print(0)

Buggy submission (verdict: Runtime Error):
s = input()
if s.contains("RRR"):
  print(3)
elif s.contains("RR"):
  print(2)
elif s.contains("R"):
  print(1)
else:
  print(0)
Problem p03844 (python)

Fixed submission:
import sys
s = sys.stdin.readline()
print(eval(s))

Buggy submission (verdict: Runtime Error):
import sys
s = sys.stdin.readline()
print eval(s)
Problem p02678 (python)

Fixed submission:
import sys
sys.setrecursionlimit(9999)

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

ps = [-1] * n
ps[0] = 0
tmps = {}
for _ in range(m):
    a,b=map(int,input().split())
    ai,bi=a-1,b-1
    if ai not in tmps:
        tmps[ai] = []
    tmps[ai].append(bi)
    if bi not in tmps:
        tmps[bi] = []
    tmps[bi].append(ai)

# print(tmps)

if 0 not in tmps:
    print("No")
    exit()


def puts(ks):
    nks = []
    for k in ks:
        _nks = tmps[k]
        for nk in _nks:
            if ps[nk] == -1:
                ps[nk] = k
                nks.append(nk)
    if nks == []:
        return None
    # puts(nks)
    return nks

ks = [0]
while True:
    nks = puts(ks)
    if nks is None:
        break
    else:
        ks = nks

#print(ps)

if -1 in ps:
    print("No")
    exit()

print("Yes")
for p in ps[1:]:
    print(p+1)

Buggy submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(9999)

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

ps = [-1] * n
ps[0] = 0
tmps = {}
for _ in range(m):
    a,b=map(int,input().split())
    ai,bi=a-1,b-1
    if ai not in tmps:
        tmps[ai] = []
    tmps[ai].append(bi)
    if bi not in tmps:
        tmps[bi] = []
    tmps[bi].append(ai)

# print(tmps)

if 0 not in tmps:
    print("No")
    exit()


def puts(ks):
    nks = []
    for k in ks:
        _nks = tmps[k]
        for nk in _nks:
            if ps[nk] == -1:
                ps[nk] = k
                nks.append(nk)
        # print(k, ps)
    if nks == []:
        return
    # print(ks, ps)
    puts(nks)  
ks = [0]
puts(ks)

# print(ps)

if -1 in ps:
    print("No")
    exit()

print("Yes")
for p in ps[1:]:
    print(p+1)

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

ps = [-1] * n
ps[0] = 0
tmps = {}
for _ in range(m):
    a,b=map(int,input().split())
    ai,bi=a-1,b-1
    if ai not in tmps:
        tmps[ai] = []
    tmps[ai].append(bi)
    if bi not in tmps:
        tmps[bi] = []
    tmps[bi].append(ai)

# print(tmps)

if 0 not in tmps:
    print("No")
    exit()


def puts(ks):
    nks = []
    for k in ks:
        _nks = tmps[k]
        for nk in _nks:
            if ps[nk] == -1:
                ps[nk] = k
                nks.append(nk)
        # print(k, ps)
    if nks == []:
        return
    # print(ks, ps)
    puts(nks)  
ks = [0]
puts(ks)

# print(ps)

if -1 in ps:
    print("No")
    exit()

print("Yes")
for p in ps[1:]:
    print(p+1)
Problem p02683 (python)

Fixed submission:
from itertools import combinations


N,M,X=map(int,input().split())

mtable = [None]*N
cs = []
for n in range(N):
    aa = list(map(int,input().split()))
    c = aa.pop(0)
    cs.append(c)
    ms = aa
    mtable[n] = ms
    

# print(mtable)
idxes = list(range(N))

prices = []
for i in range(1, N+1):
    for c in combinations(idxes, i):
        sums = [0]*M
        for idx in c:
            for i, m in enumerate(mtable[idx]):
                sums[i] += m
        if all(map(lambda x:x >= X, sums)):
            price = 0
            for idx in c:
                price += cs[idx]

            prices.append(price)
if prices == []:
    print(-1)
else:
    print(min(prices))

Buggy submission (verdict: Runtime Error):
from itertools import combinations


N,M,X=map(int,input().split())

mtable = [None]*N
cs = []
for n in range(N):
    aa = list(map(int,input().split()))
    c = aa.pop(0)
    cs.append(c)
    ms = aa
    mtable[n] = ms
    

# print(mtable)
idxes = list(range(N))

prices = []
for i in range(1, N+1):
    for c in combinations(idxes, i):
        sums = [0]*M
        for idx in c:
            for i, m in enumerate(mtable[idx]):
                sums[i] += m
        if all(map(lambda x:x >= X, sums)):
            price = 0
            for idx in c:
                price += cs[idx]

            prices.append(price)
print(min(prices))
Problem p02684 (python)

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

aa=list(map(int,input().split()))

fumi = set([0])
start = None
end = None
aab = [0]
for i in range(10**18):
    next = aa[aab[-1]] - 1
    if next in fumi:
        if start is None:
            start = i
            fumi = set()
        else:
            end = i
            break

    aab.append(next)
    fumi.add(next)
    if i+1 == k:
        print(next+1)
        exit(0)

random_first = len(aab) - 2*(end - start)
#print(aab, start, end, aab[start+1:end+1], aab[:random_first])

first = aab[:random_first]
one_cicle = aab[start+1:end+1]
if k <= len(first):
    print(first[k]+1)
else:
    k = k-len(first)
    print(one_cicle[k%len(one_cicle)]+1)

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

aa=list(map(int,input().split()))

fumi = set([0])
start = None
end = None
aab = [0]
for i in range(2*10**5):
    next = aa[aab[-1]] - 1
    if next in fumi:
        if start is None:
            start = i
            fumi = set()
        else:
            end = i
            break
    aab.append(next)
    fumi.add(next)

random_first = len(aab) - 2*(end - start)
#print(aab, start, end, aab[start+1:end+1], aab[:random_first])

first = aab[:random_first]
one_cicle = aab[start+1:end+1]
if k <= len(first):
    print(first[k]+1)
else:
    k = k-len(first)
    print(one_cicle[k%len(one_cicle)]+1)

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

aa=list(map(int,input().split()))

fumi = set([0])
start = None
end = None
aab = [0]
for i in range(1*10**5):
    next = aa[aab[-1]] - 1
    if next in fumi:
        if start is None:
            start = i
            fumi = set()
        else:
            end = i
            break
    aab.append(next)
    fumi.add(next)

random_first = len(aab) - 2*(end - start)
#print(aab, start, end, aab[start+1:end+1], aab[:random_first])

first = aab[:random_first]
one_cicle = aab[start+1:end+1]
if k <= len(first):
    print(first[k]+1)
else:
    k = k-len(first)
    print(one_cicle[k%len(one_cicle)]+1)
Problem p02696 (python)

Fixed submission:

A,B,N=map(int,input().split())
import math
def f(x):
    return math.floor(A*x/B) - A*math.floor(x/B)


print(f(min(B-1,N)))

Buggy submission (verdict: Runtime Error):
A,B,N=map(int,input().split())
import math
def f(x):
    return math.floor(A*x/B) - A*math.floor(x/B)

ans = []
for i in list(reversed(range(1, N//B+1)))[:100]:
    ans.append(f(B*i-1))
ans.append(f(N))
ans.append(f(1))
#print(f(N))
print(max(ans))
Problem p02995 (python)

Fixed submission:
import math

a,b,c,d=map(int,input().split())

def gcd(a, b):
    while b:
        a, b = b, a % b
    return a

gcd_ = int(gcd(c,d))

cc = (c//gcd_ * d)


mm1 = b//c
mm2 = b//d
mmc = b//cc
A1 = b - (mm2 + mm1 - mmc)
# print(A1, b, mm2, mm1, mmc)

a-=1
mm1 = a//c
mm2 = a//d
mmc = a//cc
A2 = a - (mm2 + mm1 - mmc)
# print(A2, a, mm2, mm1, mmc)


print(A1 - A2)

Buggy submission (verdict: Runtime Error):
import fractions

a,b,c,d=map(int,input().split())

gcd = int(fractions.gcd(c,d))

cc = (c//gcd * d)


mm1 = b//c
mm2 = b//d
mmc = b//cc
A1 = b - (mm2 + mm1 - mmc)
# print(A1, b, mm2, mm1, mmc)

a-=1
mm1 = a//c
mm2 = a//d
mmc = a//cc
A2 = a - (mm2 + mm1 - mmc)
# print(A2, a, mm2, mm1, mmc)


print(A1 - A2)
~

Buggy submission (verdict: Runtime Error):
import math

a,b,c,d=map(int,input().split())

gcd = int(math.gcd(c,d))

cc = (c//gcd * d)


mm1 = b//c
mm2 = b//d
mmc = b//cc
A1 = b - (mm2 + mm1 - mmc)
# print(A1, b, mm2, mm1, mmc)

a-=1
mm1 = a//c
mm2 = a//d
mmc = a//cc
A2 = a - (mm2 + mm1 - mmc)
# print(A2, a, mm2, mm1, mmc)


print(A1 - A2)
Problem p03000 (python)

Fixed submission:
n,x=map(int,input().split())
ls=list(map(int,input().split()))
c = 1
b = 0
for an in range(n):
    b+=ls[an]
    if b>x:
        break
    c+=1
print(c)

Buggy submission (verdict: Runtime Error):
c = 0
b = 0
for an in range(n):
    c+=1
    b+=ls[an]
    if b>x:
        break
print(c)
Problem p02727 (python)

Fixed submission:
from heapq import heappop, heappush
x,y,a,b,c = map(int, input().split())

aa = sorted(map(int, input().split()), reverse=True)
bb = sorted(map(int, input().split()), reverse=True)
cc = sorted(map(int, input().split()), reverse=True)
dd = []
for i in aa[:x]:
    heappush(dd,i)
for i in bb[:y]:
    heappush(dd, i)

for i in range(c):
    heappush(dd, cc[i])
    heappop(dd)

print(sum(dd))

Buggy submission (verdict: Runtime Error):
from heapq import heappop, heappush
x,y,a,b,c = map(int, input().split())

aa = sorted(map(int, input().split()), reverse=True)
bb = sorted(map(int, input().split()), reverse=True)
cc = sorted(map(int, input().split()), reverse=True)
heap = []
used = {}
for i in range(min(c,x)):
    heappush(heap, [-cc[i], 2, i])
for i in range(x):
    heappush(heap, [-aa[i], 0, i])

ans = 0
for i in range(x):
    value, color, pos = heappop(heap)
    ans -= value
    if color == 2:
        used.add(pos)

i = 0
heap = []
while len(heap) < y and i < c:
    if i not in used:
        heappush(heap, -cc[i])
    i += 1
for i in range(y):
    heappush(heap, -bb[i])

for i in range(y):
    value = heappop(heap)
    ans -= value

print(ans)
Problem p02889 (python)

Fixed submission:
from scipy.sparse.csgraph import dijkstra as di

inf = float('INF')
n,m,l = map(int,input().split())

route = [[0 for _ in range(n)] for _ in range(n)]
for _ in range(m):
    a,b,c = map(int, input().split())
    route[a-1][b-1] = route[b-1][a-1] = c

p_route = di(route)
p_route[p_route == 0] = inf
p_route[l >= p_route] = 1
p_route[l < p_route] = 0
p_route = di(p_route)

# print(p_route)
query = []
q = int(input())
ans = []
for _ in range(q):
    s,t = map(int, input().split())
    print(-1 if p_route[s-1][t-1] == inf else int(p_route[s-1][t-1]) - 1)

Buggy submission (verdict: Runtime Error):
from scipy.sparse.csgraph import dijkstra as di

inf = float('INF')


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

route = [[0 for _ in range(n)] for _ in range(n)]
for _ in range(m):
    a,b,c = map(int, input().split())
    route[a-1][b-1] = route[b-1][a-1] = c

p_route = di(route)
for i in range(n):
    for j in range(n):
        if p_route[i][j] == inf:
            continue
        elif p_route[i][j] <= l:
            p_route[i][j] = 1
p_route = di(p_route)

query = []
q = int(input())
ans = []
for _ in range(q):
    s,t = map(int, input().split())
    print(-1 if p_route[s-1][t-1] == inf else p_route[s-1][t-1])
Problem p02936 (python)

Fixed submission:
# https://atcoder.jp/contests/abc138/tasks/abc138_d

from collections import deque

def bfs(graph, start, query, n):
    queue = deque([])
    acc = query[start] if start in query else 0
    queue.append([start, acc])
    ans = [-1] * n
    ans[start] = acc

    while queue:
        idx, acc = queue.popleft()
        for child in graph[idx].keys():
            if ans[child] >= 0:
                continue
            ans[child] = acc
            if child in query:
                ans[child] += query[child]
            queue.append([child, ans[child]])
    
    print(' '.join(map(str, ans)))

n,q = map(int, input().split())
tree = {}
start = 0
for i in range(n-1):
    a,b = map(int, input().split())
    a -= 1
    b -= 1
    if a not in tree:
        tree[a] = {}
    tree[a][b] = 1
    if b not in tree:
        tree[b] = {}
    tree[b][a] = 1

query = {}
for _ in range(q):
    p, x = map(int,input().split())
    p -= 1
    if p not in query:
        query[p] = x
    else:
        query[p] += x
bfs(tree, start, query, n)

Buggy submission (verdict: Runtime Error):
# https://atcoder.jp/contests/abc138/tasks/abc138_d

from collections import deque

def bfs(graph, start, query):
    queue = deque([])
    acc = query[start] if start in query else 0
    queue.append([start, acc])
    ans = {start:acc}

    while queue:
        idx, acc = queue.popleft()
        for child in graph[idx].keys():
            ans[child] = acc
            if child in query:
                ans[child] += query[child]
            if child in graph:
                queue.append([child, ans[child]])
    [print(ans[i], end=' ') for i in range(1, n+1)]

n,q = map(int, input().split())
tree = {}
start = 1
init = 1
for i in range(n-1):
    a,b = map(int,input().split())
    if a not in tree:
        tree[a] = {}
    tree[a][b] = init
    # if b not in tree:
    #     tree[b] = {}
    # tree[b][a] = init

query = {}
for _ in range(q):
    p, x = map(int,input().split())
    if p not in query:
        query[p] = x
    else:
        query[p] += x
bfs(tree, start, query)
Problem p02960 (python)

Fixed submission:
def main():
    M=10**9+7
    r=tuple(tuple((j-k)*9%13for j in range(10))for k in range(13))
    d=[1]+[0]*12
    for c in input():
        if c > '9':
            d = [sum(d[j] for j in k)%M for k in r] 
        else:
            d = [d[(int(c)-k)*9%13] for k in range(13)]
    print(d[5])
main()

Buggy submission (verdict: Runtime Error):
s = input()
mod = 10**9+7

init = [0 for i in range(13)]
if s[0] == '?':
  dp = [1] * 10 + [0] * 3
else:
  dp = [0 for i in range(13)]
  dp[int(s[0])] = 1

for c in s[1:]:
  d = init.copy()
  if c == '?':
    for i in range(13):
      for j in range(10):
        idx = (i * 10 + j) % 13
        d[idx] = (dp[i] + d[idx]) % mod 
  else :
    for i in range(13):
      idx = (i * 10 + int(c)) % 13
      d[idx] = (dp[i] + d[idx]) % mod
  dp = d.copy()
print(dp[5])
Problem p02971 (python)

Fixed submission:
from collections import Counter

N = int(input())
A = [int(input()) for i in range(N)]

c = Counter(A)

mx = max(A)
B = list(set(A))
B.remove(mx)
for i in range(N):
    if A[i] != mx:
        print(mx)
    elif c[mx] == 1:
        print(max(B))
    else:
        print(mx)

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

N = int(input())
A = [int(input()) for i in range(N)]

c = Counter(A)

mx = max(A)
B = list(set(A))
B.remove(mx)
bmx = max(B)
for i in range(N):
    if A[i] != mx:
        print(mx)
    elif c[mx] == 1:
        print(bmx)
    else:
        print(mx)
Problem p02997 (python)

Fixed submission:
import math
N,K = map(int, input().split())
M = (N-1)*(N-2)//2
if K > M:
    print(-1)
    exit()

print(N-1+M-K)
for i in range(2,N+1):
    print(1,i)
s = 2
d = 3
for i in range(M-K):
    print(s,d)
    d+=1
    if d > N:
        s+=1
        d = s+1

Buggy submission (verdict: Runtime Error):
import math
N,K = map(int, input().split())
M = (N-1)*(N-2)//2
if K > M:
    print(-1)
    exit()

print(N-1+M-K)
for i in range(2,N+1):
    print(1,i)
s = 2
d = 3
for i in range(M-K):
    print(s,d)
    d+=1
    if d > n:
        s+=1
        d = s+1

Buggy submission (verdict: Runtime Error):
import math
N,K = map(int, input().split())
if N == 2 and K != 0:
    print(-1)
    exit()
if K > math.factorial(N-1) // (math.factorial(N - 1 - 2) * math.factorial(2)):
    print(-1)
    exit()

for i in range(2,N+1):
    print(1,i)

for i in range(3,K+3):
    print(2,i)

Buggy submission (verdict: Runtime Error):
import math
N,K = map(int, input().split())
if K > math.factorial(N-1) // (math.factorial(N - 1 - 2) * math.factorial(2)):
    print(-1)
    exit()

for i in range(2,N+1):
    print(1,i)

for i in range(3,K+3):
    print(2,i)

Buggy submission (verdict: Runtime Error):
import math
N,K = map(int, input().split())
if K > math.factorial(n-1) // (math.factorial(N - 1 - 2) * math.factorial(2)):
    print(-1)
    exit()

for i in range(2,N+1):
    print(1,i)

for i in range(3,K+3):
    print(2,i)
Problem p03006 (python)

Fixed submission:
N = int(input())
A = [list(map(int, input().split())) for i in range(N)]

if N == 1:
    print(1)
    exit()
A.sort()
grid = {}
for i in range(N):
    for j in range(i+1,N):
        if (A[j][0] - A[i][0], A[j][1] - A[i][1]) not in grid:
            grid[A[j][0] - A[i][0], A[j][1] - A[i][1]] = 1
        else:
            grid[A[j][0] - A[i][0], A[j][1] - A[i][1]] += 1

print(N - max(grid.values()))

Buggy submission (verdict: Runtime Error):
N = int(input())
A = [list(map(int, input().split())) for i in range(N)]

A.sort()
grid = {}
for i in range(N):
    for j in range(i+1,N):
        if (A[j][0] - A[i][0], A[j][1] - A[i][1]) not in grid:
            grid[A[j][0] - A[i][0], A[j][1] - A[i][1]] = 1
        else:
            grid[A[j][0] - A[i][0], A[j][1] - A[i][1]] += 1

print(N - max(grid.values()))
Problem p03014 (python)

Fixed submission:
import numpy as np
import sys

H, W = list(map(int, sys.stdin.readline().split()))
S = np.array([list(sys.stdin.readline().rstrip()) for _ in range(H)]) == '.'
ups = np.zeros((H, W), dtype=int)
downs = np.zeros((H, W), dtype=int)
rights = np.zeros((H, W), dtype=int)
lefts = np.zeros((H, W), dtype=int)

for h in range(1, H):
    ups[h] = (ups[h - 1] + 1) * S[h - 1]
    downs[H - h - 1] = (downs[H - h] + 1) * S[H - h]
for w in range(1, W):
    lefts[:, w] = (lefts[:, w - 1] + 1) * S[:, w - 1]
    rights[:, W - w - 1] = (rights[:, W - w] + 1) * S[:, W - w]
print(((ups + downs + lefts + rights) * S).max() + 1)

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

H, W = list(map(int, sys.stdin.readline().split()))
S = np.array([list(sys.stdin.readline().rstrip()) for _ in range(H)]) == '.'
ups = np.zeros((H, W), dtype=int)
downs = np.zeros((H, W), dtype=int)
rights = np.zeros((H, W), dtype=int)
lefts = np.zeros((H, W), dtype=int)

for h in range(1, H):
    ups[h] = (ups[h - 1] + 1) * S[h - 1]
    downs[H - h] = (downs[H - h + 1] + 1) * S[H - h + 1]
for w in range(1, W):
    lefts[:, w] = (lefts[:, w - 1] + 1) * S[:, w - 1]
    rights[:, W - w] = (rights[:, W - w + 1] + 1) * S[:, W - w + 1]
print(((ups + downs + lefts + rights) * S).max() + 1)
Problem p03071 (python)

Fixed submission:
A, B = map(int , input().split())
maxi = 0
if A < B:
    maxi = B
    B -= 1
else :
    maxi = A
    A -= 1
if A < B:
    maxi += B
else :
    maxi += A
print(maxi)

Buggy submission (verdict: Runtime Error):
a = list(map(int, input().split()))
a.append(a[0]-1)
a.append(a[1]-1)
a.sort()
pirnt(a[-1]+ a[-2])
Problem p03078 (python)

Fixed submission:
*xyz,k = map(int, input().split()) 
xyz_list = []
xyz_list.append(list(map(int, input().split())))
xyz_list.append(list(map(int, input().split())))
xyz_list.append(list(map(int, input().split())))
xyz_list[0].sort(reverse=True)
xyz_list[1].sort(reverse=True)
xyz_list[2].sort(reverse=True)

print(xyz_list[0][0]+xyz_list[1][0]+xyz_list[2][0])
p = [1,0,0]
num = lambda x: [
    [x[0]+p[i], x[1]+p[(4-i)%3], x[2]+p[(5-i)%3],
    xyz_list[0][x[0]+p[i]]+xyz_list[1][x[1]+p[(4-i)%3]]+xyz_list[2][x[2]++p[(5-i)%3]]]
    for i in range(3) if x[i]+1 < xyz[i]]
stack = num([0,0,0])
num_dict={}
for i in stack:
    if i[3] not in num_dict:
        num_dict[i[3]] = [[i[0], i[1], i[2]]]
    else:
        num_dict[i[3]].append([i[0], i[1], i[2]])
k -= 1
while k != 0:
    x, y, z, maxi = max(stack, key=lambda x:x[3])
    print(maxi)
    k -= 1
    if k == 0:
      break
    stack.remove([x,y,z,maxi])
    for i in num([x,y,z]):
        if i[3] not in num_dict:
            num_dict[i[3]] = [[i[0], i[1], i[2]]]
            stack.append([i[0], i[1], i[2], i[3]])
        elif [i[0], i[1], i[2]] not in num_dict[i[3]]:
            num_dict[i[3]].append([i[0], i[1], i[2]])
            stack.append([i[0], i[1], i[2], i[3]])

Buggy submission (verdict: Runtime Error):
from itertools import product
from heapq import heappop, heappush

x,y,z,k = map(int,input().split())
a = sorted(map(int, input().split()), reverse=True)
b = sorted(map(int, input().split()), reverse=True)
c = sorted(map(int, input().split()), reverse=True)

if x * y * z <= 3000:
    lst = sorted([sum(i) for i in product(a,b,c)], reverse=True)
    [print(i) for i in lst[:k]]
    exit()

lst = []
idx = [0,0,0]
heap = []

xxx = [x,y,z]
aaa = idx[0] if idx[0]+1 >= x else idx[0] + 1
bbb = idx[1] if idx[1]+1 >= y else idx[1] + 1
ccc = idx[2] if idx[2]+1 >= z else idx[2] + 1
heappush(heap, [-([aaa] + b[idx[1]] + c[idx[2]]), 0])
heappush(heap, [-([idx[0]] + b[bbb] + c[idx[2]]), 1])
heappush(heap, [-([idx[0]] + b[idx[1]] + c[ccc]), 2])
print(a[idx[0]] + b[idx[1]] + c[idx[2]])
for _ in range(k-1):
    score, ix = heappop(heap)
    print(-score)
    print(idx)
    idx[ix] = idx[ix] if idx[ix] + 1 >= xxx[ix] else idx[ix] + 1
    score = ([idx[0]] + b[idx[1]] + c[idx[2]])
    heappush(heap, [-score, ix])

# lst.sort(reverse=True)
# [print(i) for i in lst[:k]]
Problem p03106 (python)

Fixed submission:
A,B,K = map(int,input().split())
x = []
for i in range(1, min(A,B)+1):
  if A % i == 0 and B % i == 0:
    x.append(i)
print(x[-K])

Buggy submission (verdict: Runtime Error):
A,B,K = map(int,input().split())
cnt = 0
for i in range(1, min(A,B)):
  if A % i == 0 and B % i == 0:
    cnt += 1
  if cnt == K:
    break
print(i)