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

Fixed submission:
N=int(input())
A=list(map(int,input().split()))
l=[[] for _ in range(3)]
ans=1
p=10**9+7
flag=1
for i in range(N):
    cnt=0
    piv=A[i]
    ind=[]
    for j in range(3):
        if len(l[j])==piv:
            cnt=cnt+1
            ind.append(j)
    if len(ind)==0:
        flag=0
        break
    l[ind[0]].append(piv)
    ans=(ans*cnt)%p
    #print(l,ans)
    #input()
if flag==1:
    print(ans%p)
else:
    print(flag)

Buggy submission (verdict: Runtime Error):
#from math import *
N=int(input())
A=list(map(int,input().split()))
l=[0 for _ in range(3)]
ans=1
p=10**9+7
for i in range(N):
    cnt=0
    piv=A[i]
    ind=[]
    for j in range(3):
        if l[j]==piv:
            cnt=cnt+1
            ind.append(j)
    l[ind[0]]=l[ind[0]]+1
    ans=(ans*cnt)%p
    #print(l,ans)
    #input()
print(ans%p)

Buggy submission (verdict: Runtime Error):
#from math import *
N=int(input())
A=list(map(int,input().split()))
l=[[],[],[]]
ans=1
p=10**9+7
for i in range(N):
    cnt=0
    piv=A[i]
    ind=[]
    for j in range(3):
        if len(l[j])==piv:
            cnt=cnt+1
            ind.append(j)
    l[ind[0]].append(piv)
    ans=(ans*cnt)%p
    #print(l,ans)
    #input()
print(ans)

Buggy submission (verdict: Runtime Error):
from math import *
N=int(input())
A=list(map(int,input().split()))
l=[[],[],[]]
ans=1
p=10**9+7
for i in range(N):
    cnt=0
    piv=A[i]
    ind=[]
    for j in range(3):
        if len(l[j])==piv:
            cnt=cnt+1
            ind.append(j)
    l[ind[0]].append(piv)
    ans=(ans*cnt)%p
    #print(l,ans)
    #input()
print(ans)
Problem p02975 (python)

Fixed submission:
import collections
N=int(input())
a=list(map(int,input().split()))
l=[]
if max(a)==0:
    print("Yes")
elif (N%3)==0:
    c=collections.Counter(a)
    values = list(c.values())  # aのCollectionのvalue値のリスト(n_1こ、n_2こ…)
    key = list(c.keys())  # 先のvalue値に相当する要素のリスト(要素1,要素2,…)
    for i in range(len(key)):
        l.append([key[i], values[i]])  # lは[要素i,n_i]の情報を詰めたmatrix
    l.sort(key=lambda x:x[1],reverse=True)
    #print(l)
    if (len(l)==3)and(l[0][1]==l[1][1]==l[2][1])and(l[0][0]^l[1][0]==l[2][0]):
        print("Yes")
    elif (len(l)==2)and(l[0][1]==2*l[1][1])and(l[1][0]==0):
        print("Yes")
    else:
        print("No")
else:
    print("No")

Buggy submission (verdict: Runtime Error):
import collections
N=int(input())
a=list(map(int,input().split()))
l=[]
if max(a)==0:
    print("Yes")
elif (N%3)==0:
    c=collections.Counter(a)
    values = list(c.values())  # aのCollectionのvalue値のリスト(n_1こ、n_2こ…)
    key = list(c.keys())  # 先のvalue値に相当する要素のリスト(要素1,要素2,…)
    for i in range(len(key)):
        l.append([key[i], values[i]])  # lは[要素i,n_i]の情報を詰めたmatrix
    l.sort(key=lambda x:x[1],reverse=True)
    #print(l)
    if ((len(l)==3)and(l[0][1]==l[0][2]==l[0][3])and(l[0]^l[1]==l[2])):
        print("Yes")
    elif (len(l)==2)and(l[0][1]==2*l[1][1])and(l[1][0]==0):
        print("Yes")
    else:
        print("No")
else:
    print("No")

Buggy submission (verdict: Runtime Error):
N=int(input())
a=list(map(int,input().split()))
if N==3:
    if a[0]^a[1]==a[2]:
        print("Yes")
    else:
        print("No")
    input()
else:
    if max(a)==0:
        print("Yes")
    else:
        print("No")
Problem p02996 (python)

