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

Fixed submission:
N,M=map(int,input().split())
G=[]
for i in range(0,N):
    G.append([])

for i in range(0,M):
    a,b=map(int,input().split())
    a-=1
    b-=1
    G[a].append(b)
    G[b].append(a)

q=[]
sign=[-1]*N
sign[0]=0
q.append(0)
while q:
    x=q.pop(0)
    for nv in G[x]:
        if sign[nv]==-1:
            sign[nv]=x
            q.append(nv)

print("Yes")
for i in range(1,N):
    print(sign[i]+1)

Buggy submission (verdict: Runtime Error):
N,M=map(int,input().split())
G=[]
for i in range(0,M):
    G.append([])

for i in range(0,M):
    a,b=map(int,input().split())
    a-=1
    b-=1
    G[a].append(b)
    G[b].append(a)

q=[]
sign=[-1]*N
sign[0]=0
q.append(0)
while q:
    x=q.pop(0)
    for nv in G[x]:
        if sign[nv]==-1:
            sign[nv]=x
            q.append(nv)

print("Yes")
for i in range(1,N):
    print(sign[i]+1)
Problem p02684 (python)

Fixed submission:
N,K=map(int,input().split())
A=list(map(int,input().split()))

move=[]
for i in range(0,N):
    move.append([])
    A[i]-=1
    move[i].append(A[i])


for j in range(1,64):
    for i in range(0,N):
        move[i].append(move[move[i][j-1]][j-1])
town=0
for i in range(0,64):
    if K%2==1:
        town=move[town][i]
    K//=2

print(town+1)

Buggy submission (verdict: Runtime Error):
N,K=map(int,input().split())
A=list(map(int,input().split()))

cycle=[]
for i in range(0,N):
    cycle.append(-1)
    A[i]-=1

count=0
cycle[0]=count
town=0
mod=0
while True:
    count+=1
    K-=1
    town=A[town]
    if K==0:
        break
    if cycle[town]==-1:
        cycle[town]=count
    else:
        mod=count-cycle[town]
        break

K%=mod
while K>0:
    town=A[town]
    K-=1

print(town+1)
Problem p02772 (python)

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

flag=True
for a in A:
    if a%2==0:
        if (a%3!=0)&(a%5!=0):
            flag=False
            break

if flag:
    print("APPROVED")
else:
    print("DENIED")

Buggy submission (verdict: Runtime Error):
#include <bits/stdc++.h>
using namespace std;

int main(){
  cout<<"Hello"<<endl;
}
Problem p02945 (python)

Fixed submission:
A,B=map(int,input().split())
print(max(A+B,A-B,A*B))

Buggy submission (verdict: Runtime Error):
map(int,input().split())
print(max(A+B,A-B,A*B))
Problem p03274 (python)

Fixed submission:
N,K=map(int,input().split())
x=list(map(int,input().split()))
positive=[]
negative=[]
for i in range(N):
    if x[i]<0:
        negative.append(-x[i])
    else:
        positive.append(x[i])
negative.sort()
n=len(negative)
m=len(positive)
ans=1000000000
if n>=K:
    ans=min(ans,negative[K-1])
if m>=K:
    ans=min(ans,positive[K-1])

for i in range(n):
    j=K-(i+1)
    if j>m:
        continue
    if j<=0:
        continue
    ans=min(ans,negative[i]+positive[j-1]+min(negative[i],positive[j-1]))
print(ans)

Buggy submission (verdict: Runtime Error):
N,K=map(int,input().split())
x=list(map(int,input().split()))
positive=[]
negative=[]
for i in range(N):
    if x[i]<0:
        negative.append(-x[i])
    else:
        positive.append(x[i])
negative.sort()
n=len(negative)
m=len(positive)
ans=1000000000
if n>=K:
    ans=min(ans,negative[K-1])
if m>=K:
    ans=min(ans,positive[K-1])

for i in range(n):
    j=K-(i+1)
    if j<=0:
        continue
    ans=min(ans,negative[i]+positive[j-1]+min(negative[i],positive[j-1]))
print(ans)
Problem p03623 (python)

Fixed submission:
x,a,b=map(int,input().split())
if abs(x-a)<abs(x-b):
    print('A')
else:
    print('B')

Buggy submission (verdict: Runtime Error):
x,a,b=map(int,input().split())
if abs(x-a)<abs(x-b):
    pirnt('A')
else:
    print('B')
Problem p03760 (python)

Fixed submission:
O=input()
E=input()
ans=""
for i in range(len(E)):
  ans+=O[i]
  ans+=E[i]

