Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
S = [int(_) for _ in input()]
length = 0
x =0
flag = True
if(len(S) == 1):
    flag = False
while(flag):
    x += 1

    if(S[x]+S[x-1] == 1):
        S.pop(x)
        S.pop(x-1)
        length += 2
        x=0
   
    if(x >= len(S)-1):
        break

print(length)
        

Fixed submission:
S = [int(_) for _ in input()]
length = len(S)
temp = [S[0]]
for x in S[1:]:
    if(len(temp) == 0):
        temp.append(x)
    elif( temp[-1] == x):
        temp.append(x)
    else:
        temp.pop(-1)
print(length-len(temp))
Buggy python 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))

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

Buggy python 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))

Fixed submission:
nk=[int(x) for x in input().split()]
if(nk[0]>=2*nk[1]-1):
    print("YES")
else:
    print("NO")
Buggy python 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))

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 python submission (verdict: Time Limit Exceeded):
def main():
    N = int(input())
    P = list(map(float,input().split()))
    f = [[0]*(N + 1) for _ in range(N + 1)]
    f[0][0] = 1 - P[0]
    f[0][1] = P[0]
    for i in range(1,N):
        p = P[i]
        f[i][0] = f[i - 1][0]*(1 - p)
        for j in range(1,i + 2):
            f[i][j] += p*f[i - 1][j - 1] + (1 - p)*f[i - 1][j]
    print(sum(f[N - 1][N //2 + 1:]))
    return

if __name__ == "__main__":
    main()

Fixed submission:
from math import ceil
def main():
    N = int(input())
    P = list(map(float,input().split()))
    f = [[0]*(N + 1) for _ in range(N + 1)]
    f[0][0] = 1 - P[0]
    f[0][1] = P[0]
    for i in range(1,N):
        p = P[i]
        f[i][0] = f[i - 1][0]*(1 - p)
        for j in range(max(1,ceil((N + 1)/2) - N + i - 3),i + 2):
            f[i][j] += p*f[i - 1][j - 1] + (1 - p)*f[i - 1][j]
    print(sum(f[N - 1][N //2 + 1:]))
    return

if __name__ == "__main__":
    main()
Buggy python submission (verdict: Runtime Error):
a=[int(x) for x in input().split()]
if(a[0]+a[1]>a[2]):
  print(a[1]+a[2])
elif:
  print(a[1]+a[2]-abs(a[0]+a[1]-a[2]))

Fixed submission:
a=[int(x) for x in input().split()]
if(a[0]+a[1]>=a[2]):
  print(a[1]+a[2])
else:
  print(2*a[1]+a[0]+1)
Buggy python 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)

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 python submission (verdict: Runtime Error):
eve="Christmas"
for x in range(input()):
	eve += "Eve"
print(eve)

Fixed submission:
eve="Christmas"
for x in range(25,int(input()),-1):
	eve += " Eve"
print(eve)
Buggy python 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 = " ")            
                
            

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 python submission (verdict: Time Limit Exceeded):
n,m = map(int,input().split())

limit = int(m/n)
ans = 1
for i in range(limit,1,-1):
    if m%i == 0:
        ans = i
        break
print(ans)

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 python 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)))

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 python submission (verdict: Time Limit Exceeded):
nm=[int(x) for x in input().split()]
temp=[]
for x in range(1,int(nm[1]/nm[0])+1):
    if(nm[1]%x==0 and (nm[1]/x)>=nm[0]):
        temp.append(x)
print(int(max(temp)))

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 python submission (verdict: Runtime Error):
a,b,c = input().split()
print(max(int(a+b)+int(c),int(b+c)+int(a))

Fixed submission:
A = list(map(int,input().split()))
A.sort()
print(A[2]*10 + A[1]+A[0])
Buggy python 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)



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 python 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)



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 python 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))

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 python 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)

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 python 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(_)

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 python submission (verdict: Time Limit Exceeded):
n=int(input())
s=input()
num_s=[]
value=[]
for f_s in s:
    if(f_s=="E"):
        num_s.append(0)
    else:
        num_s.append(1)
for n in range(len(s)):
    value.append(sum(num_s[:n])+abs(sum(num_s[n:])-len(num_s[n:])))
print(min(value))

Fixed submission:
n=int(input())
s=input()
num_s=[]
value=[]
left=0
for f_s in s:
    if(f_s=="E"):
        num_s.append(0)
    else:
        num_s.append(1)
right=sum(num_s[1:])
len_s=n-1
value.append(len_s-right)
for p in range(1,n):
    left+=num_s[p-1]
    right-=num_s[p]
    len_s-=1
    value.append(left+len_s-right)
print(min(value))
Buggy python 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])

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 python 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)

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 python 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)
    

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 python 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)
    

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 python submission (verdict: Time Limit Exceeded):
n,y = map(int,input().split())

flag = False

yki = min(n,y//10000)
for i in range(yki+1):
    for j in range(y-i+1):
        nogu = n -i - j
        if nogu*1000 + i*10000 + j*5000 == y and nogu >= 0:
            ans = [i,j,nogu]
            flag = True
            break
    if flag:
        break

if flag:
    print(*ans,sep = " ")
else:
    print(-1,-1,-1)

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

flag = False

yki = min(n,y//10000)
for i in range(yki+1):
    for j in range(n-i+1):
        nogu = n -i - j
        if nogu*1000 + i*10000 + j*5000 == y and nogu >= 0:
            ans = [i,j,nogu]
            flag = True
            break
    if flag:
        break

if flag:
    print(*ans,sep = " ")
else:
    print(-1,-1,-1)
Buggy python 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))

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 python submission (verdict: Time Limit Exceeded):
import bisect as bi
n = int(input())
kariA = list(map(int,input().split()))
kariB = list(map(int,input().split()))
kariC = list(map(int,input().split()))
A = sorted(kariA)
B = sorted(kariB)
C = sorted(kariC)
count = 0
for c in C:
    for b in B[:bi.bisect_left(B,c)]:
            count += bi.bisect_left(A,b)
    
print(count)

Fixed submission:
import bisect as bi
n = int(input())
kariA = list(map(int,input().split()))
kariB = list(map(int,input().split()))
kariC = list(map(int,input().split()))
A = sorted(kariA)
B = sorted(kariB)
C = sorted(kariC)
count = 0
Clength = len(C)
for b in B:
    count += bi.bisect_left(A,b)*(Clength - bi.bisect_right(C,b))
print(count)
Buggy python submission (verdict: Time Limit Exceeded):
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 wf(e,n):
    for s in range(1,n+1):
        for g in range(1,n+1):
            for k in range(1,n+1):
                e[s][g] = min(e[s][g],e[s][k] + e[k][g])
                e[g][s] = e[s][g]
    return e
    


from itertools import permutations as pm

temp = list(pm(R))

ans = 10000000000
Edge = wf(edge,n)

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

print(ans)

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 python 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)

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 python 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()

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()