Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
x=int(input())
if(x>=25):
  print("Yes")
 else:
  print("No")

Fixed submission:
x=int(input())
if(x>=30):
  print('Yes')
else:
  print("No")
Buggy python submission (verdict: Runtime Error):
n=int(input())
a=list(map(int,input().split()))
if n==1:
print(a[0])
else:
l=list(map(lambda z:z**2,a)
x=sum(a)
y=sum(l)
t=(x-y)//2
if t>(10**9+7):
       print(t%(10**9+7))
else:
       print(t)


Fixed submission:
n=int(input())
a=list(map(int,input().split()))
l=list(map(lambda z:z**2,a))
x=sum(a)**2
y=sum(l)
t=(x-y)//2
if t>(10**9+7):
       print(t%(10**9+7))
else:
       print(t)

Buggy python submission (verdict: Runtime Error):
n=int(input())
a=list(map(int,input().split()))
l=list(map(lambda z:z**2,a)
x=sum(a)
y=sum(l)
t=(x-y)//2
print(t)


Fixed submission:
n=int(input())
a=list(map(int,input().split()))
l=list(map(lambda z:z**2,a))
x=sum(a)**2
y=sum(l)
t=(x-y)//2
if t>(10**9+7):
       print(t%(10**9+7))
else:
       print(t)

Buggy python submission (verdict: Runtime Error):
n=int(input())
a=list(map(int,input().split()))
if n==1:
print(a[0])
else:
l=list(map(lambda z:z**2,a)
x=sum(a)
y=sum(l)
t=(x-y)//2
print(t)

Fixed submission:
n=int(input())
a=list(map(int,input().split()))
l=list(map(lambda z:z**2,a))
x=sum(a)**2
y=sum(l)
t=(x-y)//2
if t>(10**9+7):
       print(t%(10**9+7))
else:
       print(t)
Buggy python submission (verdict: Runtime Error):
t=int(input())
if t>=30:
  print("Yes")
 else:
  print("No")

Fixed submission:
t=int(input())
if t>=30:
  print("Yes")
else:
  print("No")
Buggy python submission (verdict: Runtime Error):
N,D=map(int,input().split())
l=[]
l1=[]
count=0
for i in range(N):
  x,y=map(int,input().split())
  l.append(x)
  l1append(y)
for i in range(N):
  if (l[i]**2 +l1[i]**2)**0.5 <=D:
    count+=1
print(count)    
  


Fixed submission:
N,D=map(int,input().split())
l=[]
l1=[]
count=0
for i in range(N):
  x,y=map(int,input().split())
  l.append(x)
  l1.append(y)
for i in range(N):
  if (l[i]**2 +l1[i]**2)**0.5 <=D:
    count+=1
print(count)

Buggy python submission (verdict: Runtime Error):
N,D=map(int,input().split())
l=[]
l1=[]
count=0
for i in range(N):
  x,y=map(int,input().split())
  l.append(x)
  l1.append(y)
for i in range(N):
  if (l[i]**2 +l1**2)**0.5 <=D:
    count+=1
print(count)    
  


Fixed submission:
N,D=map(int,input().split())
l=[]
l1=[]
count=0
for i in range(N):
  x,y=map(int,input().split())
  l.append(x)
  l1.append(y)
for i in range(N):
  if (l[i]**2 +l1[i]**2)**0.5 <=D:
    count+=1
print(count)

Buggy python submission (verdict: Runtime Error):
N,D=map(int,input().split())
l=[]
l1=[]
count=0
for i in range(N):
  x,y=map(int,input().split())
  l.append(x)
  l1append(y)
for i in range(N):
  if (l[i]**2 +l1**2)**0.5 <=D:
    count+=1
print(count)    
  

Fixed submission:
N,D=map(int,input().split())
l=[]
l1=[]
count=0
for i in range(N):
  x,y=map(int,input().split())
  l.append(x)
  l1.append(y)
for i in range(N):
  if (l[i]**2 +l1[i]**2)**0.5 <=D:
    count+=1
print(count)
Buggy python submission (verdict: Time Limit Exceeded):
import math
K=int(input())
ans=0

for i in range(1,K+1):
    for j in range(1,K+1):
        for k in range(1,K+1):
            ans+=math.gcd(i,math.gcd(j,k))
print(ans)

Fixed submission:
import math
K=int(input())
ans=0

for i in range(1,K+1):
    for j in range(1,K+1):
        for k in range(1,K+1):
            ans+=math.gcd(i,math.gcd(j,k))
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
S=input()
Q=int(input())
r_count=0
top=[1,2]
tail=[2,1]

for i in range(Q):
    q=list(input().split())
    if q[0]=="1":
        r_count+=1
    else:
        q[1]=int(q[1])
        if q[1]==1:
            q[1]=top[r_count%2]
        else:
            q[1]=tail[r_count%2]
        
        if q[1]==1:
            S=q[2]+S
        else:
            S=S+q[2]
if r_count%2==1:
    print(S[::-1])
else:
    print(S)

Fixed submission:
from collections import deque
S=input()
Q=int(input())
r_count=0
top=[1,2]
tail=[2,1]
S=deque(list(S))

for i in range(Q):
    q=list(input().split())
    if q[0]=="1":
        r_count+=1
    else:
        q[1]=int(q[1])
        if q[1]==1:
            q[1]=top[r_count%2]
        else:
            q[1]=tail[r_count%2]
        
        if q[1]==1:
            S.appendleft(q[2])
        else:
            S.append(q[2])
S=list(S)
if r_count%2==1:
    S.reverse()
print(''.join(S))

Buggy python submission (verdict: Time Limit Exceeded):
S=input()
Q=int(input())

for i in range(Q):
    q=list(input().split())
    if q[0]=="1":
        S=S[::-1]
    elif q[1]=="1":
        S=q[2]+S
    elif q[1]=="2":
        S=S+q[2]
print(S)

Fixed submission:
from collections import deque
S=input()
Q=int(input())
r_count=0
top=[1,2]
tail=[2,1]
S=deque(list(S))

for i in range(Q):
    q=list(input().split())
    if q[0]=="1":
        r_count+=1
    else:
        q[1]=int(q[1])
        if q[1]==1:
            q[1]=top[r_count%2]
        else:
            q[1]=tail[r_count%2]
        
        if q[1]==1:
            S.appendleft(q[2])
        else:
            S.append(q[2])
S=list(S)
if r_count%2==1:
    S.reverse()
print(''.join(S))
Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
S=[]
L=[]
C=[]

for i in range(N):
    S.append(str(input()))

S.sort()
L.append(S[0])
C.append(S.count(S[0]))

for i in range(1,N):
    if S[i]!=S[i-1]:
        L.append(S[i])
        C.append(S.count(S[i]))
count_max=max(C)
for i in range(len(L)):
    if C[i]==count_max:
        print(L[i])

Fixed submission:
N=int(input())
S=[]
L=[]
C=[]

for i in range(N):
    S.append(str(input()))

S.sort()
L.append(S[0])
C.append(1)
cur=0

for i in range(1,N):
    if S[i]!=S[i-1]:
        L.append(S[i])
        C.append(1)
        cur+=1
    else:
        C[cur]+=1
count_max=max(C)
for i in range(len(L)):
    if C[i]==count_max:
        print(L[i])

Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
S=[]
L=[]
C=[]

for i in range(N):
    S.append(str(input()))

S.sort()
L.append(S[0])
C.append(S.count(S[0]))

for i in range(1,N):
    if S[i]!=S[i-1]:
        L.append(S[i])
        C.append(S.count(S[i]))
count_max=max(C)
for i in range(len(L)):
    if C[i]==count_max:
        print(L[i])

Fixed submission:
N=int(input())
S=[]
L=[]
C=[]

for i in range(N):
    S.append(str(input()))

S.sort()
L.append(S[0])
C.append(1)
cur=0

for i in range(1,N):
    if S[i]!=S[i-1]:
        L.append(S[i])
        C.append(1)
        cur+=1
    else:
        C[cur]+=1
count_max=max(C)
for i in range(len(L)):
    if C[i]==count_max:
        print(L[i])
Buggy python submission (verdict: Time Limit Exceeded):
import math
H,N=map(int,input().split())
A=[0 for i in range(N)]
B=[0 for i in range(N)]
dp=[[0 for j in range(H)] for i in range(N)]
for i in range(N):
    A[i],B[i]=map(int,input().split())

for i in range(N):
    for j in range(H):
        if i==0:
            dp[i][j]=B[i]*math.ceil((j+1)/A[i])
        elif j+1<=A[i]:
            dp[i][j]=min(dp[i-1][j],B[i])
        else:
            dp[i][j]=min(dp[i-1][j],dp[i][j-A[i]]+B[i])

print(dp[N-1][H-1])

Fixed submission:
import math
H,N=map(int,input().split())
A=[0 for i in range(N)]
B=[0 for i in range(N)]
dp=[[0 for j in range(H)] for i in range(N)]
for i in range(N):
    A[i],B[i]=map(int,input().split())

for i in range(N):
    for j in range(H):
        if i==0:
            dp[i][j]=B[i]*math.ceil((j+1)/A[i])
        elif j+1<=A[i]:
            dp[i][j]=min(dp[i-1][j],B[i])
        else:
            dp[i][j]=min(dp[i-1][j],dp[i][j-A[i]]+B[i])

print(dp[N-1][H-1])

Buggy python submission (verdict: Time Limit Exceeded):
import math
H,N=map(int,input().split())
A=[]
B=[]
dp=[[0 for j in range(H)] for i in range(N)]
for i in range(N):
    a,b=map(int,input().split())
    A.append(a)
    B.append(b)

for i in range(N):
    for j in range(H):
        if i==0:
            dp[i][j]=B[i]*math.ceil((j+1)/A[i])
        elif j+1<=A[i]:
            dp[i][j]=min(dp[i-1][j],B[i])
        else:
            dp[i][j]=min(dp[i-1][j],dp[i][j-A[i]]+B[i])

print(dp[N-1][H-1])

Fixed submission:
import math
H,N=map(int,input().split())
A=[0 for i in range(N)]
B=[0 for i in range(N)]
dp=[[0 for j in range(H)] for i in range(N)]
for i in range(N):
    A[i],B[i]=map(int,input().split())

for i in range(N):
    for j in range(H):
        if i==0:
            dp[i][j]=B[i]*math.ceil((j+1)/A[i])
        elif j+1<=A[i]:
            dp[i][j]=min(dp[i-1][j],B[i])
        else:
            dp[i][j]=min(dp[i-1][j],dp[i][j-A[i]]+B[i])

print(dp[N-1][H-1])
Buggy python submission (verdict: Runtime Error):
N=int(input())
print((N*(N-1)//2)

Fixed submission:
N=int(input())
print((N*(N-1)//2))
Buggy python submission (verdict: Runtime Error):
import math

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

if __name__=="__main__":
    N,K=map(int,input().split())
    a=1000000007
    result=0

    for i in range(1,K+1):
        result=int(combination(N-K+1,i)*combination(K-1,i-1))
        print(result%a)

Fixed submission:
import math

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

if __name__=="__main__":
    N,K=map(int,input().split())
    a=1000000007
    result=0

    if N==K:
        for i in range(K):
            if i==0:
                print(1)
            else:
                print(0)
    else:
        for i in range(1,K+1):
            if N-K+1-i<0:
                print(0)
            else:
                result=int(combination(N-K+1,i)*combination(K-1,i-1))
                print(result%a)

Buggy python submission (verdict: Runtime Error):
import math

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

if __name__=="__main__":
    N,K=map(int,input().split())
    a=1000000007
    result=0

    for i in range(1,K+1):
        result=combination(N-K+1,i)*combination(K-1,i-1)
        print(result%a)

Fixed submission:
import math

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

if __name__=="__main__":
    N,K=map(int,input().split())
    a=1000000007
    result=0

    if N==K:
        for i in range(K):
            if i==0:
                print(1)
            else:
                print(0)
    else:
        for i in range(1,K+1):
            if N-K+1-i<0:
                print(0)
            else:
                result=int(combination(N-K+1,i)*combination(K-1,i-1))
                print(result%a)
Buggy python submission (verdict: Runtime Error):
import math

def LCM(a,b):
    return a*b/math.gcd(a,b)

if __name__=="__main__":
    A,B,C,D=map(int,input().split())
    lcm=LCM(C,D)
    count=B//C+B//D-B//lcm
    count1=(A-1)//C+(A-1)//D-(A-1)//lcm
    result=B-A+1-count+count1
    print(int(result))

Fixed submission:
import fractions

def LCM(a,b):
    return int(a*b/fractions.gcd(a,b))

if __name__=="__main__":
    A,B,C,D=map(int,input().split())
    lcm=LCM(C,D)
    count=B//C+B//D-B//lcm
    count1=(A-1)//C+(A-1)//D-(A-1)//lcm
    result=B-A+1-count+count1
    print(int(result))

Buggy python submission (verdict: Runtime Error):
import math

def LCM(a,b):
    return a*b/math.gcd(a,b)

if __name__=="__main__":
    A,B,C,D=map(int,input().split())
    lcm=LCM(C,D)
    count=B//C+B//D-B//lcm
    count1=(A-1)//C+(A-1)//D-(A-1)//lcm
    result=B-A+1-count+count1
    print('{}'.format((int(result))))

Fixed submission:
import fractions

def LCM(a,b):
    return int(a*b/fractions.gcd(a,b))

if __name__=="__main__":
    A,B,C,D=map(int,input().split())
    lcm=LCM(C,D)
    count=B//C+B//D-B//lcm
    count1=(A-1)//C+(A-1)//D-(A-1)//lcm
    result=B-A+1-count+count1
    print(int(result))

Buggy python submission (verdict: Runtime Error):
import math

def LCM(a,b):
    return a*b/math.gcd(a,b)

if __name__=="__main__":
    A,B,C,D=map(int,input().split())
    lcm=LCM(C,D)
    count=B//C+B//D-B//lcm
    count1=(A-1)//C+(A-1)//D-(A-1)//lcm
    result=B-A+1-count+count1
    print('{}'.format((int(result))))

Fixed submission:
import fractions

def LCM(a,b):
    return int(a*b/fractions.gcd(a,b))

if __name__=="__main__":
    A,B,C,D=map(int,input().split())
    lcm=LCM(C,D)
    count=B//C+B//D-B//lcm
    count1=(A-1)//C+(A-1)//D-(A-1)//lcm
    result=B-A+1-count+count1
    print(int(result))
Buggy python submission (verdict: Time Limit Exceeded):
def insertionsort(a,A):
    flg=0
    if len(A)>0:
        for i in range(len(A)):
            if A[i][1]==a[1]:
                if A[i][0]>a[1]:
                    A=A[:i]+[a]+A[i:]
                else:
                    A=A[:i+1]+[a]+A[i+1:]
                flg=1
                break
            elif A[i][1]>a[1]:
                A=A[:i]+[a]+A[i:]
                flg=1
                break
    if flg==0:
        A.append(a)
    return A



if __name__ == "__main__":
    N=int(input())
    work=[]

    for i in range(N):
        W=list(map(int,input().split()))
        work=insertionsort(W,work)
    
    result=work[0][0]
    i=0

    while result<=work[i][1]:
        i+=1
        if i<N:
            result+=work[i][0]
        else:
            break
    if i==N:
        print('Yes')
    else:
        print('No')

Fixed submission:
if __name__ == "__main__":
    N=int(input())
    work=[]

    for i in range(N):
        W=list(map(int,input().split()))
        work.append(W)
    
    work.sort(key=lambda x:x[1])
    result=0
    flg=0

    for i in range(N):
        result+=work[i][0]
        if result>work[i][1]:
            flg=1
            break
    
    if flg==1:
        print('No')
    else:
        print('Yes')

Buggy python submission (verdict: Time Limit Exceeded):
def insertionsort(a,A):
    flg=0
    if len(A)>0:
        for i in range(len(A)):
            if A[i][1]==a[1]:
                if A[i][0]>a[1]:
                    A=A[:i]+[a]+A[i:]
                else:
                    A=A[:i+1]+[a]+A[i+1:]
                flg=1
                break
            elif A[i][1]>a[1]:
                A=A[:i]+[a]+A[i:]
                flg=1
                break
    if flg==0:
        A.append(a)
    return A



if __name__ == "__main__":
    N=int(input())
    work=[]

    for i in range(N):
        W=list(map(int,input().split()))
        work=insertionsort(W,work)
    
    result=work[0][0]
    i=0

    while result<=work[i][1]:
        i+=1
        if i<N:
            result+=work[i][0]
        else:
            break
    if i==N:
        print('Yes')
    else:
        print('No')

Fixed submission:
if __name__ == "__main__":
    N=int(input())
    work=[]

    for i in range(N):
        W=list(map(int,input().split()))
        work.append(W)
    
    work.sort(key=lambda x:x[1])
    result=0
    flg=0

    for i in range(N):
        result+=work[i][0]
        if result>work[i][1]:
            flg=1
            break
    
    if flg==1:
        print('No')
    else:
        print('Yes')
Buggy python submission (verdict: Runtime Error):
N,X=map(int,input().split())
L=list(map(int,input().split()))
Di=0
result=0

while Di<=X:
    result+=1
    Di+=L[result-1]
    
print(result)

Fixed submission:
N,X=map(int,input().split())
L=list(map(int,input().split()))
Di=0
result=0

while Di<=X:
    result+=1
    if result==N+1:
        break
    Di+=L[result-1]

print(result)
Buggy python submission (verdict: Runtime Error):
import math

N=int(input())
result=0

for i in range(1,int(math.sqrt(N))+1):
    if N%i==0:
        if i>1 and N%(i-1)==N//(i-1):
            result+=i-1
        if N%i!=N//i:
            if N%(N//i-1)==N//(N//i-1):
                result+=N//i-1
print(result)

Fixed submission:
import math

N=int(input())
result=0
if N==1:
    print(0)
else:
    for i in range(1,int(math.sqrt(N))+1):
        if N%i==0:
            if i>1 and N%(i-1)==N//(i-1):
                result+=i-1
            if N%i!=N//i:
                if N%(N//i-1)==N//(N//i-1):
                    result+=N//i-1
    print(result)
Buggy python submission (verdict: Runtime Error):
a,b,c,d = map(int,input().split())
print(max(a,b)*max(c,d))


Fixed submission:
x = int(input())
if x == 0:
    print('1')
else:
    print('0')
Buggy python submission (verdict: Runtime Error):
s = input()

n = len(str)

ans = 0
for i in range(int(n/2)):
  if s[i] != s[n-i-1]:
    ans += 1
    
print(ans)

Fixed submission:
s = input()

n = len(s)

ans = 0
for i in range(int(n/2)):
  if s[i] != s[n-i-1]:
    ans += 1
    
print(ans)
Buggy python submission (verdict: Runtime Error):
# import numpy as np
import math

A, B, C, D = map(int, input().split())

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

def undivided_under(N, C, D):
    dived_C = N // C
    dived_D = N // D
    dived_lcm = N // lcm(C, D)

    # print(dived_C, dived_D, dived_lcm)

    return(N - dived_C - dived_D + dived_lcm)

# print(A,B,C,D)
# print(undivided_under( B, C, D ))
# print(undivided_under( A-1, C, D ))

print( int( undivided_under(B, C, D) - undivided_under(A-1, C, D)) )


Fixed submission:
# import numpy as np
import fractions

A, B, C, D = map(int, input().split())

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

def undivided_under(N, C, D):
    dived_C = N // C
    dived_D = N // D
    dived_lcm = N // lcm(C, D)

    # print(dived_C, dived_D, dived_lcm)

    return(N - dived_C - dived_D + dived_lcm)

# print(A,B,C,D)
# print(undivided_under( B, C, D ))
# print(undivided_under( A-1, C, D ))

print( int( undivided_under(B, C, D) - undivided_under(A-1, C, D)) )
Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np
N, M = map(int, input().split())
A = np.array(list(map(int, input().split())))

for _ in range(M):
    B, C = map(int, input().split())
    A = np.sort(A)
    A[:B] = np.vectorize(lambda x: max(x, C))(A[:B])

print(np.sum(A))


Fixed submission:
import numpy as np
import heapq as hq
N, M = map(int, input().split())
A = list(map(int, input().split()))

class BC():
    def __init__(self, b, c):
        self.b = b
        self.c = c

    def __eq__(self, other):
        return self.c == other.c    

    def __lt__(self, other):
        return self.c > other.c

    def __ne__(self, other):
        return not self.__eq__(other)

    def __le__(self, other):
        return self.__lt__(other) or self.__eq__(other)

    def __gt__(self, other):
        return not self.__le__(other)

    def __ge__(self, other):
        return not self.__lt__(other)

heap = []
for _ in range(M):
    hq.heappush(heap, BC(*map(int, input().split())) )

result = []
for _ in range(M):
    bc = hq.heappop(heap)
    result.extend([bc.c] * bc.b)

    if len(result) > N:
        break

A.extend(result)
A.sort(reverse=True)
print(np.sum(A[:N]))

Buggy python submission (verdict: Time Limit Exceeded):
N, M = map(int, input().split())
A = list(map(int, input().split()))

for _ in range(M):
    B, C = map(int, input().split())
    A.sort()
    A[:B] = map(lambda x:max(x, C), A[:B])

print(sum(A))


Fixed submission:
import numpy as np
import heapq as hq
N, M = map(int, input().split())
A = list(map(int, input().split()))

class BC():
    def __init__(self, b, c):
        self.b = b
        self.c = c

    def __eq__(self, other):
        return self.c == other.c    

    def __lt__(self, other):
        return self.c > other.c

    def __ne__(self, other):
        return not self.__eq__(other)

    def __le__(self, other):
        return self.__lt__(other) or self.__eq__(other)

    def __gt__(self, other):
        return not self.__le__(other)

    def __ge__(self, other):
        return not self.__lt__(other)

heap = []
for _ in range(M):
    hq.heappush(heap, BC(*map(int, input().split())) )

result = []
for _ in range(M):
    bc = hq.heappop(heap)
    result.extend([bc.c] * bc.b)

    if len(result) > N:
        break

A.extend(result)
A.sort(reverse=True)
print(np.sum(A[:N]))
Buggy python submission (verdict: Time Limit Exceeded):
def main():
    votes = int(input());
    ratio = [[ int(i) for i in input().split() ] for j in range(votes)]

    tak = aok = 0
    for i in range(votes):
        takTemp,  aokTemp = ratio[i][0], ratio[i][1]

        while tak > takTemp or aok > aokTemp:
            takTemp += ratio[i][0]
            aokTemp += ratio[i][1]

        tak, aok = takTemp, aokTemp

        #print("turn:" + str(i))
        #print("votes:" + str(ratio[i][0]) + ":" + str(ratio[i][1]) )
    print(tak + aok)

if __name__ == '__main__':
  main()


Fixed submission:
import math
from decimal import *

def main():
    votes = int(input())
    ratio = [[ int(i) for i in input().split() ] for j in range(votes)]

    votesTemp = [0, 0]
    for i in range(votes):
        if i == 0:
            votesTemp = ratio[i]
            continue

        ceil = [ math.ceil(Decimal(votesTemp[j]) / Decimal(ratio[i][j])) for j in range(2)]

        votesTemp = [ max(ceil) * ratio[i][j] for j in range(2) ]

        """
        print("turn: " + str(i))
        print("votes: " + str(ratio[i][0]) + ":" + str(ratio[i][1]) )
        print("Temp: " +str(votesTemp[0])+":"+str(votesTemp[1]))
        """
    print(sum(votesTemp))

if __name__ == '__main__':
  main()
Buggy python submission (verdict: Time Limit Exceeded):
N, M = map(int, input().split())
A = [0] * M
B = [0] * M
C = [0] * M
for i in range(M):
	A[i], B[i], C[i] = map(int, input().split())
	A[i] -= 1
	B[i] -= 1
inf = 123456789123456789123456789
dist = [ -inf ] * N
dist[0] = 0
bounded = True
for i in range(2 * N):
	for j in range(M):
		if dist[B[j]] < dist[A[j]] + C[j]:
			dist[B[j]] = dist[A[j]] + C[j]
			if B[j] == N - 1 and i >= N:
				bounded = False
if not bounded:
	print("inf")
else:
	print(dist[N - 1])

Fixed submission:
N, M = map(int, input().split())
A = [0] * M
B = [0] * M
C = [0] * M
for i in range(M):
	A[i], B[i], C[i] = map(int, input().split())
	A[i] -= 1
	B[i] -= 1
inf = 123456789123456789123456789
dist = [ -inf ] * N
dist[0] = 0
bounded = True
for i in range(max(2 * N - 3, 4)):
	for j in range(M):
		if dist[B[j]] < dist[A[j]] + C[j]:
			dist[B[j]] = dist[A[j]] + C[j]
			if B[j] == N - 1 and i >= N:
				bounded = False
if not bounded:
	print("inf")
else:
	print(dist[N - 1])
Buggy python submission (verdict: Time Limit Exceeded):
N, W = map(int, input().split())
wlist = [0] * N
vlist = [0] * N
for i in range(N):
	wlist[i], vlist[i] = map(int, input().split())
minw = min(wlist)
w = list()
for i in range(4):
	w.append(list())
for i in range(N):
	w[wlist[i] - minw].append(vlist[i])
for i in range(4):
	w[i].sort(reverse = True)
ans = 0
for i in range(len(w[0]) + 1):
	for j in range(len(w[1]) + 1):
		for k in range(len(w[2]) + 1):
			for l in range(len(w[3]) + 1):
				sumw = 0
				sumv = 0
				for z in range(i):
					sumw += minw
					sumv += w[0][z]
				for z in range(j):
					sumw += minw + 1
					sumv += w[1][z]
				for z in range(k):
					sumw += minw + 2
					sumv += w[2][z]
				for z in range(l):
					sumw += minw + 3
					sumv += w[3][z]
				if sumw <= W:
					ans = max(ans, sumv)
print(ans)

Fixed submission:
N, W = map(int, input().split())
wlist = [0] * N
vlist = [0] * N
for i in range(N):
	wlist[i], vlist[i] = map(int, input().split())
minw = min(wlist)
w = list()
for i in range(4):
	w.append(list())
for i in range(N):
	w[wlist[i] - minw].append(vlist[i])
for i in range(4):
	w[i].sort(reverse = True)
ans = 0
sumw0 = 0
sumv0 = 0
for i in range(len(w[0]) + 1):
	sumw1 = 0
	sumv1 = 0
	for j in range(len(w[1]) + 1):
		sumw2 = 0
		sumv2 = 0
		for k in range(len(w[2]) + 1):
			sumw3 = 0
			sumv3 = 0
			for l in range(len(w[3]) + 1):
				sumw = sumw0 + sumw1 + sumw2 + sumw3
				sumv = sumv0 + sumv1 + sumv2 + sumv3
				if sumw <= W:
					ans = max(ans, sumv)
				if l != len(w[3]):
					sumw3 += minw + 3
					sumv3 += w[3][l]
			if k != len(w[2]):
				sumw2 += minw + 2
				sumv2 += w[2][k]
		if j != len(w[1]):
			sumw1 += minw + 1
			sumv1 += w[1][j]
	if i != len(w[0]):
		sumw0 += minw
		sumv0 += w[0][i]
print(ans)