if len(O)!=len(E):
  ans+=O[-1]
print(ans)

Buggy submission (verdict: Runtime Error):
O=input()
E=inpu()
ans=""
for i in range(len(E)):
  ans+=O[i]
  ans+=E[i]

if len(O)!=len(E):
  ans+=O[-1]
print(ans)
Problem p04043 (python)

Fixed submission:
A=list(map(int,input().split()))
A.sort()
if A==[5,5,7]:
  print("YES")
else:
  print("NO")

Buggy submission (verdict: Runtime Error):
A=list(map(int,input().split()))
A.sorted()
if A==[5,5,7]:
  print("YES")
else:
  print("NO")

Buggy submission (verdict: Runtime Error):
A=list(map(int,input().split()))
sort(A)
if A==[5,5,7]:
  print("YES")
else:
  print("NO")
Problem p02910 (python)

Fixed submission:
s = input()
yes = True
for i, c in enumerate(s):
    if i % 2 == 1 and c == 'R':
        #print(i)
        yes = False
    elif i % 2 == 0 and c == 'L':
        yes = False
        #print(i)
if yes:
    print('Yes')
else:
    print('No')

Buggy submission (verdict: Runtime Error):
s = input()
for i, c in enumerate(s):
    if i % 2 == 0 and c == 'R':
        yes = False
    elif i % 2 == 1 and c == 'L':
        yes = False
if yes:
    print('Yes')
else:
    print('No')
Problem p02909 (python)

Fixed submission:
S = input()
if S == 'Sunny':
    print('Cloudy')
elif S == 'Cloudy':
    print('Rainy')
elif S == 'Rainy':
    print('Sunny')

Buggy submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline
 
def main():
    S = input()
    if S = 'Sunny':
        print('Cloudy')
    elif S = 'Cloudy':
        print('Rainy')
    elif S = 'Rainy':
        print('Sunny')

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

Fixed submission:
import sys
input = sys.stdin.readline
sys.setrecursionlimit(300000)


def dfs(v, x, G, X, visited, ans):
    visited[v] = True
    ans[v] = x
    # print(visited)

    for nv in G[v]:
        if visited[nv]:
            continue
        dfs(nv, x+X[nv], G, X, visited, ans)


def main():
    N, Q = map(int, input().split())
    G = [[] for _ in range(N)]
    for _ in range(N-1):
        a, b = map(int, input().split())
        G[a-1].append(b-1)
        G[b-1].append(a-1)
    X = [0]*N
    for _ in range(Q):
        p, x = map(int, input().split())
        X[p-1] += x
    # print(G)
    # print(X)
    
    visited = [False]*N
    ans = [0]*N
    dfs(0, X[0], G, X, visited, ans)
    print(' '.join(list(map(str, ans))))
    

if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline
sys.setrecursionlimit(200000)

def dfs(v, x, G, X, visited, ans):
    visited[v] = True
    ans[v] = x
    # print(visited)

    for nv in G[v]:
        if visited[nv]:
            continue
        dfs(nv, x+X[nv], G, X, visited, ans)


def main():
    N, Q = map(int, input().split())
    G = [[] for _ in range(N)]
    for _ in range(N-1):
        a, b = map(int, input().split())
        G[a-1].append(b-1)
        G[b-1].append(a-1)
    X = [0]*N
    for _ in range(Q):
        p, x = map(int, input().split())
        X[p-1] += x
    # print(G)
    # print(X)
    
    visited = [False]*N
    ans = [0]*N
    dfs(0, X[0], G, X, visited, ans)
    print(' '.join(list(map(str, ans))))
    

if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline


def dfs(v, x, G, X, visited, ans):
    visited[v] = True
    ans[v] = x
    # print(visited)

    for nv in G[v]:
        if visited[nv]:
            continue
        dfs(nv, x+X[nv], G, X, visited, ans)


def main():
    N, Q = map(int, input().split())
    G = [[] for _ in range(N)]
    for _ in range(N-1):
        a, b = map(int, input().split())
        G[a-1].append(b-1)
        G[b-1].append(a-1)
    X = [0]*N
    for _ in range(Q):
        p, x = map(int, input().split())
        X[p-1] += x
    # print(G)
    # print(X)
    
    visited = [False]*N
    ans = [0]*N
    dfs(0, X[0], G, X, visited, ans)
    print(' '.join(list(map(str, ans))))
    

if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
import math
import sys
input = sys.stdin.readline


