Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
from itertools import permutations

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

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

for i in range(len(r)):
    r[i]-=1
    
A=[]
a=[]
for i in range(N):
    for j in range(N):
        a.append(1000000)
    A.append(a)
    a=[]
#print(A)

for i in range(M):
    a,b,c=map(int,input().split())
    A[a-1][b-1]=c
    A[b-1][a-1]=c
#print(A)

for c in range(N):
    for a in range(N):
        for b in range(N):
            A[a][b]=min(A[a][b],A[a][c]+A[c][b])
#print(A)

ans=10000000
for i in permutations(r,len(r)):
    cnt=0
    for j in range(len(i)-1):
        cnt+=A[i[j]][i[j+1]]
    if ans>cnt:
        ans=cnt
print(ans)


Fixed submission:
N=input()
if N[0]=="9" or N[1]=="9":
    print("Yes")
else:
    print("No")
Buggy python submission (verdict: Time Limit Exceeded):
import itertools
N,M,R=map(int,input().split())
r=list(map(int,input().split()))

L=[[10**15 for i in range(N)]for j in range(N)]
for i in range(N):
    L[i][i]=0
for a in range(M):
    A,B,C=map(int,input().split())
    L[A-1][B-1]=C
    L[B-1][A-1]=C

#print(L)

for c in range(N):
    for a in range(N):
        for b in range(N):
            L[a][b]=min(L[a][b],L[a][c]+L[c][b])
#print(L)
LIS=list(itertools.permutations(r))
#print(LIS)
ans=10**15
#print(LIS[0][2])
for i in range(len(LIS)):
    cnt=0
    for x in range(1,len(r)):
        #print(i,x)
        cnt+=L[LIS[i][x-1]-1][LIS[i][x]-1]
    if cnt<ans:
        ans=cnt
print(ans)

Fixed submission:
import itertools
N,M,R=map(int,input().split())
r=list(map(int,input().split()))

L=[[10**15 for i in range(N)]for j in range(N)]
for i in range(N):
    L[i][i]=0
for a in range(M):
    A,B,C=map(int,input().split())
    L[A-1][B-1]=C
    L[B-1][A-1]=C

#print(L)

for c in range(N):
    for a in range(N):
        for b in range(N):
            L[a][b]=min(L[a][b],L[a][c]+L[c][b])
#print(L)
LIS=list(itertools.permutations(r))
#print(LIS)
ans=10**15
#print(LIS[0][2])
for i in range(len(LIS)):
    cnt=0
    for x in range(1,len(r)):
        #print(i,x)
        cnt+=L[LIS[i][x-1]-1][LIS[i][x]-1]
    if cnt<ans:
        ans=cnt
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
from itertools import permutations

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

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

for i in range(len(r)):
    r[i]-=1
    
A=[]
a=[]
for i in range(N):
    for j in range(N):
        a.append(1000000)
    A.append(a)
    a=[]
#print(A)

for i in range(M):
    a,b,c=map(int,input().split())
    A[a-1][b-1]=c
    A[b-1][a-1]=c
#print(A)

for c in range(N):
    for a in range(N):
        for b in range(N):
            A[a][b]=min(A[a][b],A[a][c]+A[c][b])
#print(A)

ans=10000000
for i in permutations(r,len(r)):
    cnt=0
    for j in range(len(i)-1):
        cnt+=A[i[j]][i[j+1]]
    if ans>cnt:
        ans=cnt
print(ans)


Fixed submission:
import itertools
N,M,R=map(int,input().split())
r=list(map(int,input().split()))

L=[[10**15 for i in range(N)]for j in range(N)]
for i in range(N):
    L[i][i]=0
for a in range(M):
    A,B,C=map(int,input().split())
    L[A-1][B-1]=C
    L[B-1][A-1]=C

#print(L)

for c in range(N):
    for a in range(N):
        for b in range(N):
            L[a][b]=min(L[a][b],L[a][c]+L[c][b])
#print(L)
LIS=list(itertools.permutations(r))
#print(LIS)
ans=10**15
#print(LIS[0][2])
for i in range(len(LIS)):
    cnt=0
    for x in range(1,len(r)):
        #print(i,x)
        cnt+=L[LIS[i][x-1]-1][LIS[i][x]-1]
    if cnt<ans:
        ans=cnt
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
C=list(map(int,input().split()))