Fixed submission:
N=int(input())
task=[list(map(int,input().split())) for _ in range(N)]
time=0
flag=1
task.sort(lambda x:x[1])
#print(task)
for i in range(N):
    time=time+task[i][0]
    if not(time<=task[i][1]):
        flag=0
        break
if flag==1:
    print("Yes")
else:
    print("No")

Buggy submission (verdict: Runtime Error):
N=int(input())
task=[list(map(int,input().split())) for _ in range(N)]
time=0
flag=1
task.sort(lambda x:x[1])
#print(task)
for i in range(N):
    time=time+task[i][0]
    if not(time<=task[i][1]):
        flag=0
        break
if flag==1:
    print("Yes")
else:
    print("No")
Problem p03060 (python)

Fixed submission:
N=int(input())
V=list(map(int,input().split()))
C=list(map(int,input().split()))
dif=[]
count=0
for i in range(N):
    dif.append(int(V[i]-C[i]))

dif.sort(reverse=True)

i=0
for i in range(N):
    if dif[i]>=0:
        count=count+dif[i]
    else:
        break

print(count)

Buggy submission (verdict: Runtime Error):
N=int(input())
V=list(map(int,input().split()))
C=list(map(int,input().split()))
dif=[]
count=0
for i in range(N):
    dif.append(int(V[i]-C[i]))

dif.sort(reverse=True)

i=0
while (dif[i]>=0)and(i<=N-1):
    count=count+dif[i]
    i=i+1

print(count)

Buggy submission (verdict: Runtime Error):
N=int(input())
V=list(map(int,input().split()))
C=list(map(int,input().split()))
dif=[]
count=0
for i in range(N):
    dif.append(V[i]-C[i])

dif.sort(reverse=True)

i=0
while (dif[i]>=0)and(i<=N-1):
    count=count+dif[i]
    i=i+1

print(count)

Buggy submission (verdict: Runtime Error):
N=int(input())
V=list(map(int,input().split()))
C=list(map(int,input().split()))
dif=[]
count=0
for i in range(N):
    dif.append(V[i]-C[i])

dif.sort(reverse=True)

i=0
while dif[i]>=0:
    count=count+dif[i]
    i=i+1

print(count)

Buggy submission (verdict: Runtime Error):
import numpy as np

N=int(input())
V=np.array(list(map(int,input().split())))
C=np.array(list(map(int,input().split())))
bit=[]
max=0
for i in range(2**N):
    bit=np.array([int(bin((i & (1 << j)) >> j), 0)  for j in range(N)])
    X=np.dot(V,bit)
    Y=np.dot(C,bit)
    if max<X-Y:
        max=X-Y
print(max)
Problem p03266 (python)

Fixed submission:
N,K=map(int,input().split())
res=[0]*K
for i in range(1,N+1):
    res[i%K]=res[i%K]+1
#print(res)