def dfs(v, x, G, X, visited, ans):
    visited[v] = True
    ans[v] = x

    for nv in G[v]:
        if visited[nv]:
            continue
        dfs(nv, x+X[nv], G, X, visited, ans)


def main():
    N, Q = map(int, input().split())
    G = [[] for _ in range(N)]
    for _ in range(N-1):
        a, b = map(int, input().split())
        G[a-1].append(b-1)
        G[b-1].append(a-1)
    X = [0]*N
    for _ in range(Q):
        p, x = map(int, input().split())
        X[p-1] += x
    
    visited = [False]*N
    ans = [0]*N
    dfs(0, X[0], G, X, visited, ans)
    print(' '.join(list(map(str, ans))))
    


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

Fixed submission:
N = int(input())
if N==1:
	print('Hello World')
else:
	A = int(input())
	B = int(input())
	print(A+B)

Buggy submission (verdict: Runtime Error):
n = input()
if n==1:
    print("Hello World")
else:
    A = int(input())
    B = int(input())
    print(A+B)
Problem p03262 (python)

Fixed submission:
from functools import reduce
from fractions import gcd
import sys
input = sys.stdin.readline


def main():
    N, X = map(int, input().split())
    A = list(map(int, input().split()))

    B = [abs(A[i]-X) for i in range(N)]
    print(reduce(gcd, B))


if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
import numpy as np
import sys
input = sys.stdin.readline


def main():
    N, X = map(int, input().split())
    A = list(map(int, input().split()))

    B = np.array([abs(A[i]-X) for i in range(N)])
    print(np.gcd.reduce(B))


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

Fixed submission:
S = input()

if ('a' in S) and ('b' in S) and ('c' in S):
	print('Yes')
else:
	print('No')

Buggy submission (verdict: Runtime Error):
S = intput()

if ('a' in S) and ('b' in S) and ('c' in S):
	print('Yes')
else:
	print('No')
Problem p03399 (python)

Fixed submission:
A = int(input())
B = int(input())
C = int(input())
D = int(input())
print(min([A, B]) + min([C, D]))

Buggy submission (verdict: Runtime Error):
A, B, C, D = map(int, input().split())
print(min([A, B]) + min([C, D]))
Problem p03436 (python)

Fixed submission:
from collections import deque
import sys
input = sys.stdin.readline
INF = float('inf')

def main():
    def bfs(x, y):
        L = [[INF]*W for _ in range(H)]
        L[0][0] = 1
        Q = deque([[0,0]])
        while len(Q)!=0:
            x, y = Q.popleft()
            if x==W-1 and y==H-1:
                break
            for i in range(4):
                nx, ny = x + [1,0,-1,0][i], y + [0,1,0,-1][i]
                if 0<=nx and nx<W and 0<=ny and ny<H:
                    if M[ny][nx]=='.' and L[ny][nx]==INF:
                        Q.append([nx, ny])
                        L[ny][nx] = L[y][x] + 1
        return L[H-1][W-1]
    
    H, W = map(int, input().split())
    M = []
    cnt = 0
    for _ in range(H):
        m = list(input()[:-1])
        cnt += m.count('#')
        M.append(m)

    b = bfs(0, 0)
    if b==INF:
        print(-1)
    else:
        print(H*W - cnt - b)


if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
from functools import reduce
from fractions import gcd
import heapq
import queue
import math
import bisect
import itertools
import sys
sys.setrecursionlimit(10**7)
input = sys.stdin.readline
INF = float("inf")


def main():
    H, W = map(int, input().split())
    G = []
    for _ in range(H):
        G.append(list(input()[:-1]))
    
    C = [[INF] * W for _ in range(H)]
    C[0][0] = 1
    cnt = 0
    for i in range(H):
        for j in range(W):
            if G[i][j] == "#":
                cnt += 1
                continue
            if i + 1 < H:
                C[i+1][j] = min(C[i+1][j], C[i][j] + 1)
            if j + 1 < W:
                C[i][j+1] = min(C[i][j+1], C[i][j] + 1)

    if C[H-1][W-1] == INF or G[H-1][G-1] == "#":
        print(-1)
    else:
        print(H * W - (C[H-1][W-1] + cnt))


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

Fixed submission:
a, b = map(int, input().split())
if a*b%2 == 0:
	print('Even')
else:
	print('Odd')

Buggy submission (verdict: Runtime Error):
a, b = map(int, split())

if a*b%2==0:
	print('Even')
else:
	print('Odd')
Problem p03485 (python)