C.sort(reverse=True)

W=0
for j in range(len(C)):
    if C[j]==W:
        pass
    elif C.count(C[j])>=4:
        if W==0:
            
            print(C[j]*C[j])
            exit()
        else:
            print(W*C[j])
            exit()
    elif C.count(C[j])>=2:
        if W==0:
            W=C[j]
        else:
            print(W*C[j])
            exit()
print(0)

Fixed submission:
import collections
N=int(input())
A=list(map(int,input().split()))
AC=collections.Counter(A)
AM=AC.most_common()
AM.sort(reverse=True)
#print(AM)
H=0
for i in range(len(AM)):
    if H==0:
        if AM[i][1]>=4:
            print(AM[i][0]**2)
            exit()
        elif AM[i][1]>=2:
            H=AM[i][0]
    else:
        if AM[i][1]>=2:
            
            print(AM[i][0]*H)
            exit()
print(0)
Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
list1=[]
L=list(map(int,input().split()))
L.sort(reverse=True)
cnt=1
for i in range(N-1):
    if L[i]!=L[i+1]:
        list1.append([L[i],L.count(L[i])])
list1.append([L[len(L)-1],L.count(L[len(L)-1])])
#print(list1)     
H=0
i=0
for i in range(len(list1)):
    if list1[i][1]>=4:
        if H==0:
            print(list1[i][0]**2)
            exit()
        else:
            print(H*list1[i][0])
            exit()
    elif list1[i][1]>=2:
        if H==0:
            H=list1[i][0]
        else:
            print(H*list1[i][0])
            exit()
print(0)

Fixed submission:
from collections import Counter
N=int(input())
A=list(map(int,input().split()))
B=Counter(A)
#print(B)      
C=list(B.items())
C.sort(reverse=True)
#print(C)

H=0
W=0
for i in range(len(C)):
    if H==0:
        if C[i][1]>=4:
            print(C[i][0]**2)
            exit()
        elif C[i][1]>=2:
            H=C[i][0]
    else:
        if C[i][1]>=2:
            print(H*C[i][0])
            exit()
print(0)
Buggy python submission (verdict: Runtime Error):
N=int(input())
T=int(input())
gcd=100000000000000000000000
for i in range(N-1):
    T1=int(input())
    A=max(T,T1)
    B=min(T,T1)
    for j in range(1000000000000):
        
        if A%B==0:
            gcd=B
            
            break
        else:
            C=A%B
            if C>B:
                A=C
            else:
                B=C
print(T1*T/gcd)
            


Fixed submission:
import fractions
N=int(input())
LCM=int(input())
for i in range(N-1):
    T=int(input())
    LCM=LCM*T//fractions.gcd(LCM,T)
print(LCM)
Buggy python submission (verdict: Time Limit Exceeded):
import sys
sys.setrecursionlimit(1000000)

N=int(input())
n=[[]for i in range(N+1)]

for i in range(N-1):
    a,b,c=map(int,input().split())
    n[a].append([b,c])
    n[b].append([a,c])
    
L=[-1 for i in range(N+1)]

Q,K=map(int,input().split())

L[K]=0

def dfs(x):
    for i in n[x]:
        if L[i[0]]==-1:
            L[i[0]]=L[x]+i[1]
            dfs(i[0])
dfs(K)
#print(n)
#print(L)

for i in range(Q):
    x,y=map(int,input().split())
    print(L[x]+L[y])

Fixed submission:
import sys
sys.setrecursionlimit(1000000)

N=int(input())
n=[[]for i in range(N+1)]

for i in range(N-1):
    a,b,c=map(int,input().split())
    n[a].append([b,c])
    n[b].append([a,c])
    
L=[-1 for i in range(N+1)]

Q,K=map(int,input().split())

L[K]=0

def dfs(x):
    for i in n[x]:
        if L[i[0]]==-1:
            L[i[0]]=L[x]+i[1]
            dfs(i[0])
dfs(K)
#print(n)
#print(L)

for i in range(Q):
    x,y=map(int,input().split())
    print(L[x]+L[y])

Buggy python submission (verdict: Runtime Error):
N=int(input())
n=[[]for i in range(N+1)]