if K%2==0:
    print(pow(res[K//2],3)+pow(res[0],3))
else:
    print(pow(res[0], 3))

Buggy submission (verdict: Runtime Error):
N,K=map(int,input().split())
res=[0]*N
for i in range(1,N+1):
    res[i%K]=res[i%K]+1
#print(res)

if K%2==0:
    print(pow(res[K//2],3)+pow(res[0],3))
else:
    print(pow(res[0], 3))
Problem p03351 (python)

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

if ((abs(a-b)<=d)and(abs(b-c)<=d))or(abs(a-c)<=d):
    print("Yes")
else:
    print("No")

Buggy submission (verdict: Runtime Error):
a,b,c,d=map(int,input().split())

if (abs(a-b)=<d)or(abs(a-c)=<d)or(abs(b-c)=<d):
    print("Yes")
else:
    print("No")
Problem p03501 (python)

Fixed submission:
N,A,B=map(int,input().split())
print(min(N*A,B))

Buggy submission (verdict: Runtime Error):
N,A,B=map(int,input())
print(min(N*A,B))
Problem p03523 (python)

Fixed submission:
import itertools
S=input()
N=len(S)
flag=0
s="AKIHABARA"
s2=""
l2=[]
count=0
for i in range(9):
    l=list((itertools.combinations(s,i+1)))
    #print(l)
    for j in range(len(l)):
        s2="".join(l[j])
        l2.append(s2)
for i in range(len(l2)):
    if l2[i]==S:
        for j in range(len(l2[i])):
            if l2[i][j]=="A":
                count=count+1
        if (4-count)+len(l2[i])==9:
            flag=1
        break
if flag==1:
    print("YES")
else:
    print("NO")

Buggy submission (verdict: Runtime Error):
import itertools
S=input()
N=len(S)
flag=0
s="AKIHABARA"
s2=""
l2=[]
count=0
for i in range(9):
    l=list((itertools.combinations(s,i+1)))
    #print(l)
    for j in range(len(l)):
        s2="".join(l[j])
        l2.append(s2)
for i in range(len(l2)):
    if l2[i]==S:
        for j in range(len(l2[i])):
            if l2[i][j]=="A":
                count=connt+1
        if (4-count)+len(l2[i])==9:
            flag=1
        break
if flag==1:
    print("YES")
else:
    print("NO")
Problem p03569 (python)

Fixed submission:
from math import ceil
s=list(input())
n=len(s)
l=[]
m=[]
buf=[]
for i in range(n):
    if s[i]!="x":
        l.append(s[i])
m=l[::-1]
#print(l,m)
left=[]
right=[]
ans=0
if m==l:
    flag=1
    for i in range(ceil(len(l)/2)):
        buf.append(l[i])
    piv=0
    cnt=0
    #print(buf)
    for i in range(n):
        if piv==len(buf):
            break
        if s[i]==buf[piv]:
            left.append(cnt)
            cnt=0
            piv=piv+1
        else:
            cnt=cnt+1
    piv=0
    cnt=0
    for i in range(n-1,-1,-1):
        if piv==len(buf):
            break
        if s[i]==buf[piv]:
            right.append(cnt)
            cnt=0
            piv=piv+1
        else:
            cnt=cnt+1
    #print(left,right)
    for i in range(len(left)):
        ans=ans+abs(left[i]-right[i])
    print(ans)
else:
    print("-1")

Buggy submission (verdict: Runtime Error):
from math import ceil
s=list(input())
n=len(s)
l=[]
m=[]
buf=[]
for i in range(n):
    if s[i]!="x":
        l.append(s[i])
m=l[::-1]
#print(l,m)
left=[]
right=[]
ans=0
if m==l:
    flag=1
    for i in range(ceil(len(l)/2)):
        buf.append(s[i])
    piv=0
    cnt=0
    for i in range(n):
        if piv==len(buf):
            break
        if s[i]==buf[piv]:
            left.append(cnt)
            cnt=0
            piv=piv+1
        else:
            cnt=cnt+1
    piv=0
    cnt=0
    for i in range(n-1,-1,-1):
        if piv==len(buf):
            break
        if s[i]==buf[piv]:
            right.append(cnt)
            cnt=0
            piv=piv+1
        else:
            cnt=cnt+1
    #print(left,right)
    for i in range(len(left)):
        ans=ans+abs(left[i]-right[i])
    print(ans)
else:
    print("-1")
Problem p03597 (python)

Fixed submission:
N=int(input())
A=int(input())

print(N*N-A)

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

print(N*N-A)
Problem p03712 (python)

Fixed submission:
import numpy as np
H,W=map(int,input().split())
a=[list(map(str,list(input()))) for i in range(H)]
f=np.empty((H+2,W+2))
f=f.tolist()
#print(f)
#print(a)

for i in range(H+2):
    for j in range(W+2):
        if (i==0)or(i==H+1)or(j==0)or(j==W+1):
            f[i][j]='#'
            #print("#")
        elif (i>0)and(j>0):
            f[i][j]=a[i-1][j-1]
            #print(a[i-1][j-1])
for i in f:print(*i, sep='')

Buggy submission (verdict: Runtime Error):
import numpy as np
H,W=map(int,input().split())
a=[list(map(str,list(input()))) for i in range(H)]
f=np.empty((H+2,W+2))
f=f.tolist()
#print(f)
#print(a)

for i in range(H+2):
    for j in range(W+2):
        if (i==0)or(i==H+1)or(j==0)or(j==W+1):
            f[i][j]='#'
            #print("#")
        elif (i>0)and(j>0):
            f[i][j]=a[i-1][j-1]
            #print(a[i-1][j-1])
for i in f:print(*i, sep='')
Problem p03759 (python)

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

if (2*b-a-c)==0:
    print("YES")
else:
    print("NO")

Buggy submission (verdict: Runtime Error):
a,b,c=map(str,input().split())

if (2*b-a-c)==0:
    print("YES")
else:
    print("NO")

Buggy submission (verdict: Runtime Error):
a,b,c=map(str,input().split())

if (b-a)=(c-b):
    print("YES")
else:
    print("NO")

Buggy submission (verdict: Runtime Error):
a,b,c=map(str,input().split())

if (b-a)==(c-b):
    print("YES")
else:
    print("NO")
Problem p03994 (python)

Fixed submission:
s=list(input())
N=len(s)
K=int(input())
num=123

for i in range(N):
    diff=(num-ord(s[i]))%26
    if K==0:
        break
    if diff<=K:
        s[i]="a"
        K=K-diff
#print(s)
#print(K)
if K>0:
    K=K%26
    s[N-1]=chr(ord(s[N-1])+K)
#print(s)
print("".join(s))

Buggy submission (verdict: Runtime Error):
s=list(input())
N=len(s)
K=int(input())
num=123

for i in range(N):
    diff=(num-ord(s[i]))%26
    if K==0:
        break
    if diff<=K:
        s[i]="a"
        K=K-diff
#print(s)
if K>0:
    s[N-1]=chr(ord(s[N-1])+K)
#print(s)
print("".join(s))
Problem p03997 (python)

Fixed submission:
a=int(input())
b=int(input())
c=int(input())
print(int(((a+b)*c)/2))

Buggy submission (verdict: Runtime Error):
a,b,c=map(int,input().split())
print(((a+b)*c)/2)
Problem p03035 (python)

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

ans = 0
if A >= 13:
	ans = B
elif A >= 6:
    ans = int(B / 2)
else:
	ans = 0

print(ans)

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

ans = 0
if A >= 13:
	ans = B
elif A >= 6:
    ans = Int(B / 2)
else:
	ans = 0

print(ans)
Problem p02628 (python)

Fixed submission:
N,K=map(int,input().split())
P=sorted(list(map(int,input().split())))
print(sum(P[:K]))

Buggy submission (verdict: Runtime Error):
N.K=map(int,input().split())
P=sorted(list(map(int,input().split())))
print(sum(P[:K]))
Problem p02664 (python)

Fixed submission:
T=input()
ans=''
i=0
N=len(T)
if N==1 and T=='?':
  print('D')
  exit(0)
while i<N:
  if T[i]!='?':
    ans=ans+T[i]
  else:
    if i>0 and i<N-1:
      if ans[-1]=='P':
        ans=ans+'D'
      elif ans[-1]=='D' and T[i+1]=='D':
        ans=ans+'P'
      elif ans[-1]=='D' and T[i+1]=='P':
        ans=ans+'D'
      elif ans[-1]=='D' and T[i+1]=='?':
        ans=ans+'PD'
        i+=1
    elif i==0:
      if T[i+1]=='D':
        ans=ans+'P'
      elif T[i+1]=='?':
        ans=ans+'PD'
        i+=1
      else:
        ans=ans+'D'
    elif i==N-1:
      ans=ans+'D'

        
  i+=1
print(ans)

Buggy submission (verdict: Runtime Error):
T=input()
ans=''
i=0
N=len(T)
while i<N:
  if T[i]!='?':
    ans=ans+T[i]
  else:
    if i>0 and i<N-1:
      if ans[-1]=='P':
        ans=ans+'D'
      elif ans[-1]=='D' and T[i+1]=='D':
        ans=ans+'P'
      elif ans[-1]=='D' and T[i+1]=='P':
        ans=ans+'D'
      elif ans[-1]=='D' and T[i+1]=='?':
        ans=ans+'PD'
        i+=1
    elif i==0:
      if T[i+1]=='D':
        ans=ans+'P'
      elif T[i+1]=='?':
        ans=ans+'PD'
        i+=1
      else:
        ans=ans+'D'
    elif i==N-1:
      ans=ans+'D'

        
  i+=1
print(ans)

Buggy submission (verdict: Runtime Error):
T=input()
ans=''
i=0
N=len(T)
while i<N:
  if T[i]!='?':
    ans=ans+T[i]
  else:
    if i>0 and i<N-1:
      if ans[-1]=='P':
        ans=ans+'D'
      elif ans[-1]=='D' and T[i+1]=='D':
        ans=ans+'P'
      elif ans[-1]=='D' and T[i+1]=='P':
        ans=ans+'D'
    elif i==0:
      if T[i+1]=='D':
        ans=ans+'P'
      elif T[i+1]=='?':
        ans=ans+'PD'
        i+=1
      else:
        ans=ans+'D'
    elif i==N-1:
      ans=ans+'D'   
  i+=1
print(ans)

Buggy submission (verdict: Runtime Error):
T=input()
ans=''
i=0
N=len(T)
while i<N:
  if T[i]!='?':
    ans=ans+T[i]
  else:
    if i>0 and ans[-1]=='P':
      ans=ans+'D'
    elif i==N-1 and ans[-1]=='D':
      ans=ans+'D'
    elif i>0 and i<N-1 and ans[-1]=='D' and T[i+1]=='P':
      ans=ans+'D'
    elif i<N-1 and T[i+1]=='D':
      ans=ans+'P'
    elif i<N-1 and T[i+1]=='?':
      ans=ans+'PD'
      i+=1
  i+=1
print(ans)

Buggy submission (verdict: Runtime Error):
T=input()
ans=''
i=0
N=len(T)
while i<N:
  if T[i]!='?':
    ans=ans+T[i]
  else:    
    if ans[-1]=='P':
      ans=ans+'D'
    if i<N-1 and T[i+1]=='D':
      ans=ans+'P'
    if i<N-1 and T[i+1]=='?':
      ans=ans+'PD'
      i+=1
  i+=1
print(ans)
Problem p02718 (python)

Fixed submission:
N,M=map(int,input().split())
A=list(map(int,input().split()))
x=sum(A)
if sum([1 if a>=x/4/M else 0 for a in A])>=M:
  print('Yes')
else:
  print('No')

Buggy submission (verdict: Runtime Error):
N,M=map(int,input().split())
A=list(map(int,input().split()))
x=sum(A)
if sum([i if a>=x/4/M else 0 for a in A])>=M:
  print('Yes')
else:
  print('No')
Problem p02796 (python)

Fixed submission:
N=int(input())
XL=[list(map(int,input().split())) for i in range(N)]
XL.sort(key=lambda x:x[0]+x[1])
ans=1
left=XL[0][0]+XL[0][1]
for i in range(1,N):
  if XL[i][0]-XL[i][1] >= left:
    ans+=1
    left=XL[i][0]+XL[i][1]
  else:
    pass
print(ans)

Buggy submission (verdict: Runtime Error):
N=int(input())
if N==1:
  print(1)
  exit()
XL=[list(map(int,input().split())) for i in range(N)]
XL.sort(key=lambda x:x[0]-x[1])
i=0
normv=0
rmv=0
while True:
  if XL[i][0]+XL[i][1]<=XL[i+1][0]-XL[i+1][1]:
    i+=1
    normv+=1
  else:
    if XL[i]>XL[i+1]:
      XL.pop(i)
      rmv+=1
    elif XL[i][0]+XL[i][1] < XL[i+1][0]+XL[i+1][1]:
      XL.pop(i+1)
      i+=1
      normv+=1
      rmv+=1
    else:
      XL.pop(i)
      rmv+=1
  if rmv+normv==N-1:
    break
if len(XL)<2:
  pass
elif XL[-1][0]-XL[-1][0]<XL[-2][0]-XL[-2][0]:
  rmv+=1
else:
  normv+=1
print(len(XL))

Buggy submission (verdict: Runtime Error):
N=int(input())
XL=[list(map(int,input().split())) for i in range(N)]
XL.sort(key=lambda x:x[0]-x[1])
i=0
normv=0
rmv=0
while True:
  if XL[i][0]+XL[i][1]<=XL[i+1][0]-XL[i+1][1]:
    i+=1
    normv+=1
  else:
    if XL[i]>XL[i+1]:
      XL.pop(i)
      rmv+=1
    elif XL[i][0]+XL[i][1] < XL[i+1][0]+XL[i+1][1]:
      XL.pop(i+1)
      i+=1
      normv+=1
      rmv+=1
    else:
      XL.pop(i)
      rmv+=1
  if rmv+normv==N-1:
    break
if len(XL)<2:
  pass
elif XL[-1][0]-XL[-1][0]<XL[-2][0]-XL[-2][0]:
  rmv+=1
else:
  normv+=1
print(len(XL))
Problem p02806 (python)

Fixed submission:

N=int(input())
ST=[list(input().split()) for i in range(N)]
X=input()
ans=-1
for s,t in ST:
  if s !=X and ans==-1:
    continue
  else:
    if ans==-1:
      ans=0
    else:
      ans+=int(t)
print(ans)

Buggy submission (verdict: Runtime Error):
N=int(input())
ST=[list(map(int,input().split())) for i in range(N)]
X=input()
ans=-1
for s,t in ST:
  if s !=X and ans==-1:
    continue
  else:
    if ans==-1:
      ans=0
    else:
      ans+=int(t)
print(ans)

Buggy submission (verdict: Runtime Error):
N=int(input())
ST=[list(map(int,input().split())) for i in range(N)]
X=input()
ans=-1
for s,t in ST:
  if s !=X and ans==-1:
    continue
  else:
    if ans==-1:
      ans=0
    else:
      ans+=t
print(ans)
Problem p02837 (python)

Fixed submission:
N=int(input())
syougen=[]
for i in range(N):
  A=int(input())
  X=[list(map(int,input().split())) for i in range(A)]
  syougen.append(X)

def search(l):
  global seigo,syougen,flg
  for x,y in l:
    if seigo[x-1]==100:
      seigo[x-1]=y
      if y==1:
        search(syougen[x-1])
    elif seigo[x-1]!=y:
      flg=False

ans=0
for i in range(N):
  flg=True
  seigo=[100]*N
  seigo[i]=1
  _ans=0
  search(syougen[i])
  if flg:
    if sum(seigo)>100:
      i=0
      while sum(seigo)>100:
        if seigo[i]==100:
          _seigo=seigo[:]
          flg=True
          seigo[i]=1
          search(syougen[i])
          if flg:
            pass
          else:
            seigo=_seigo[:]
            seigo[i]=0
        i+=1
        i%=N
    _ans=sum(seigo)%100
    if _ans>ans:
      ans=_ans
      maxseigo=seigo        
print(ans)

Buggy submission (verdict: Runtime Error):
N=int(input())
syougen=[]
for i in range(N):
  A=int(input())
  X=[list(map(int,input().split())) for i in range(A)]
  syougen.append(X)

def search(l):
  global seigo
  for x,y in l:
    if y==1:
      seigo[x-1]=1
    else:
      seigo[x-1]=0
def chk(l):
  global seigo
  for x,y in l:
    if seigo[x-1] != y:
      if seigo[x-1]==100:
        seigo[x-1]=y
        if y==1:
          global syougen
          if chk(syougen[x-1],seigo):
            return True
      else:
      	return True
  return False

ans=0
for i in range(N):
  flg=True
  seigo=[100]*N
  _ans=0
  seigo[i]=1
  search(syougen[i])
  for j in range(N):
    if i==j:
      continue
    if seigo[j]==1:
      if chk(syougen[j]):
        flg=False
        break
    if seigo[j]==100:
      continue
  if flg:
    _ans=sum(seigo)%100
    if ans<_ans:
      ans=_ans
print(ans)
Problem p02850 (python)

Fixed submission:
import sys
sys.setrecursionlimit(10**6)
N=int(input())
P=[tuple(map(int,input().split())) for i in range(N-1)]
Path=[[] for i in range(N)]
for p in P:
  Path[p[0]-1].append(p[1]-1)
  Path[p[1]-1].append(p[0]-1)
colornum=1
dic={}
def bfs(nodes,p,pcolor,selfnum):
  global colornum
  if len(nodes)-1==0 and p!=-1:
    return
  c=1
  for n in nodes:
    if n == p:
      continue
    if c==pcolor:
      c+=1
    dic[(selfnum+1,n+1)]=c
    dic[(n+1,selfnum+1)]=c
    bfs(Path[n],selfnum,c,n)
    c+=1
  if c>colornum:
    colornum=c
bfs(Path[0],-1,0,0)
print(colornum-1)
for p in P:
  print(dic[p])

Buggy submission (verdict: Runtime Error):
N=int(input())
P=[tuple(map(int,input().split())) for i in range(N-1)]
Path=[[] for i in range(N)]
for p in P:
  Path[p[0]-1].append(p[1]-1)
  Path[p[1]-1].append(p[0]-1)
colornum=1
dic={}
def bfs(nodes,p,pcolor,selfnum):
  global colornum
  if len(nodes)-1==0 and p!=-1:
    return
  c=1
  for n in nodes:
    if n == p:
      continue
    if c==pcolor:
      c+=1
    dic[(selfnum+1,n+1)]=c
    dic[(n+1,selfnum+1)]=c
    bfs(Path[n],selfnum,c,n)
    c+=1
  if c>colornum:
    colornum=c
bfs(Path[0],-1,0,0)
print(colornum-1)
for p in P:
  print(dic[p])
Problem p02889 (python)

Fixed submission:
from scipy.sparse.csgraph import csgraph_from_dense
from scipy.sparse import csr_matrix
from scipy.sparse.csgraph import floyd_warshall
import numpy as np
N,M,L=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
Q=int(input())
ST=[list(map(int,input().split())) for _ in range(Q)]


G = csr_matrix((C, (A, B)), shape=(N, N))
d = floyd_warshall(G, directed=False)
G=np.full((N,N), np.inf)
G[d<=L]=1
G = csr_matrix(G)
E = floyd_warshall(G, directed=False)

for s,t in ST:
    if E[s-1][t-1]==float('inf'):
        print(-1)
    else:
        print(int(E[s-1][t-1]-1))

Buggy submission (verdict: Runtime Error):
from scipy.sparse.csgraph import csgraph_from_dense
from scipy.sparse.csgraph import floyd_warshall
N,M,L=map(int,input().split())
ABC=[map(int,input().split()) for _ in range(M)]
Q=int(input())
ST=[list(map(int,input().split())) for _ in range(Q)]

E=[[float('inf')]*N for _ in range(N)]
for a,b,c in ABC:
    E[a-1][b-1]=c
    E[b-1][a-1]=c
G = csgraph_from_dense(E, null_value=10**10)
d = floyd_warshall(G)
E=[[1 if __<= L else 10**10 for __ in _] for _ in d]
G = csgraph_from_dense(E, null_value=10**10)
E = floyd_warshall(G)

for s,t in ST:
    if E[s-1][t-1]==float('inf'):
        print(-1)
    else:
        print(int(E[s-1][t-1]-1))

Buggy submission (verdict: Runtime Error):
from scipy.sparse.csgraph import csgraph_from_dense
from scipy.sparse.csgraph import floyd_warshall
import numpy as np
N,M,L=map(int,input().split())
ABC=[map(int,input().split()) for _ in range(M)]
Q=int(input())
ST=[list(map(int,input().split())) for _ in range(Q)]

E=[[10**10]*N for _ in range(N)]
for a,b,c in ABC:
    E[a-1][b-1]=c
    E[b-1][a-1]=c
G = csgraph_from_dense(E, null_value=10**10)
d = floyd_warshall(G)
E=[[1 if __<= L else 10**10 for __ in _] for _ in d]
G = csgraph_from_dense(E, null_value=10**10)
E = floyd_warshall(G)

for s,t in ST:
    if np.isinf(E[s-1][t-1]):
        print(-1)
    else:
        print(int(E[s-1][t-1]-1))

Buggy submission (verdict: Runtime Error):
from scipy.sparse.csgraph import csgraph_from_dense
from scipy.sparse.csgraph import floyd_warshall
N,M,L=map(int,input().split())
ABC=[map(int,input().split()) for _ in range(M)]
Q=int(input())
ST=[list(map(int,input().split())) for _ in range(Q)]

E=[[10**10]*N for _ in range(N)]
for a,b,c in ABC:
    E[a-1][b-1]=c
    E[b-1][a-1]=c
G = csgraph_from_dense(E, null_value=10**10)
d = floyd_warshall(G)
E=[[1 if __<= L else 10**10 for __ in _] for _ in d]
G = csgraph_from_dense(E, null_value=10**10)
E = floyd_warshall(G)

for s,t in ST:
    if E[s-1][t-1]==float('inf'):
        print(-1)
    else:
        print(int(E[s-1][t-1]-1))
Problem p02934 (python)

Fixed submission:
N = int(input())
A = map(int,input().split())
x =0
for a in A:
  x+=1/a
x=1/x
print("{}".format(x))

Buggy submission (verdict: Runtime Error):
N = int(input())
A = map(int,input())
x =0
for a in A:
  x+=1/A
print("{:,5f}".format(1/x))