Fixed submission:
import math

a, b = list(map(int, input().split()))
ans = math.ceil((a+b)/2)
print(ans)

Buggy submission (verdict: Runtime Error):
a, b = list(map(int, input().split()))
print(int((a+b)/2 + 1)
Problem p03567 (python)

Fixed submission:
def solve():
	S = input()
	for i in range(len(S)-1):
		if S[i:i+2]=='AC':
			print('Yes')
			return
	print('No')
	return

solve()

Buggy submission (verdict: Runtime Error):
def solve():
	S = input()
	for i in range(len(S)-1):
		if S[i:i+2]=='AC':
			print('Yes')
			return
	print('No')
	return

 solve()
Problem p03573 (python)

Fixed submission:
A, B, C = list(map(int, input().split()))
if A==B:
	print(C)
elif B==C:
	print(A)
elif C==A:
	print(B)

Buggy submission (verdict: Runtime Error):
A, B, C = int(input())
if A==B:
	print(C)
elif B==C:
	print(A)
elif C==A:
	print(B)
Problem p03608 (python)

Fixed submission:
import itertools

def warshall_floyd(D, n):
    for k in range(n):
        for i in range(n):
            for j in range(n):
                D[i][j] = min(D[i][j], D[i][k]+D[k][j])


N, M, R = map(int, input().split())
r = list(map(int, input().split()))
D = [[float('inf')]*N for _ in range(N)]
for i in range(N):
    D[i][i] = 0
for _ in range(M):
    a, b, c = map(int, input().split())
    D[a-1][b-1] = c
    D[b-1][a-1] = c

warshall_floyd(D, N)

ans = float('inf')
for P in itertools.permutations(r):
    cost = 0
    for i in range(R-1):
        cost += D[P[i]-1][P[i+1]-1]
    ans = min(ans, cost)

print(ans)

Buggy submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline

def main():
        import itertools

    def warshall_floyd(D, n):
        for k in range(n):
            for i in range(n):
                for j in range(n):
                    D[i][j] = min(D[i][j], D[i][k]+D[k][j])


    N, M, R = map(int, input().split())
    r = list(map(int, input().split()))
    D = [[float('inf')]*N for _ in range(N)]
    for i in range(N):
        D[i][i] = 0
    for _ in range(M):
        a, b, c = map(int, input().split())
        D[a-1][b-1] = c
        D[b-1][a-1] = c

    warshall_floyd(D, N)

    ans = float('inf')
    for P in itertools.permutations(r):
        cost = 0
        for i in range(R-1):
            cost += D[P[i]-1][P[i+1]-1]
        ans = min(ans, cost)

    print(ans)


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

Fixed submission:
N, K = map(int, input().split())
l = list(map(int, input().split()))

ans = 0
for i in range(K):
	m = max(l)
	ans += m
	l[l.index(m)] = 0
print(ans)

Buggy submission (verdict: Runtime Error):
N, K = map(int, input().split())
l = list(map(int, input().split()))

ans = 0
for i in range(K):
	m = max(l)
	ans += m
	l[l.find(str(m))] = 0
print(ans)

Buggy submission (verdict: Runtime Error):
N, K = map(int, input().split())
l = list(map(int, input().split()))

ans = 0
for i in range(K):
	m = max(l)
	ans += m
	l[l.find(m)] = 0
print(ans)
Problem p03679 (python)

Fixed submission:
X, A, B = list(map(int, input().split()))
if A-B>=0:
	print('delicious')
elif X+A-B>=0:
	print('safe')
else:
	print('dangerous')

Buggy submission (verdict: Runtime Error):
X, A, B = input().split()

if A-B>=0:
	print('delicious')
elif X+A-B>=0:
	print('safe')
else:
	print('dangerous')
Problem p03722 (python)

Fixed submission:
N, M = map(int, input().split())
a = [0]*M
b = [0]*M
c = [0]*M
for i in range(M):
	x, y, z = map(int, input().split())
	a[i] = x
	b[i] = y
	c[i] = -z

INF = float('inf')
d = [INF]*N
d[0] = 0

for _ in range(N-1):
	for i in range(M):
		if d[a[i]-1]==INF:
			continue
		if d[b[i]-1]>d[a[i]-1]+c[i]:
			d[b[i]-1] = d[a[i]-1] + c[i]

ans = -d[N-1]

negative = [False]*N
for _ in range(N):
	for i in range(M):
		if d[a[i]-1]==INF:
			continue
		if d[b[i]-1]>d[a[i]-1]+c[i]:
			d[b[i]-1] = d[a[i]-1] + c[i]
			negative[b[i]-1] = True
		if negative[a[i]-1]==True:
			negative[b[i]-1] = True

if negative[N-1]==True:
	print('inf')
else:
	print(ans)

Buggy submission (verdict: Runtime Error):
from functools import reduce
from fractions import gcd
import math
import bisect
import itertools
import sys
sys.setrecursionlimit(10**7)
input = sys.stdin.readline
INF = float("inf")
MOD = 1000000007


def bellman_ford(edges, num_v, sv):
    #グラフの初期化
    dist = [INF] * num_v
    dist[sv]=0
    
    #辺の緩和
    for i in range(num_v):
        for edge in edges:
            s, t, d = edge[0], edge[1], edge[2]
            if dist[s] != INF and dist[t] > dist[s] + d:
                dist[t] = dist[s] + d
                if i == num_v - 1:
                    return -1       # 負の閉路が存在する
    
    return dist


def main():
    N, M = map(int, input().split())

    edges = []
    for _ in range(M):
        a, b, c = map(int, input().split())
        a -= 1; b -= 1; c *= -1
        edges.append([a, b, c])
    
    dist = bellman_ford(edges, N, 0)

    if dist == 0:
        print("inf")
    else:
        print(-dist[N-1])


if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
N, M = map(int, input().split())
a = [0]*M
b = [0]*M
c = [0]*M
for i in range(M):
	x, y, z = map(int, input().split())
	a[i] = x
	b[i] = y
	c[i] = -z

INF = float('inf')
d = [INF]*N
d[0] = 0

for _ in range(N-1):
	for i in range(M):
		if d[a[i]-1]==INF:
			continue
		if d[b[i]-1]>d[a[i]-1]+c[i]:
			d[b[i]-1] = d[a[i]-1] + c[i]

ans = -d[N-1]

negative = [False]*N
for _ in range(N):
	for i in range(M):
		if d[a[i]-1]==INF:
			continue
		if d[b[i]-1]>d[a[i]-1]+c[i]:
			d[b[i]-1] = d[a[i]-1] + c[i]
			negative[i] = True
		if negative[a[i]-1]==True:
			negative[b[i]-1] = True

if negative[N-1]==True:
	print('inf')
else:
	print(ans)
Problem p03777 (python)

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

if a=='H':
	if b=='H':
		print('H')
	else:
		print('D')
else:
	if b=='H':
		print('D')
	else:
		print('H')

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

if a=='H':
	if b=='H':
		print('H')
	else:
		print('D')
else:
	if b=='H':
		print('D')
	else:
		print('H')
Problem p03826 (python)

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

if A*B >= C*D:
	print(A*B)
else:
	print(C*D)

Buggy submission (verdict: Runtime Error):
A, B, C, D = map(list(int, input().split()))

if A*B >= C*D:
	print(A*B)
else:
	print(C*D)
Problem p03962 (python)

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

if a==b and b==c:
	print(1)
elif a!=b and b!=c and c!=a:
	print(3)
else:
	print(2)

Buggy submission (verdict: Runtime Error):
a = int(input())
b = int(input())
c = int(input())

if a==b and b==c:
	print(1)
elif a!=b and b!=c and c!=a:
	print(3)
else:
	print(2)
Problem p02555 (python)

Fixed submission:
import bisect, collections, copy, heapq, itertools, math, string
import sys
def I(): return int(sys.stdin.readline().rstrip())
def MI(): return map(int, sys.stdin.readline().rstrip().split())
def LI(): return list(map(int, sys.stdin.readline().rstrip().split()))
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())