for i in range(N-1):
    a,b,c=map(int,input().split())
    n[a].append([b,c])
    n[b].append([a,c])
    
L=[-1 for i in range(N+1)]

Q,K=map(int,input().split())

L[K]=0

def dfs(x):
    for i in n[x]:
        if L[i[0]]==-1:
            L[i[0]]=L[x]+i[1]
            dfs(i[0])
dfs(K)
#print(n)
#print(L)

for i in range(Q):
    x,y=map(int,input().split())
    print(L[x]+L[y])

Fixed submission:
import sys
sys.setrecursionlimit(1000000)

N=int(input())
n=[[]for i in range(N+1)]

for i in range(N-1):
    a,b,c=map(int,input().split())
    n[a].append([b,c])
    n[b].append([a,c])
    
L=[-1 for i in range(N+1)]

Q,K=map(int,input().split())

L[K]=0

def dfs(x):
    for i in n[x]:
        if L[i[0]]==-1:
            L[i[0]]=L[x]+i[1]
            dfs(i[0])
dfs(K)
#print(n)
#print(L)

for i in range(Q):
    x,y=map(int,input().split())
    print(L[x]+L[y])
Buggy python submission (verdict: Time Limit Exceeded):
N,M=map(int,input().split())
L1=[]
LN=[]
for i in range(M):
    a,b=map(int,input().split())
    if a==1:
        if b in LN:
            print("POSSIBLE")
            exit()
        else:
            L1.append(b)
    elif b==N:
        if a in L1:
            print("POSSIBLE")
            exit()
        else:
            LN.append(a)
print("IMPOSSIBLE")

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

Start=[]
Goal=[]

for i in range(M):
    a,b=map(int,input().split())
    if a==1:
        Start.append(b)
    elif b==1:
        Start.append(a)
    if a==N:
        Goal.append(b)
    elif b==N:
        Goal.append(a)
    
S=set(Start)
G=set(Goal)
if len(S&G)>0:
    print("POSSIBLE")
elif len(S&G)==0:
    print("IMPOSSIBLE")
Buggy python submission (verdict: Runtime Error):
from collections import Counter

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

L=[]
for i in range(N):
    A=list(map(int,input().split()))
    L.append(A)
    
OUTD=dict()
S=[0 for i in range(M)]

ANS=1000
for i in range(M):
    B=[0 for _ in range(N)]
    for j in range(N):
        for k in range(S[j],M):
            '''if L[j][k] in OUTD:
                S[j]+=1
            else:
                B[j]=L[j][k]
                break'''
            if L[j][k] in OUTD:
                S[j]+=1
            else:
                B[j]=L[j][k]
                break
    X=Counter(B).most_common()[0]
    if X[1]<ANS:
        ANS=X[1]
    OUTD[X[0]]=1
    #print(ANS,B,OUTD)
print(ANS)

Fixed submission:
from collections import Counter

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

L=[]
for i in range(N):
    A=list(map(int,input().split()))
    L.append(A)
    
OUTD=dict()
S=[0 for i in range(N)]

ANS=1000
for i in range(M):
    B=[0 for _ in range(N)]
    for j in range(N):
        for k in range(S[j],M):
            if L[j][k] in OUTD:
                S[j]+=1
            else:
                B[j]=L[j][k]
                break
    X=Counter(B).most_common()[0]
    if X[1]<ANS:
        ANS=X[1]
    OUTD[X[0]]=1
    #print(ANS,B,OUTD)
print(ANS)

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

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

L=[]
for i in range(N):
    A=list(map(int,input().split()))
    L.append(A)
    
OUTD=dict()
S=[0 for i in range(M)]

ANS=1000
for i in range(M):
    B=[0 for _ in range(N)]
    for j in range(N):
        for k in range(S[j],M):
            if L[j][k] in OUTD:
                S[j]+=1
            else:
                B[j]=L[j][k]
                break
    X=Counter(B).most_common()[0]
    if X[1]<ANS:
        ANS=X[1]
    OUTD[X[0]]=1
    #print(ANS,B,OUTD)
print(ANS)

Fixed submission:
from collections import Counter

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

L=[]
for i in range(N):
    A=list(map(int,input().split()))
    L.append(A)
    
