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

Fixed submission:
from fractions import gcd
a,b,c,d = map(int,input().split())
ans = b - a + 1#ok
a -= 1#ok

g = gcd(c,d)
temp = c*d//g

cc = -int(a//c) + int(b//c)
dd = -int(a//d) + int(b//d)
cd = -int(a//temp) + int(b // temp)

print(ans - cc - dd + cd)

Buggy submission (verdict: Runtime Error):
from math import gcd
a,b,c,d = map(int,input().split())
ans = b - a + 1#ok
a -= 1#ok

g = gcd(c,d)
temp = c*d/g
cc = -int(a/c) + int(b/c)
dd = -int(a/d) + int(b/d)
cd = -int(a/temp) + int(b / temp)

if c == 1 or d == 1:
    print(0)
else:
    print(ans - cc - dd + cd)

Buggy submission (verdict: Runtime Error):
from math import gcd
a,b,c,d = map(int,input().split())
ans = b - a + 1#ok
a -= 1#ok

g = gcd(c,d)
n = c / g
m = d / g
temp = n*m*g

ans -= -int(a/c) + int(b/c)
ans -= -int(a/d) + int(b/d)
ans += -int(a/temp) + int(b / temp)

print(int(ans))
Problem p03001 (python)

Fixed submission:
w,h,x,y = map(int,input().split())
if w/2 == x and h/2 == y:
  print(w*h/2,1)
else:
  print(w*h/2,0)

Buggy submission (verdict: Runtime Error):
W,H,x,y = map(int,input().split())
temp1 = [(W-x)*H,x*H]
temp2 = [W*y,W*(H-y)]

ans = max(min(temp1),min(temp2))
if  (W/2 == x and H/2 == y):
    print(W*H/2,1)
elif H/W == y/x:
    print(W*H/2,0)
elif x == 0 or x == W or y == 0 or y == H:
    print(W*H/2,0)
elif min(temp1) == min(temp2):
    print(ans,1)
else:
    print(ans,0)
Problem p03006 (python)

Fixed submission:
N = int(input())
XY = {}
for i in range(N):
    x,y = map(int,input().split())
    XY[(x,y)] = 1
dis = {}

ans = N

for x,y in XY.keys():
    for xx,yy in XY.keys():
        if x != xx or y != yy:
            temp = (xx-x,yy-y)
            if not(temp in dis):
                dis[temp] = 1

for p,q in dis:
    test = 0
    copy = XY.copy()
    for x,y in copy:
            if (x+p,y+q) in copy.keys():
                test += 1
    if N - test < ans:
        ans = N - test
print(ans)

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

cost = N
from operator import itemgetter
XY.sort(key = itemgetter(0))
dic = {}

for i in range(N-1):
    xx,yy = XY[i]
    x,y = XY[i+1]
    temp = (x-xx,y-yy)
    if temp in dic:
        dic[temp] += 1
    else:
        dic[temp] = 1

print(cost - max(dic.values()))
Problem p03014 (python)

Fixed submission:
def main():
    H,W = map(int,input().split())
    S = [[1 if s == "." else 0 for s in input()] for _ in range(H)]

    if H == 1:
        for w in range(1,W):
            if S[0][w] and S[0][w - 1]:
                S[0][w] += S[0][w - 1]
        print(max(S[0]))
        return
    if W == 1:
        ans = 0
        for h in range(1,H):
            if S[h][0] and S[h-1][0]:
                S[h][0] += S[h - 1][0]
                ans = max(ans,S[h][0])
        print(ans)
        return


    R = [[0]*W for _ in range(H)]
    L = [[0]*W for _ in range(H)]
    D = [[0]*W for _ in range(H)]
    U = [[0]*W for _ in range(H)]

    for h in range(H):
        for w in range(1,W - 1):
            if S[h][w] and S[h][w - 1]:
                L[h][w] += L[h][w - 1] + 1
            if S[h][W - w] and S[h][W - w - 1]:
                R[h][W - w - 1] += R[h][W - w] + 1
        if S[h][W -1] and S[h][W - 2]:
            L[h][W - 1] += L[h][W - 2] + 1
        if S[h][0] and S[h][1]:
            R[h][0] += R[h][1] + 1
    for w in range(W):
        for h in range(1,H-1):
            if S[h-1][w] and S[h][w]:
                U[h][w] += U[h-1][w] + 1
            if S[H - h][w] and S[H - h - 1][w]:
                D[H - h - 1][w] += D[H - h][w] + 1
        if S[H - 1][w] and S[H - 2][w]:
            D[H - 1][w] += D[H-2][w] + 1
        if S[0][w] and S[1][w]:
            U[0][w] += U[1][w] + 1
    ans = 0
    for h in range(H):
        for w in range(W):
            ans = max(ans,U[h][w] + D[h][w] + R[h][w] + L[h][w])
    print(ans + 1)
    return 

if __name__ == "__main__":
    main()

Buggy submission (verdict: Runtime Error):
def main():
    H,W = map(int,input().split())
    S = [[1 if s == "." else 0 for s in input()] for _ in range(H)]
    R = [[0]*W for _ in range(H)]
    L = [[0]*W for _ in range(H)]
    D = [[0]*W for _ in range(H)]
    U = [[0]*W for _ in range(H)]

    for h in range(H):
        for w in range(1,W - 1):
            if S[h][w] and S[h][w - 1]:
                L[h][w] += L[h][w - 1] + 1
            if S[h][W - w] and S[h][W - w - 1]:
                R[h][W - w - 1] += R[h][W - w] + 1
        if S[h][W -1] and S[h][W - 2]:
            L[h][W - 1] += L[h][W - 2] + 1
        if S[h][0] and S[h][1]:
            R[h][0] += R[h][1] + 1
    for w in range(W):
        for h in range(1,H-1):
            if S[h-1][w] and S[h][w]:
                U[h][w] += U[h-1][w] + 1
            if S[H - h][w] and S[H - h - 1][w]:
                D[H - h - 1][w] += D[H - h][w] + 1
        if S[H - 1][w] and S[H - 2][w]:
            D[H - 1][w] += D[H-2][w] + 1
        if S[0][w] and S[1][w]:
            U[0][w] += U[1][w] + 1
    ans = 0
    for h in range(H):
        for w in range(W):
            ans = max(ans,U[h][w] + D[h][w] + R[h][w] + L[h][w])
    print(ans + 1)
    return 

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

Fixed submission:
from math import ceil,log2

def main():
    N = int(input())
    UVW = [list(map(int,input().split())) for _ in range(N - 1)]
    edge = [[] for _ in range(N + 1)]
    dis = {}
    for u,v,w in UVW:
        edge[u].append(v)
        edge[v].append(u)
        dis[(u,v)] = w
        dis[(v,u)] = w
    cnt = 0
    queue = [1]
    gone = {1:0}
    while cnt < N:
        node = queue[cnt]
        for e in edge[node]:
            if e not in gone:
                if dis[(node,e)]%2 == 1:
                    gone[e] = (gone[node] + 1)%2
                else:
                    gone[e] = gone[node]
                queue.append(e)
        cnt += 1
    for i in range(1,N + 1):
        print(gone[i])
    return
if __name__ == "__main__":
    main()

Buggy submission (verdict: Runtime Error):
n = int(input())
UVW = []
UF = [[0,0] for _ in range(n+1)]
for i in range(n-1):
    u,v,w = map(int,input().split())
    UF[v][0] = u
    UF[v][1] = w

def search(UF,loc):
    if UF[loc][0] == loc:
        return UF[loc]
    else:
        UF[loc] = search(UF,UF[loc])
        return UF[loc]
print(0)
for i in range(2,n+1):
    if search(UF,2)[1]%2 == 1:
        print(1)
    else:
        print(0)

Buggy submission (verdict: Runtime Error):
n = int(input())
edge = [[] for _ in range(n+1)]
node = [0]*(n+1)
distance = {}
for _ in range(n-1):
    u,v,w = map(int,input().split())
    edge[u].append(v)
    distance[str(u)+"&"+str(v)] = w

stack = edge[1]
now = 1
while True:
    if len(stack) == 0:
        break
    temp = stack[-1]
    stack.pop(-1)
    for e in edge[temp]:
        stack.append(e)
    if distance[str(now)+"&"+str(temp)]%2 == 1:
        node[temp] = 1
    now = temp
print(*node[1:],sep ="\n")
Problem p03061 (python)

Fixed submission:
n = int(input())
A = list(map(int,input().split()))
A.sort()
def find(inte):
    re = []
    for i in range(1,int(inte**0.5)+1):
        if inte%i==0:
            re.append(i)
            if i != inte/i:
                re.append(int(inte/i))
    return set(re)
if n==2:
    print(A[1])
else:
    a1 = find(A[0])
    a2 = find(A[1])
    a3 = find(A[2])
    t1 = a1 & a2
    t2 = a2 & a3
    t3 = a1 & a3
    cond = t1 | t2 |t3
    maxi = 0
    for con in cond:
        count = 0
        flag = True
        for a in A:
            if a%con != 0:
                count +=1
            if count >= 2:
                
                flag = False
                break
        if flag and maxi < con:
            maxi = con
    print(maxi)

Buggy submission (verdict: Runtime Error):
from fraction import gcd
n = int(input())
A = list(map(int,input().split()))
left = [0]*(n+1)
right = [0]*(n+2)
for a,aa,i in zip(A,A[::-1],range(1,n+1)):
    left[i] = gcd(a,left[i-1])
    right[n+1-i] = gcd(aa,right[n-i+2])
ans = 1
for i in range(1,n+1):
    if i ==1:
        if ans < right[i+1]:
            ans = right[i+1]
    elif i == n:
        if ans < left[i-1]:
            ans = left[i-1]
    else:
        if ans < gcd(left[i-1],right[i+1]):
            ans = gcd(left[i-1],right[i+1])

print(ans)
Problem p03129 (python)

Fixed submission:
nk=[int(x) for x in input().split()]
if(nk[0]>=2*nk[1]-1):
    print("YES")
else:
    print("NO")

Buggy submission (verdict: Runtime Error):
k,a,b=[int(p) for p in input().split()]
if(a+2>=b or (k)/(a+2)<1 or 2*a+2==b):
    print(k+1)
elif(2*a+2>b):
    print(1+k+(int((1+k)/(2*a-b+2)))*(b-a-2))
else:
    print(1+k+(int((1+k-a)/2))*(b-a-2))

Buggy submission (verdict: Runtime Error):
k,a,b=[int(p) for p in input().split()]
if(a+2>=b or k/(a+2)<1 or 2*a+2==b):
    print(k+1)
elif(2*a+2>b):
    print(1+k+(int((1+k)/(2*a-b+2)))*(b-a-2))
else:
    print(1+k+(int((1+k-a)/2))*(b-a-2))
Problem p03166 (python)

Fixed submission:
N,M = map(int,input().split())
edge = { i:[] for i in range(1,N+1)}
for _ in range(M):
    x,y = map(int,input().split())
    edge[x] += [y]
import sys 

sys.setrecursionlimit(10**5+1)
dp = [-1]*(N+1)
def distance(start):
    if dp[start] > 0:
        return dp[start]
    elif len(edge[start]) == 0:
        dp[start] = 0
        return 0
    else:
        temp = [distance(e) + 1 for e in edge[start]]
        dp[start] =  max(temp)
        return dp[start]

for i in range(1,N+1):
    go = distance(i)
print(max(dp))

Buggy submission (verdict: Runtime Error):
N,M = map(int,input().split())
edge = { i:[] for i in range(1,N+1)}
for _ in range(M):
    x,y = map(int,input().split())
    edge[x] += [y]

dp = [-1]*(N+1)
def distance(start):
    if dp[start] > 0:
        return dp[start]
    elif len(edge[start]) == 0:
        dp[start] = 0
        return 0
    else:
        temp = [distance(e) + 1 for e in edge[start]]
        dp[start] =  max(temp)
        return dp[start]

for i in range(1,N+1):
    go = distance(i)
print(max(dp))
Problem p03200 (python)

Fixed submission:
S = [1 if(_ =="B") else 0 for _ in input()]+[1]
ans = 0
if(S.index(1) == len(S)-1):
    print(0)
else:
    S.pop(-1)
    first = S.index(1)
    count = first
    start = first
    for s in S[start:]:
        if(s == 0):
            ans += count -first
            first += 1
        count += 1
    print(ans)

Buggy submission (verdict: Runtime Error):
S = [1 if(_ =="B") else 0 for _ in input()]
ans = 0
first = S.index(1)
count = first
start = first
for s in S[start:]:
    if(s == 0):
        ans += count -first
        first += 1
    count += 1
print(ans)
Problem p03206 (python)

Fixed submission:
eve="Christmas"
for x in range(25,int(input()),-1):
	eve += " Eve"
print(eve)

Buggy submission (verdict: Runtime Error):
eve="Christmas"
for x in range(input()):
	eve += "Eve"
print(eve)
Problem p03240 (python)

Fixed submission:
n = int(input())
XYH = []

for _ in range(n):
    x,y,h = map(int,input().split())
    if h != 0:
        XYH.append([x,y,h])

flag = False
ans = XYH[0]
for i in range(101):
    for j in range(101):
        tempH = abs(XYH[0][0] - i) + abs(XYH[0][1] - j) + XYH[0][2]
        for x,y,h in XYH[1:]:
            if abs(x - i) + abs(y - j) + h != tempH:
                flag = False
                break
            else:
                flag = True
        if flag:
            ans = [i,j,tempH]
            break
    if flag:
        break

print(*ans,sep = " ")

Buggy submission (verdict: Runtime Error):
n = int(input())
XYH = [list(map(int,input().split())) for _ in range(n)]
flag = False
for i in range(101):
    for j in range(101):
        tempH = abs(XYH[0][0] - i) + abs(XYH[0][1] - j) + XYH[0][2] 
        for x,y,h in XYH[1:]:
            if abs(x - i) + abs(y - j) + h != tempH:
                flag = False
                break
            else:
                flag = True
        if flag:
            ans = [i,j,tempH]
            break
    if flag:
        break

print(*ans,sep = " ")
Problem p03241 (python)

Fixed submission:
n,m = map(int,input().split())
def getDivisor(inte):
    Ans1 = [1]
    Ans2 = [inte]
    for i in range(2,int(inte**(0.5))):
        if inte % i == 0:
            Ans1.append(i)
            Ans2.append(int(inte/i))
    if inte % inte**(0.5) == 0:
        Ans1.append(int(int(inte**(0.5))))
    Ans = Ans1 + Ans2[::-1]
    return Ans

limit = int(m/n)
for i in reversed(getDivisor(m)):
    if i <= limit:
        print(i)
        break

Buggy submission (verdict: Runtime Error):
nm=[int(x) for x in input().split()]
temp=[]
for x in range(1,int(nm[1]/nm[0])):
    if(nm[1]%x==0):
        temp.append(x)
print(int(max(temp)))
Problem p03262 (python)

Fixed submission:
n,x = map(int,input().split())
X = list(map(int,input().split()))
sort_X = sorted(X)
temp = sort_X[0]
mini = float("inf")
D = 1
if(n==1):
    print(abs(X[0]-x))
elif(n==2):
    mini = min(X[-1]-x,x-X[0])

    for p in range(1,mini+1):
        point = x%p
        flag = True
        for xx in X:
            if(point != xx%p):
                    flag = False
                    break
        if(flag):
            D = p
    print(D)

else:
    for xx in sort_X[1:]:
        if(mini >= xx-temp):
            mini = xx-temp
        temp = xx
    for p in range(1,mini+1):
        point = x%p
        flag = True
        for xx in X:
            if(point != xx%p):
                    flag = False
                    break
        if(flag):
            D = p

    print(D)

Buggy submission (verdict: Runtime Error):
n,x = map(int,input().split())
X = list(map(int,input().split()))
sort_X = sorted(X)
temp = sort_X[0]
mini = X[-1]-X[0]
D = 1
if(n==1):
    print(999999999)
elif(n==2):
    print(mini)
else:
    for xx in sort_X[1:]:
        if(mini >= xx-temp):
            mini = xx-temp
        temp = xx
    for p in range(1,mini+1):
        point = x%p
        flag = True
    for xx in X:
        if(point != xx%p):
                flag = False
                break
    if(flag):
        D = p

    print(D)

Buggy submission (verdict: Runtime Error):
n,x = map(int,input().split())
X = list(map(int,input().split()))
sort_X = sorted(X)
temp = sort_X[0]
mini = float("inf")
D = 1
for xx in sort_X[1:]:
    if(mini >= xx-temp):
        mini = xx-temp
    temp = xx
for p in range(1,mini+1):
    point = x%p
    flag = True
    for xx in X:
        if(point != xx%p):
                flag = False
                break
    if(flag):
        D = p
if(n==1):
    print(999999999)
else:
    print(D)
Problem p03274 (python)

Fixed submission:
n,k = map(int,input().split())
X = list(map(int,input().split()))
from bisect import bisect_left as bl
zero = bl(X,0)

temp = []
for i in range(max(zero,k-1),min(zero+k,n)):
    if X[i-k+1] >= 0:
        temp.append(X[i])
    elif X[i] <= 0:
        temp.append(abs(X[i-k+1]))
    else:
        temp.append(min(abs(X[i]),abs(X[i-k+1]))*2+max(abs(X[i]),abs(X[i-k+1])))
try:
        print(min(temp))
except:
        print(abs(X[-k]))

Buggy submission (verdict: Runtime Error):
n,k = map(int,input().split())
X = list(map(int,input().split()))
from bisect import bisect_left as bl
zero = bl(X,0)
ans = 0

temp = []
for i in range(max(zero,k-1),min(zero+k,n)):
    
    if X[i-k+1] >= 0:
        temp.append(X[i])
    elif X[i] <= 0:
        temp.append(abs(X[i-k+1]))
    else:
        temp.append(min(abs(X[i]),abs(X[i-k+1]))*2+max(abs(X[i]),abs(X[i-k+1])))
print(min(temp))
Problem p03283 (python)

Fixed submission:
n,m,qq = map(int,input().split())
PQ = []
LR = [[_+1,0]+list(map(int,input().split())) for _ in range(m)]

for i in range(qq):
    p,q = map(int,input().split())
    PQ.append([i+1,1,p,q+0.1])
record = [0]*(n+1)
Ans = []

All = LR+PQ
from operator import itemgetter
All.sort(key = itemgetter(3))

for num,flag ,l, r in All:
    if flag :
        Ans.append([num,sum(record[l:int(r+1)])])
    else:
        record[l] += 1
Ans.sort(key = itemgetter(0))
for ans in Ans:
    print(ans[1])

Buggy submission (verdict: Runtime Error):
from operator import itemgetter
n,m,q = map(int,input().split())
LR = [[-1]+list(map(int,input().split())) for _ in range(m)]
PQ = [[_]+list(map(int,input().split())) for _ in range(q)]

Ans = [0]*501
section = LR + PQ
section.sort(key = itemgetter(2))

l = [0]*501
for x,y,z in section:
    if x == -1:
        l[y] += 1
    else:
        Ans[x] = sum(l[y:z+1])

for ans in Ans:
    if ans >= 1:
        print(ans)

Buggy submission (verdict: Runtime Error):
n,m,q = map(int,input().split())
import numpy as np
LR = np.full((500,500),0)
Ans = []
for _ in range(m):
    x,y = map(int,input().split())
    LR[x][y] += 1

def portionsum(List,x,y):#List must be 2-demension,x>y
    re = 0
    for l in range(x,y+1):
        re += sum(List[l][x:y+1])
    return re

for i in range(q):
    p,q = map(int,input().split())
    Ans.append(portionsum(LR,p,q))
for _ in Ans:
    print(_)
Problem p03353 (python)

Fixed submission:
s=input()
k=int(input())
s_list=[]
for p in range(len(s)):
    for q in range(min(5,len(s[p:]))):
        if(not(s_list.__contains__(s[p:p+q+1]))):
                s_list.append(s[p:p+q+1])
s_list_sort=sorted(s_list)
print(s_list_sort[k-1])

Buggy submission (verdict: Runtime Error):
n=int(input())
h=[int(x) for x in input().split()]
cost=[0]
cost.append(abs(h[0]-h[1]))
for p in range(2,n):
    cost.append(min(cost[p-1]+abs(h[p]-h[p-1]),abs(h[p]-h[p-2])+cost[p-2]))
print(cost)
print(cost[n-1])
Problem p03380 (python)

Fixed submission:
n = int(input())
A = list(map(int,input().split()))
aj = max(A)
temp = 10000000000
for a in A:
    if a != aj:
        if temp > abs(int(aj/2+0.5)-a):
            ai = a
            temp = abs(int(aj/2+0.5)-a)
            
print(aj,ai)

Buggy submission (verdict: Runtime Error):
n = int(input())
A = list(map(int,input().split()))
aj = max(A)
temp = 100000
for a in A:
    if a != aj:
        if temp > abs(int(aj/2+0.5)-a):
            ai = a
            temp = abs(int(aj/2+0.5)-a)
            
print(aj,ai)
Problem p03409 (python)

Fixed submission:
n = int(input())
AB = [[0]+list(map(int,input().split())) for _ in range(n)]
CD = [list(map(int,input().split())) for _ in range(n)]
from operator import itemgetter

points = AB.copy()
for c,d in CD:
    points.append([1,c,max(0,d-0.1)])
points.sort(key = itemgetter(2))

ans = 0
record = [0]*(2*n+1)
for flag, x, y in points:
    if flag:
        for i in range(x-1,-1,-1):
            if record[i] > 0:
                ans += 1
                record[i] -= 1
                break
    else:
        record[x] += 1
print(ans)

Buggy submission (verdict: Runtime Error):
n = int(input())
AB = [[0]+list(map(int,input().split())) for _ in range(n)]
CD = [list(map(int,input().split())) for _ in range(n)]
from operator import itemgetter
points = AB.copy()
for c,d in CD:
    points.append([1,c+0.1,d+0.1])
points.sort(key = itemgetter(1))
points.sort(key = itemgetter(2))

ans = 0
record = [0]*(2*n+1)
for flag, x, y in points:
    if flag:
        ans += sum(record[x:y])
    else:
        record[x] += 1
print(ans)

Buggy submission (verdict: Runtime Error):
n = int(input())
AB = [[0]+list(map(int,input().split())) for _ in range(n)]
CD = [[1]+list(map(int,input().split())) for _ in range(n)]
from operator import itemgetter
points = AB.copy()
for c,d in CD:
    points.append([c+0.1,d+0.1])
points.sort(key = itemgetter(2))
points.sort(key = itemgetter(1))
temp = 0
ans = 0
for flag, x, y in points:
    if flag:
        if temp > 0:
            ans += 1
            temp -= 1
    else:
        temp += 1
print(ans)
Problem p03480 (python)

Fixed submission:
S = input()
length = len(S)
temp = []
for i in range(1,length):
    if S[i] != S[i-1]:
        temp.append(max(i , length - i))
if len(temp) == 0:
    print(length)
else:
    print(min(temp))

Buggy submission (verdict: Runtime Error):
S = input()
length = len(S)
temp = []
for i in range(1,length):
    if S[i] != S[i-1]:
        temp.append(max(i , length - i))
print(min(temp))
Problem p03608 (python)

Fixed submission:
n,m,rrr = map(int,input().split())
R = tuple(map(int,input().split()))
ABC = [list(map(int,input().split())) for _ in range(m)]
inf = 1000000000

edge = [[inf]*(n+1) for _ in range(n+1)]

for a,b,c in ABC:
    edge[a][b] = c
    edge[b][a] = c
    
def dijkstra(start,e,N):
    for _ in range(3):
        for v in range(1,N+1):#中間
            for g in range(1,N+1):#ゴール
                e[start][g] = min(e[start][g],e[start][v] + e[v][g])
                e[g][start] = e[start][g]
    return e[start]

dic = {}
for rr in R:
    dic[rr] = dijkstra(rr,edge,n)

from itertools import permutations as pm

temp = list(pm(R))

ans = 10000000000
for RR in temp:
    cost = 0
    for i in range(rrr-1):
        cost += dic[RR[i]][RR[i+1]]
    if cost < ans:
        ans = cost
print(ans)

Buggy submission (verdict: Runtime Error):
n,m,r = map(int,input().split())
R = tuple(map(int,input().split()))
ABC = [list(map(int,input().split())) for _ in range(m)]
inf = 1000000000

edge = [[inf]*(n+1) for _ in range(n+1)]

for a,b,c in ABC:
    edge[a][b] = c
    edge[b][a] = c
    
def dijkstra(start,e,N):
    for v in range(1,N+1):#中間
        for g in range(1,N+1):#ゴール
            e[start][g] = min(e[start][g],e[start][v] + e[v][g])
            e[g][start] = e[start][g]
    return e[start]

cost = 0
dic = {}
for r in R:
    dic[r] = dijkstra(r,edge,n)

from itertools import permutations as pm

temp = list(pm(R))

ans = 10000000000
for RR in temp:
    cost = 0
    for i in range(r-2):
        cost += dic[RR[i]][RR[i+1]]
    if cost < ans:
        ans = cost

print(ans)
Problem p03722 (python)

Fixed submission:

def Bellman_Ford(node_num:int,start:int,goal:int,VWC:list)->list:
    Ans = [float("inf")]*(node_num + 1)
    node = start
    Ans[start] = 0        
    for _ in range(node_num-1):
        for v,w,c in VWC:
            Ans[w] = min(Ans[w], Ans[v] + c)
    Pre = list(Ans)
    for _ in range(node_num-1):
        for v,w,c in VWC:
            Ans[w] = min(Ans[w], Ans[v] + c)
    if Ans[goal] == Pre[goal]:
        return Ans[goal]
    else:
        return float("inf")
def main():
    N,M = map(int,input().split())
    ABC = [list(map(int,input().split())) for _ in  range(M)]
    newABC = [[a,b,-c] for a,b,c in ABC]
    ans = Bellman_Ford(N,1,N,newABC)
    print(-ans if ans < float("inf") else "inf")
    return


if __name__ == "__main__":
    main()

Buggy submission (verdict: Runtime Error):
from math import ceil,log2

def Bellman_Ford(node_num:int,start:int,VWC:list)->list:
    Ans = [float("inf")]*(node_num + 1)
    node = start
    Ans[start] = 0
    changeable = {}
    for v,w,c in VWC:
        if v not in changeable:
            changeable[v] = True
        if w not in changeable:
            changeable[w] = True
        
    for _ in range(node_num-1):
        for v,w,c in VWC:
            Ans[w] = min(Ans[w], Ans[v] + c)
    Pre = Ans.copy()
    for _ in range(2*(node_num-1)):
        for v,w,c in VWC:
            Ans[w] = min(Ans[w], Ans[v] + c)
    for node in changeable.keys():
        if Ans[node] == Pre[node]:
            return Ans
    return [float("inf")]*(node_num + 1)

def main():
    N,M = map(int,input().split())
    ABC = [list(map(int,input().split())) for _ in  range(M)]
    newABC = [[a,b,-c] for a,b,c in ABC]
    Ans1 = Bellman_Ford(N,1,newABC)
    print("inf" if Ans1[N] == float("inf") else -Ans1[N])
    return
if __name__ == "__main__":
    main()
Problem p03945 (python)

Fixed submission:
S = input()
count = 0
temp = S[-1]
for s in S[-2::-1]:
    if s != temp:
        count += 1
    temp = s
print(0 if count == 0 else count)

Buggy submission (verdict: Runtime Error):
S = input()
count = 0
temp = S[-1]
for s in S[-2::-1]:
    if s != temp:
        count += 1
    temp = s
print(0 if count == 0 else temp-1)