from collections import defaultdict
from collections import deque
import bisect
from decimal import *
from functools import reduce
def main():
    def comb(n, r):
        if r == 0:
            return 1
        else:
            numerator = reduce(lambda x, y: x * y % mod, [n - r + k + 1 for k in range(r)])
            denominator = reduce(lambda x, y: x * y % mod, [k + 1 for k in range(r)])
            return numerator * pow(denominator, mod - 2, mod) % mod
    S = I()
    mod = 10 ** 9 + 7
    N = S // 3
    ans = 0
    for i in range(1, N + 1):
        x = S - 3 * i
        ans += comb(x + i - 1, i - 1)
        ans %= mod
    print(ans)
if __name__ == "__main__":
    main()

Buggy submission (verdict: Runtime Error):
import bisect, collections, copy, heapq, itertools, math, string
import sys
def I(): return int(sys.stdin.readline().rstrip())
def MI(): return map(int, sys.stdin.readline().rstrip().split())
def LI(): return list(map(int, sys.stdin.readline().rstrip().split()))
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())

from collections import defaultdict
from collections import deque
import bisect
from decimal import *
from functools import reduce
def main():
    def comb(n, r):
        numerator = reduce(lambda x, y: x * y % mod, [n - r + k + 1 for k in range(r)])
        denominator = reduce(lambda x, y: x * y % mod, [k + 1 for k in range(r)])
        return numerator * pow(denominator, mod - 2, mod) % mod
    S = I()
    mod = 10 ** 9 + 7
    N = S // 3
    ans = 0
    for i in range(1, N + 1):
        x = S - 3 * i
        ans += comb(x + i - 1, x)
        ans %= mod
    print(ans)