OUTD=dict()
S=[0 for i in range(N)]

ANS=1000
for i in range(M):
    B=[0 for _ in range(N)]
    for j in range(N):
        for k in range(S[j],M):
            if L[j][k] in OUTD:
                S[j]+=1
            else:
                B[j]=L[j][k]
                break
    X=Counter(B).most_common()[0]
    if X[1]<ANS:
        ANS=X[1]
    OUTD[X[0]]=1
    #print(ANS,B,OUTD)
print(ANS)
Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
import sys
input=sys.stdin.readline
X=[[-10**10,0]]
Y=[[-10**10,0]]

for i in range(N):
    x,y=map(int,input().split())
    X.append([x,i+1])
    Y.append([y,i+1])
X.append([10**10,N+1])
Y.append([10**10,N+1])
X.sort()
Y.sort()

#print(X,Y)

L=[[]for i in range(N+1)]
for i in range(1,N+1):
    L[X[i][1]].append([X[i][0]-X[i-1][0],X[i-1][1]])
    L[X[i][1]].append([X[i+1][0]-X[i][0],X[i+1][1]])
for i in range(1,N+1):
    L[Y[i][1]].append([Y[i][0]-Y[i-1][0],Y[i-1][1]])
    L[Y[i][1]].append([Y[i+1][0]-Y[i][0],Y[i+1][1]])
#print(L)
C=[1 for i in range(N+2)]
C[0]=0
C[-1]=0
C[1]=0
import heapq
ans=0
Q=L[1]
heapq.heapify(Q)
for i in range(10**6):
    #print(ans,Q)
    #print(C)
    if len(Q)==0:
        break
    q=heapq.heappop(Q)
    if C[q[1]]==0:
        continue
    else:
        C[q[1]]=0
        ans+=q[0]
        for j in range(4):
            if C[L[q[1]][j][1]]==1:
                heapq.heappush(Q,L[q[1]][j])
print(ans)

Fixed submission:
N=int(input())
import sys
input=sys.stdin.readline
X=[(-10**10,0)]
Y=[(-10**10,0)]

for i in range(N):
    x,y=map(int,input().split())
    X.append((x,i+1))
    Y.append((y,i+1))
X.append((10**10,N+1))
Y.append((10**10,N+1))
X.sort()
Y.sort()

#print(X,Y)

L=[[]for i in range(N+1)]
for i in range(1,N+1):
    L[X[i][1]].append((X[i][0]-X[i-1][0],X[i-1][1]))
    L[X[i][1]].append((X[i+1][0]-X[i][0],X[i+1][1]))
for i in range(1,N+1):
    L[Y[i][1]].append((Y[i][0]-Y[i-1][0],Y[i-1][1]))
    L[Y[i][1]].append((Y[i+1][0]-Y[i][0],Y[i+1][1]))
#print(L)
C=[1 for i in range(N+2)]
C[0]=0
C[-1]=0
C[1]=0
import heapq
ans=0
Q=L[1]
heapq.heapify(Q)
for i in range(10**6):
    #print(ans,Q)
    #print(C)
    if len(Q)==0:
        break
    q=heapq.heappop(Q)
    if C[q[1]]==0:
        continue
    else:
        C[q[1]]=0
        ans+=q[0]
        for j in range(4):
            if C[L[q[1]][j][1]]==1:
                heapq.heappush(Q,L[q[1]][j])
print(ans)
Buggy python submission (verdict: Runtime Error):
if B==0 and 0>A:
    print(abs(A))
elif B>=A and A>=0:
    print(B-A)
elif B>=0 and 0>=A:
    if abs(B)>=abs(A):
        print(abs(B)-abs(A)+1)
    else:
        print(abs(A)-abs(B)+1)
elif 0>=B and B>=A:
    print(abs(A)-abs(B))
    
elif A>B and B>=0:
    print(A-B+2)
elif A>=0 and 0>=B:
    if abs(A)>=abs(B):
        print(abs(A)-abs(B)+1)
    else:
        print(abs(B)-abs(A)+1)
elif 0>=A and A>=B:
    print(abs(B)-abs(A)+2)

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

if B==0 and 0>A:
    print(abs(A))
elif B==0 and A>0:
    print(abs(A)+1)
elif B>=A and A>=0:
    print(B-A)
elif B>=0 and 0>=A:
    if abs(B)>=abs(A):
        print(abs(B)-abs(A)+1)
    else:
        print(abs(A)-abs(B)+1)
elif 0>=B and B>=A:
    print(abs(A)-abs(B))
    
elif A>B and B>=0:
    print(A-B+2)
elif A>=0 and 0>=B:
    if abs(A)>=abs(B):
        print(abs(A)-abs(B)+1)
    else:
        print(abs(B)-abs(A)+1)
elif 0>=A and A>=B:
    print(abs(B)-abs(A)+2)
Buggy python submission (verdict: Runtime Error):
N=int(input())
if N%2==0:
    L=[]
    for i in range(int(N/2)):
        L.append(i*2+1)
        L.append(i*2+1)
        
else:
    L=[0]
    for i in range(1,int((N-1)/2)+1):
        L.append(i*2)
        L.append(i*2)

A=list(map(int,input().split()))
A.sort()

if A==L:
    if N%2==0:
        ans=1
        for j in range(int(N/2)):
            ans*=2
            ans%=(10**9+7)
        print(ans)
    else:
        ans=1
        for j in range(int(N-1)/2):
            ans*=2
            ans%=(10**9+7)
        print(ans)
else:
    print(0)



Fixed submission:
N=int(input())
if N%2==0:
    L=[]
    for i in range(int(N/2)):
        L.append(i*2+1)
        L.append(i*2+1)
        
else:
    L=[0]
    for i in range(1,int((N-1)/2)+1):
        L.append(i*2)
        L.append(i*2)

A=list(map(int,input().split()))
A.sort()

if A==L:
    if N%2==0:
        ans=1
        for j in range(int(N/2)):
            ans*=2
            ans%=(10**9+7)
        print(ans)
    else:
        ans=1
        for j in range(int((N-1)/2)):
            ans*=2
            ans%=(10**9+7)
        print(ans)
else:
    print(0)

Buggy python submission (verdict: Runtime Error):
N=int(input())
if N%2==0:
    L=[]
    for i in range(int(N/2)):
        L.append(i*2+1)
        L.append(i*2+1)
        
else:
    L=[0]
    for i in range(1,int((N-1)/2)+1):
        L.append(i*2)
        L.append(i*2)

A=list(map(int,input().split()))
A.sort()

if A==L:
    if N%2==0:
        print(int(2**(N/2)%(10**9+7)))
    else:
        print(int(2**((N-1)/2)%(10**9+7)))
else:
    print(0)



Fixed submission:
N=int(input())
if N%2==0:
    L=[]
    for i in range(int(N/2)):
        L.append(i*2+1)
        L.append(i*2+1)
        
else:
    L=[0]
    for i in range(1,int((N-1)/2)+1):
        L.append(i*2)
        L.append(i*2)

A=list(map(int,input().split()))
A.sort()

if A==L:
    if N%2==0:
        ans=1
        for j in range(int(N/2)):
            ans*=2
            ans%=(10**9+7)
        print(ans)
    else:
        ans=1
        for j in range(int((N-1)/2)):
            ans*=2
            ans%=(10**9+7)
        print(ans)
else:
    print(0)

Buggy python submission (verdict: Runtime Error):
N=int(input())
if N%2==0:
    L=[]
    for i in range(int(N/2)):
        L.append(i*2+1)
        L.append(i*2+1)
        
else:
    L=[0]
    for i in range(1,int((N-1)/2)+1):
        L.append(i*2)
        L.append(i*2)

A=list(map(int,input().split()))
A.sort()

if A==L:
    if N%2==0:
        print(int(2**(N/2)))
    else:
        print(int(2**((N-1)/2)))
else:
    print(0)



Fixed submission:
N=int(input())
if N%2==0:
    L=[]
    for i in range(int(N/2)):
        L.append(i*2+1)
        L.append(i*2+1)
        
else:
    L=[0]
    for i in range(1,int((N-1)/2)+1):
        L.append(i*2)
        L.append(i*2)

A=list(map(int,input().split()))
A.sort()