if __name__ == "__main__":
    main()
Problem p02586 (python)

Fixed submission:
import sys
import math
from collections import defaultdict
from collections import deque

sys.setrecursionlimit(1000000)
MOD = 10 ** 9 + 7
input = lambda: sys.stdin.readline().strip()
NI = lambda: int(input())
NMI = lambda: map(int, input().split())
NLI = lambda: list(NMI())
SI = lambda: input()


def main():
    R, C, K = NMI()
    item = [[0] * (C + 1) for i in range(R + 1)]

    for i in range(K):
        r_, c_, v_, = NMI()
        item[r_ - 1][c_ - 1] = v_

    dp = [[[0 for _ in range(C + 2)] for _ in range(R + 2)] for _ in range(4)]

    for i in range(R + 1):
        for j in range(C + 1):
            for k in range(4):
                a = dp[k][i][j]
                v = item[i][j]

                if k == 3:
                    dp[0][i + 1][j] = max(a, dp[0][i + 1][j])
                    continue
                dp[0][i + 1][j] = max(a, a + v, dp[0][i + 1][j])
                dp[k][i][j + 1] = max(a, dp[k][i][j + 1])
                dp[k + 1][i][j + 1] = max(a + v, dp[k + 1][i][j + 1])

    print(max(dp[0][R][C], dp[1][R][C], dp[2][R][C], dp[3][R][C]))

if __name__ == "__main__":
    main()

Buggy submission (verdict: Runtime Error):
import bisect, collections, copy, heapq, itertools, math, string
import sys
def I(): return int(sys.stdin.readline().rstrip())
def MI(): return map(int, sys.stdin.readline().rstrip().split())
def LI(): return list(map(int, sys.stdin.readline().rstrip().split()))
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())

R, C, K = MI()
item = {(0,0):0}

for i in range(K):
    r_, c_, v_, = MI()
    item[(r_ - 1,c_ - 1)] = v_

dp = [[[0 for _ in range(C + 2)] for _ in range(R + 2)] for _ in range(4)]

for i in range(R + 1):
    for j in range(C + 1):
        for k in range(4):
            a = dp[i][j][k]
            if (i,j) in item:
                v = item[(i,j)]
            else:
                v = 0

            if k == 3:
                dp[0][i + 1][j] = max(a, dp[0][i + 1][j])
                continue
            dp[0][i + 1][j] = max(a, a + v, dp[0][i + 1][j])
            dp[k][i][j + 1] = max(a, dp[k][i][j + 1])
            dp[k + 1][i][j + 1] = max(a + v, dp[k + 1][i][j + 1])

print(max(dp[0][R][C], dp[1][R][C], dp[2][R][C], dp[3][R][C]))
Problem p02601 (python)

Fixed submission:
A, B, C = map(int, input().split())
K = int(input())
i_ans = 0
j_ans = 0
for i in range(0,8):
    B_after = B * (2 ** i)
    if B_after > A:
        i_ans = i
        break
B_after = B * (2 ** i_ans)
for j in range(0,8):
    C_after = C * (2 ** j)
    if C_after > B_after:
        j_ans = j
        break
if i_ans + j_ans <=K:
    print('Yes')
else:
    print('No')

Buggy submission (verdict: Runtime Error):
A, B, C = map(int, input().split())
K = int(input())
i_ans = 0
j_ans = 0
for i in range(0,8):
    B_after = B * (2 ** i)
    if B_after > A:
        i_ans = i
        break
B_after = B * (2 ** i_ans)
for j in range(0,8):
    C_after = C * (2 ** j)
    if C_after > B_after:
        j_ans = j
        break
if i_ans + j_ans <=K:
    print('Yes')
else:
    pri