if A==L:
    if N%2==0:
        ans=1
        for j in range(int(N/2)):
            ans*=2
            ans%=(10**9+7)
        print(ans)
    else:
        ans=1
        for j in range(int((N-1)/2)):
            ans*=2
            ans%=(10**9+7)
        print(ans)
else:
    print(0)
Buggy python submission (verdict: Runtime Error):
N=int(input())
T=list(map(int,input().split()))
A=list(map(int,input().split()))

if T[N-1]!=A[0]:
    print(0)
elif N==1:
    print(1)
else:
    
    L=[[T[0],0]]
    for i in range(1,N):
        if T[i]==T[i-1]:
            L.append([T[i],1])
        else:
            L.append([T[i],0])
    #print(L)
            
    if L[len(L)-1][0]>A[len(L)-1]:
        L[len(L)-1]=[A[len(L)-1],0]
    else:
        L[len(L)-1][1][0]
    
    for i in range(1,N):
        if L[len(L)-1-i][0]>=A[len(L)-1-i]:
            L[len(L)-1-i][0]=A[len(L)-1-i]
            if A[len(L)-1-i]==A[len(L)-i]:
               pass
            else:
                L[len(L)-1-i][1]=0
            if L[len(L)-1-i][0]>L[len(L)-i][0]:
                L[len(L)-1-i][1]=0
    #print(L)
    ans=1
    for i in range(len(L)):
        if L[i][1]==1:
            ans*=L[i][0]
            ans%=(10**9+7)
    print(ans)

Fixed submission:
N=int(input())
T=list(map(int,input().split()))
t=[1]
for i in range(1,N):
    if T[i]!=T[i-1]:
        t.append(1)
    else:
        t.append(T[i])
    if T[i]<T[i-1]:
        print(0)
        exit()
A=list(map(int,input().split()))
A=A[::-1]
a=[1]
for i in range(1,N):
    if A[i]!=A[i-1]:
        a.append(1)
    else:
        a.append(A[i])
    if A[i]<A[i-1]:
        print(0)
        exit()
A=A[::-1]
a=a[::-1]
#print(t)
#print(a)
M=max(A)

for i in range(N):
    if T[i]==M:
        if A[i]==M:
            break
        else:
            print(0)
            exit()

for i in range(N):
    if A[N-1-i]==M:
        if T[N-1-i]==M:
            break
        else:
            print(0)
            exit()
ans=1
mod=(10**9+7)
for i in range(N):
    ans*=min(t[i],a[i])
    ans%=mod
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
import bisect
N=int(input())
A=list(map(int,input().split()))
B=[i+1 for i in range(N)]

C=[]
for i in range(N):
    C.append([A[i],B[i]])
C.sort()

L=[0,N+1]

ans=0

#print(C)
for i in range(N):
    ans+=C[i][0]*(L[bisect.bisect_right(L,C[i][1])]-C[i][1])*(C[i][1]-L[bisect.bisect_left(L,C[i][1])-1])
    L.insert(bisect.bisect_left(L,C[i][1]),C[i][1])
    #print(ans,L)
#print(L)
print(ans)

Fixed submission:
import sys
sys.setrecursionlimit(1000000)

N=int(input())
a=list(map(int,input().split()))

b=[i for i in range(1,N+1)]

A=[]
for i in range(N):
    A.append([a[i],b[i]])
A.sort(reverse=True)
#print(A)
PL=[i for i in range(N+1)]+[N+1]
PR=[i for i in range(N+1)]+[N+1]

def findL(x):
    if x==PL[x]:
        return x
    else:
        return findL(PL[x])
        
def findR(x):
    if x==PR[x]:
        return x
    else:
        return findR(PR[x])
#print(PR)
ans=0
for i in range(N):
    ans+=A[i][0]*(A[i][1]-findL(A[i][1]-1))*(findR(A[i][1]+1)-A[i][1])
    #print(ans,A[i][1],(A[i][1]-findL(A[i][1])+1),findR(A[i][1])-A[i][1]+1)
    #print(PR)
    PL[A[i][1]]=findL(A[i][1]-1)
    PR[A[i][1]]=findR(A[i][1]+1)
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import bisect
N=int(input())
A=list(map(int,input().split()))
B=[i+1 for i in range(N)]

C=[]
for i in range(N):
    C.append([A[i],B[i]])
C.sort()

L=[0,N+1]

ans=0

#print(C)
for i in range(N):
    ans+=C[i][0]*(L[bisect.bisect_right(L,C[i][1])]-C[i][1])*(C[i][1]-L[bisect.bisect_left(L,C[i][1])-1])
    L.insert(bisect.bisect_left(L,C[i][1]),C[i][1])
    #print(ans,L)
#print(L)
print(ans)

Fixed submission:
import sys
sys.setrecursionlimit(1000000)

N=int(input())
a=list(map(int,input().split()))

b=[i for i in range(1,N+1)]

A=[]
for i in range(N):
    A.append([a[i],b[i]])
A.sort(reverse=True)
#print(A)
PL=[i for i in range(N+1)]+[N+1]
PR=[i for i in range(N+1)]+[N+1]

def findL(x):
    if x==PL[x]:
        return x
    else:
        return findL(PL[x])
        
def findR(x):
    if x==PR[x]:
        return x
    else:
        return findR(PR[x])
#print(PR)
ans=0
for i in range(N):
    ans+=A[i][0]*(A[i][1]-findL(A[i][1]-1))*(findR(A[i][1]+1)-A[i][1])
    #print(ans,A[i][1],(A[i][1]-findL(A[i][1])+1),findR(A[i][1])-A[i][1]+1)
    #print(PR)
    PL[A[i][1]]=findL(A[i][1]-1)
    PR[A[i][1]]=findR(A[i][1]+1)
print(ans)
Buggy python submission (verdict: Runtime Error):
input=sys.stdin.readline
import math
pi=math.pi
def calcAngle(h,m): 
    if (h == 12): 
        h = 0
    if (m == 60): 
        m = 0
    hour_angle = 0.5 * (h * 60 + m) 
    minute_angle = 6 * m 
    angle = abs(hour_angle - minute_angle) 
    angle = min(360 - angle, angle) 
    return angle
A,B,H,M=map(int,input().split())
angle=calcAngle(H,M)
t= A*A + B*B - 2*A*B*math.cos(((math.pi)/180)*(angle))
print("{0:.15f}".format(t**0.5))

Fixed submission:
import math
pi=math.pi
def calcAngle(h,m): 
    if (h == 12): 
        h = 0
    if (m == 60): 
        m = 0
    hour_angle = 0.5 * (h * 60 + m) 
    minute_angle = 6 * m 
    angle = abs(hour_angle - minute_angle) 
    angle = min(360 - angle, angle) 
    return angle
A,B,H,M=map(int,input().split())
angle=calcAngle(H,M)
t= A*A + B*B - 2*A*B*math.cos(((math.pi)/180)*(angle))
print("{0:.15f}".format(t**0.5))
Buggy python submission (verdict: Runtime Error):
if N=="ABC":
    print("ARC")
else:
    print("ABC")

Fixed submission:
N=input()
if N=="ABC":
    print("ARC")
else:
    print("ABC")
Buggy python submission (verdict: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
int A[101],B[101],C[101],D[101];
int ans;
int N,M,Q;
void dfs(vector<int> v)
{
    // cout<<" hi"<<"";
    if(v.size()==N)
    {
        int sum=0;
        for(int i=0;i<Q;i++)
        {
            if (v[B[i]-1]-v[A[i]-1]==C[i])
            {
                sum+=D[i];
            }
        }
        ans=max(ans,sum);
    }
    else
    {
        for(int i=v[v.size()-1];i<=M;i++)
        {
            vector<int> n=v;
            n.push_back(i);
            dfs(n);
        }
    }
}
int main() 
{  
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    ans=INT_MIN;
    cin>>N>>M>>Q;
    for(int i=0;i<Q;i++)
    {
        cin>>A[i]>>B[i]>>C[i]>>D[i];
    }
    for(int i=1;i<=M;i++)
    {
        vector<int> v;
        v.push_back(i);
        dfs(v);
    }
    cout<<ans<<" ";
}

Fixed submission:
K=int(input())
N,M=map(int,input().split())
FLAG=0
for i in range(1000):
    if K*i>=N and K*i<=M:
        print("OK")
        FLAG=1
        break
if FLAG==0:
    print("NG")