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

Fixed submission:
H,A = list(map(int, input().split()))
i = 0
while(True):
    i += 1
    if A * i >= H:
        break

print(i)

Buggy submission (verdict: Runtime Error):
H,N = list(map(int, input().split()))
A = []
B = []
for _ in range(N):
    a,b = list(map(int, input().split()))
    A.append(a)
    B.append(b)

dp = [float('inf') for i in range(H+max(A))]
dp[0] = 0

for i in range(H+max(A)):
    m = []
    for j in range(N):
        if i-A[j] >= 0:
            m.append(dp[i-A[j]]+B[j])
    m.append(dp[i])
    dp[i] = min(m)

print(min(dp[H:]))
Problem p02789 (python)

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

if M >= N:
    print('Yes')
else:
    print('No')

Buggy submission (verdict: Runtime Error):
N = int(input())
count = 0

c = [[0 for i in range(10)]for j in range(10)]

for i in range(1,N+1):
    str_i = str(i)
    c[int(str_i[0])][int(str_i[-1])] += 1

for j in range(10):
    for k in range(10):
        count += c[j][k] * c[k][j]

print(count)
Problem p02830 (python)

Fixed submission:
N = int(input())
S,T = input().split()
ans = ''

for i in range(N):
    ans += S[i]+T[i]

print(ans)

Buggy submission (verdict: Runtime Error):
N = int(input())
S,T = list(input())
ans = ''

for i in range(N):
    ans += S[i]+T[i]

print(ans)
Problem p02917 (python)

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

list_A = [0]*n

list_A[0] = B[0]
list_A[n-1] = B[n-2]
for i in range(1,n-1):
    list_A[i] = min(B[i-1],B[i])

print(sum(list_A))

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

list_A = [0]*n

list_A[0] = B[0]
list_A[i-1] = B[i-2]
for i in range(1:n-2):
    list_A[i] = max(B[i],B[i+1])

print(sum(list_A))
Problem p02919 (python)

Fixed submission:
N = int(input())
P = list(map(int, input().split()))
 
left_bigger  = [0] + [i for i in range(N+1)]
right_bigger = [i+1 for i in range(N+1)] + [N+1]
 
E = [(v, i+1) for i, v in enumerate(P)]
E.sort()

ans = 0
for v,i in E:
    l0=left_bigger[i]
    l1=left_bigger[l0]
    r0=right_bigger[i]
    r1=right_bigger[r0]
    ans += ((r1-r0)*(i-l0) + (r0-i)*(l0-l1))*v
    left_bigger[r0]=l0
    right_bigger[l0]=r0
print(ans)

Buggy submission (verdict: Runtime Error):
N = int(input())
P = list(map(int, input().split()))
 
left_bigger  = [0] + [i for i in range(N+1)]
right_bigger = [i+1 for i in range(N+1)] + [N+1]
 
E = [(v, i+1) for i, v in enumerate(P)]
E.sort()

ans = 0
for v,i in E:
    l0=left_bigger[i]
    l1=left_bigger[l0]
    r0=right_bigger[i]
    r1=right_bigger[r0]
    print(left_bigger)
    ans += ((r1-r0)*(i-l0) + (r0-i)*(l0-l1))*v
    left_bigger[r0]=l0
    right_bigger[l0]=r0
print(ans)
Problem p02994 (python)

Fixed submission:
N,L = list(map(int, input().split()))
l = []
l_abs = []
for i in range(N):
    l.append(L+i)
    l_abs.append(abs(L+i))


print(sum(l)-l[l_abs.index(min(l_abs))])

Buggy submission (verdict: Runtime Error):
N,L = list(map(int, input().split()))
l = []
l_abs = []
for i in range(N):
    l.append(L+i)
    l_abs.append(abs(L+i))


print(sum(l)-l[l.index(min(l_abs))])

Buggy submission (verdict: Runtime Error):
N,L = list(map(int, input().split()))
l = []
l_abs = []
for i in range(N):
    l.append(L+i)
    l_abs.append(abs(L+i))


print(sum(l)-l[l.index(min(l_abs))])
Problem p03455 (python)

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

if (a*b)%2 == 0:
    print("Even")

else:
    print("Odd")

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

if (a*b)%2 == 0:
    print(Even)

else:
    print(Odd)
Problem p03493 (python)

Fixed submission:
n = int(input())
s = 0

if int(n/100) == 1:
    s += 1
if n%100 >= 10:
    s += 1
if n%10 == 1:
    s += 1

print(s)

Buggy submission (verdict: Runtime Error):
n = int(input())
s = 0

if int(n/100) == 1:
    s += 1
if n%100 => 10:
    s += 1
if n%10 == 1:
    s += 1

print(s)

Buggy submission (verdict: Runtime Error):
n = int(input())
s = 0

if int(n/100) == 1:
    s ++
if n%100 => 10:
    s ++
if n%10 == 1:
    s ++

print(s)
Problem p03734 (python)

Fixed submission:
N,W = list(map(int, input().split()))
w_0 = []
w_1 = []
w_2 = []
w_3 = []
v = []
w = 0
w_count = [0]*4
for _ in range(N):
    a,b = list(map(int, input().split()))
    if w == 0:
        w = a
        w_0.append(b)
    else:
        if a == w:
            w_0.append(b)
        elif a == w+1:
            w_1.append(b)
        elif a == w+2:
            w_2.append(b)
        elif a == w+3:
            w_3.append(b)
    w_count[a-w] += 1

w_0.sort(reverse=True)
w_1.sort(reverse=True)
w_2.sort(reverse=True)
w_3.sort(reverse=True)
ans = 0

for i in range(w_count[0]+1):
    for j in range(w_count[1]+1):
        for k in range(w_count[2]+1):
            for l in range(w_count[3]+1):
                if W >= w * i + (w+1) * j + (w+2) * k + (w+3) * l:
                  
                    S = sum(w_0[:i])+sum(w_1[:j])+sum(w_2[:k])+sum(w_3[:l])
                    ans = max(ans,S)

print(ans)




# dp = [[0]*(W+1) for _ in range(N+1)]

# for i in range(N):
#     for j in range(W+1):
#         if j - w[i] < 0:
#             dp[i+1][j] = dp[i][j]
#         else:
#             dp[i+1][j] = max(dp[i][j],dp[i][j-w[i]] + v[i])

# k = max(dp)
# print(max(k))

Buggy submission (verdict: Runtime Error):
N,W = list(map(int, input().split()))
w = []
v = []
for _ in range(N):
    a,b = list(map(int, input().split()))
    w.append(a)
    v.append(b)

dp = [[0]*(W+1) for _ in range(N+1)]

for i in range(N):
    for j in range(W+1):
        if j - w[i] < 0:
            dp[i+1][j] = dp[i][j]
        else:
            dp[i+1][j] = max(dp[i][j],dp[i][j-w[i]] + v[i])

k = max(dp)
print(max(k))

Buggy submission (verdict: Runtime Error):
N,W = list(map(int, input().split()))
w = []
v = []
for _ in range(N):
    a,b = list(map(int, input().split()))
    w.append(a)
    v.append(b)

dp = [[0]*(W+1) for _ in range(N+1)]

for i in range(N):
    for j in range(W+1):
        if j - w[i] < 0:
            dp[i+1][j] = dp[i][j]
        else:
            dp[i+1][j] = max(dp[i][j],dp[i][j-w[i]] + v[i])

print(max(max(dp)))

Buggy submission (verdict: Runtime Error):
N,W = list(map(int, input().split()))
w = []
v = []
for _ in range(N):
    a,b = list(map(int, input().split()))
    w.append(a)
    v.append(b)

dp = [[0]*(W+1) for _ in range(N+1)]

for i in range(N):
    for j in range(W+1):
        if j - w[i] < 0:
            dp[i+1][j] = dp[i][j]
        else:
            dp[i+1][j] = max(dp[i][j],dp[i][j-w[i]] + v[i])

print(max(max(dp)))
Problem p02576 (python)

Fixed submission:
N,X,T=map(int,input().split())
print(((N-1)//X+1)*T)

Buggy submission (verdict: Runtime Error):
from collections import deque
H,W=map(int,input().split())
Ch,Cw=map(int,input().split())
Dh,Dw=map(int,input().split())
Ch-=1
Cw-=1
Dh-=1
Dw-=1

S=[]
for i in range(H):
  s=list(input())
  S.append([-1 if i =="." else i for i in s])

dq = deque()
dq.append((Ch,Cw))
S[Ch][Cw]=0

while dq:
  a=dq.pop()
  if a[0]-1>=0 and (S[a[0]-1][a[1]]==-1 or (S[a[0]-1][a[1]]!="#" and S[a[0]-1][a[1]]>S[a[0]][a[1]])):
    S[a[0]-1][a[1]]=S[a[0]][a[1]]
    dq.appendleft((a[0]-1,a[1]))
  if a[0]+1<H and (S[a[0]+1][a[1]]==-1 or (S[a[0]+1][a[1]]!="#" and S[a[0]+1][a[1]]>S[a[0]][a[1]])):
    S[a[0]+1][a[1]]=S[a[0]][a[1]]
    dq.appendleft((a[0]+1,a[1]))
  if a[1]-1>=0 and (S[a[0]][a[1]-1]==-1 or (S[a[0]][a[1]-1]!="#" and S[a[0]][a[1]-1]>S[a[0]][a[1]])):
    S[a[0]][a[1]-1]=S[a[0]][a[1]]
    dq.appendleft((a[0],a[1]-1))
  if a[1]+1<W and (S[a[0]][a[1]+1]==-1 or (S[a[0]][a[1]+1]!="#" and S[a[0]][a[1]+1]>S[a[0]][a[1]])):
    S[a[0]][a[1]+1]=S[a[0]][a[1]]
    dq.appendleft((a[0],a[1]+1))
  for i in range(5):
    for j in range(5):
      if a[0]-2+i>=0 and a[0]-2+i<H and a[1]-2+j>=0 and a[1]-2+j<W and (S[a[0]-2+i][a[1]-2+j]==-1 or (S[a[0]-2+i][a[1]-2+j]!="#" and S[a[0]-2+i][a[1]-2+j]>=S[a[0]][a[1]]+1)):
        S[a[0]-2+i][a[1]-2+j]=S[a[0]][a[1]]+1
        dq.append((a[0]-2+i,a[1]-2+j))

print(S[Dh][Dw])
Problem p02579 (python)

Fixed submission:
from collections import deque
H,W=map(int,input().split())
Ch,Cw=map(int,input().split())
Dh,Dw=map(int,input().split())
Ch-=1
Cw-=1
Dh-=1
Dw-=1

S=[]
for i in range(H):
  s=list(input())
  S.append([10**10 if i =="." else -1 for i in s])
visit=[[False for i in range(W)] for j in range(H)]

dq = deque()
dq.append((Ch,Cw,0))
S[Ch][Cw]=0
counter=0

while dq:
  a=dq.popleft()
  if visit[a[0]][a[1]]==True:
    continue
  elif S[a[0]][a[1]]==counter:
    visit[a[0]][a[1]]=True
  elif a[2]==counter+1:
    visit[a[0]][a[1]]=True
    counter+=1
  for i in range(5):
    for j in range(5):
      if a[0]-2+i>=0 and a[0]-2+i<H and a[1]-2+j>=0 and a[1]-2+j<W:
        if abs(i-2)+abs(j-2)==1 and S[a[0]][a[1]]<S[a[0]-2+i][a[1]-2+j] and visit[a[0]-2+i][a[1]-2+j]==False:
          S[a[0]-2+i][a[1]-2+j]=counter
          dq.appendleft((a[0]-2+i,a[1]-2+j,counter))
        elif S[a[0]][a[1]]+1<S[a[0]-2+i][a[1]-2+j] and visit[a[0]-2+i][a[1]-2+j]==False:
          S[a[0]-2+i][a[1]-2+j]=counter+1
          dq.append((a[0]-2+i,a[1]-2+j,counter+1))
  #print(visit,counter,a,dq,"\n")
if S[Dh][Dw]==10**10:
  print(-1)
else:
  print(S[Dh][Dw])

Buggy submission (verdict: Runtime Error):
from collections import deque
H,W=map(int,input().split())
Ch,Cw=map(int,input().split())
Dh,Dw=map(int,input().split())
Ch-=1
Cw-=1
Dh-=1
Dw-=1

S=[]
for i in range(H):
  s=list(input())
  S.append([-1 if i =="." else i for i in s])

dq = deque()
dq.append((Ch,Cw))
S[Ch][Cw]=0

while dq:
  a=dq.pop()
  if a[0]-1>=0 and (S[a[0]-1][a[1]]==-1 or (S[a[0]-1][a[1]]!="#" and S[a[0]-1][a[1]]>S[a[0]][a[1]])):
    S[a[0]-1][a[1]]=S[a[0]][a[1]]
    dq.appendleft((a[0]-1,a[1]))
  if a[0]+1<H and (S[a[0]+1][a[1]]==-1 or (S[a[0]+1][a[1]]!="#" and S[a[0]+1][a[1]]>S[a[0]][a[1]])):
    S[a[0]+1][a[1]]=S[a[0]][a[1]]
    dq.appendleft((a[0]+1,a[1]))
  if a[1]-1>=0 and (S[a[0]][a[1]-1]==-1 or (S[a[0]][a[1]-1]!="#" and S[a[0]][a[1]-1]>S[a[0]][a[1]])):
    S[a[0]][a[1]-1]=S[a[0]][a[1]]
    dq.appendleft((a[0],a[1]-1))
  if a[1]+1<W and (S[a[0]][a[1]+1]==-1 or (S[a[0]][a[1]+1]!="#" and S[a[0]][a[1]+1]>S[a[0]][a[1]])):
    S[a[0]][a[1]+1]=S[a[0]][a[1]]
    dq.appendleft((a[0],a[1]+1))
  for i in range(5):
    for j in range(5):
      if a[0]-2+i>=0 and a[0]-2+i<H and a[1]-2+j>=0 and a[1]-2+j<W and (S[a[0]-2+i][a[1]-2+j]==-1 or S[a[0]-2+i][a[1]-2+j]>=S[a[0]][a[1]]+1):
        S[a[0]-2+i][a[1]-2+j]=S[a[0]][a[1]]+1
        dq.append((a[0]-2+i,a[1]-2+j))

print(S[Dh][Dw])
Problem p02608 (python)

Fixed submission:
N=int(input())
A=[0]*N
for x in range(1,101):
  for y in range(1,101):
    for z in range(1,101):
      if x**2+y**2+z**2+x*y+y*z+z*x<=N:
        A[x**2+y**2+z**2+x*y+y*z+z*x-1]+=1
for i in range(N):
  print(A[i])

Buggy submission (verdict: Runtime Error):
NN=int(input())
A=[0]*N
for x in range(1,101):
  for y in range(1,101):
    for z in range(1,101):
      if x**2+y**2+z**2+x*y+y*z+z*x<=N:
        A[x**2+y**2+z**2+x*y+y*z+z*x-1]+=1
for i in range(N):
  print(A[i])
Problem p02618 (python)

Fixed submission:
D=int(input())
C=list(map(int,input().split()))
import sys
S=sys.stdin.readlines()
A=[0]*26
B=[0]*D
k=0
for i in range(26):
  if C[i]!=0:
    k+=C[i]
for i in range(26):
  if i<25:
    A[i]=int(C[i]/k*D)
  else:
    A[i]=D-sum(A[:25])

for i in range(25):
  for j in range(A[i]):
    B[D//A[i]*j]=i+1

for i in range(D):
  if B[i]==0:
    B[i]=26


for i in range(D):
  print(B[i])

Buggy submission (verdict: Runtime Error):
D=int(input())
C=list(map(int,input().split()))
import sys
S=sys.stdin.readlines()
A=[0]*26
B=[0]*D
k=0
for i in range(26):
  k+=1/C[i]
for i in range(26):
  if i<25:
    A[i]=int(1/C[i]/k*365)
  else:
    A[i]=365-sum(A[:25])

for i in range(25):
  for j in range(A[i]):
    B[D//A[i]*j]=i+1

for i in range(D):
  if B[i]==0:
    B[i]=26

for i in range(D):
  print(B[i])
Problem p02647 (python)

Fixed submission:
import numpy as np
from numba import jit
N,K=map(int,input().split())
A=np.array(list(map(int,input().split())),dtype=np.int64)
@jit
def loop(a,k):
  if k>41:
    ans=np.ones(N,dtype=np.int64)*N
  else:
    ans=a
    for j in range(k):
      B=np.zeros(N+1,dtype=np.int64)
      for i in range(N):
        B[max(0,i-int(ans[i]))] +=1
        B[min(N,i+int(ans[i])+1)] -=1
      ans=np.cumsum(B)[:N]
  return ans

for i in loop(A,K):
  print(i)

Buggy submission (verdict: Runtime Error):
import numpy as np
N,K=map(int,input().split())
A=np.array(list(map(int,input().split())),dtype=int64)
B=np.zeros(N+1,dtype=int64)
if K>41:
  A=np.ones(N,dtype=int64)*N
else:
  for k in range(K):
    for i in range(N):
      B[max(0,i-int(A[i]))] +=1
      B[min(N,i+int(A[i])+1)] -=1
    A=np.cumsum(B)[:N]
    B=np.zeros(N+1,dtype=int64)

for i in A:
  print(i)
Problem p02665 (python)

Fixed submission:
import numpy as np
N=int(input())
A=np.array(list(map(int,input().split())))
B=np.sum(A)-np.cumsum(np.append(0, A[:len(A)-1]))
v=0
k=0
for i in range(N+1):
  if i==0:
    if N==0 and A[0]==1:
      k=1
    elif A[0]==0:
      k=1
    else:
      print(-1)
      break
  elif i==N:
    if B[i]<=2*(k-A[i-1]):
      k=B[i]
    else:
      k=0
      print(-1)
      break
  else:
    k=min(2*(k-A[i-1]),B[i])
    if k<=0:
      print(-1)
      break
  v+=k
if k>0:
  print(v)

Buggy submission (verdict: Runtime Error):
import numpy as np
N=int(input())
A=list(map(int,input().split()))
A=np.array(A)
v=0
j=0
k=0
for i in reversed(range(0, N+1)):
  j+=A[i]/(2**i)
  if i==N:
    k=A[i]
  else:
    k=min(k+A[i],2**i-np.sum(np.array([A[k]*(2**(i-k)) for k in range(i)])))
  v+=k

if j>1:
  print(-1)
else:
  print(int(v))

Buggy submission (verdict: Runtime Error):
import numpy as np
N=int(input())
A=np.zeros(N+1)
a=list(map(int,input().split()))
for i in range(N+1):
  A[i]=a[i]
v=0
j=0
k=0
for i in reversed(range(0, N+1)):
  j+=A[i]/(2**i)
  if i==N:
    k=A[i]
  else:
    k=min(k+A[i],2**i-np.sum(np.array([A[k]*(2**(i+1-(N-k))) for k in range(i)])))
  v+=k

if j>1:
  print(-1)
else:
  print(int(v))

Buggy submission (verdict: Runtime Error):
import numpy as np
N=int(input())
A=np.zeros(N+1)
a=list(map(int,input().split()))
for i in range(N+1):
  A[i]=a[i]
v=0
j=0
k=0
B=np.zeros(N+1)
for i in range(N+1):
  B[i]=N-i
for i in reversed(range(0, N+1)):
  j+=A[i]/(2**i)
  if i==N:
    k=A[i]
  else:
    k=min(k+A[i],2**i-np.sum(A[0:i]*(2**(B[0:i]-(N-i)))))
  v+=k

if j>1:
  print(-1)
else:
  print(int(v))
Problem p02683 (python)

Fixed submission:
import numpy as np
N,M,X=map(int,input().split())
C=np.zeros(N,dtype=int)
A=np.zeros([N,M],dtype=int)
for i in range(N):
    T=list(map(int,input().split()))
    C[i]=T[0]
    for j in range(M):
        A[i,j]=T[j+1]
a=np.zeros(N,dtype=int)
ans=-1
while a.all()!=1:
  if ((a@A)>=X).all():
    if ans==-1:
        ans=a@(C.T)
    elif a@(C.T)<ans:
        ans=a@(C.T)
  for i in range(N):
    if a[N-i-1]==0:
      a[N-i-1]=1
      break
    else:
      a[N-i-1]=0

if ((a@A)>=X).all():
  if ans==-1:
      ans=a@(C.T)
  elif a@(C.T)<ans:
      ans=a@(C.T)

print(ans)

Buggy submission (verdict: Runtime Error):
import numpy as np
N=int(input())
A=np.zeros(N+1)
a=list(map(int,input().split()))
for i in range(N+1):
  A[i]=a[i]
v=0
j=0
k=0
B=np.zeros(N+1)
for i in range(N+1):
  B[i]=N-i
for i in reversed(range(0, N+1)):
  j+=A[i]/(2**i)
  if i==N:
    k=A[i]
  else:
    k=min(k+A[i],2**i-np.sum(A[0:i]*(2**(B[0:i]-(N-i)))))
  v+=k

if j>1:
  print(-1)
else:
  print(int(v))

Buggy submission (verdict: Runtime Error):
import numpy as np
N,M,X=map(int,input().split())
C=np.zeros(N,dtype=int)
A=np.zeros([N,M],dtype=int)
for i in range(N):
    T=list(map(int,input().split()))
    C[i]=T[0]
    for j in range(M):
        A[i,j]=T[j+1]
a=np.zeros(N,dtype=int)
ans=-1
while a.all()!=1:
  if ((a@A)>X).all():
    if ans==-1:
        ans=a@(C.T)
    elif a@(C.T)<ans:
        ans=a@(C.T)
  for i in range(N):
    if a[N-i-1]==0:
      a[N-i-1]=1
      break
    else:
      a[N-i-1]=0

a=np.array([0,1,1])
if ((a@A)>=X).all():
  if ans==-1:
      ans=a@(C.T)
  elif a@(C.T)<ans:
      ans=a@(C.T)

print(ans)
Problem p02684 (python)

Fixed submission:
import numpy as np
N,K=map(int,input().split())
A=list(map(int,input().split()))
C=[1]
s=set([1])
for i in range(N):
  if A[C[i]-1] in s:
    l=C.index(A[C[i]-1])+1
    break
  else:
    C.append(A[C[i]-1])
    s.add(A[C[i]-1])
if K+1<=l:
  print(C[K])
else:
  print(C[l-1+(K+1-l)%(len(C)-l+1)])

Buggy submission (verdict: Runtime Error):
import numpy as np
N,K=map(int,input().split())
A=list(map(int,input().split()))
C=[1]
for i in range(1,N+1):
  if C.count(A[C[i]-1])==0:
    C.append(A[C[i]-1])
  else:
    l=C.index(A[C[i]-1])+1
    break
if K+1<=l:
  print(C[K])
else:
  print(C[l-1+(K+1-l)%(len(C)-l+1)])
print(C)

Buggy submission (verdict: Runtime Error):
import numpy as np
N,K=map(int,input().split())
A=list(map(int,input().split()))
def B(i):
  if i==0:
    return 1
  return A[B(i-1)-1]
C=[1]
for i in range(1,N+1):
  if C.count(B(i))==0:
    C.append(B(i))
  else:
    l=C.index(B(i))+1
    break
if K+1<=l:
  print(C[K])
else:
  print(C[l-1])
print(C)

Buggy submission (verdict: Runtime Error):
import numpy as np
N,K=map(int,input().split())
A=list(map(int,input().split()))
def B(i):
  if i==0:
    return 1
  return A[B(i-1)-1]
C=[1]
for i in range(1,N+1):
  if C.count(B(i))==0:
    C.append(B(i))
  else:
    l=C.index(B(i))+1
    break
if K<=l-1:
  print(C[K-1])
else:
  print(C[l-2+(K+2-l)%(len(C)-l+1)])

Buggy submission (verdict: Runtime Error):
import numpy as np
N,K=map(int,input().split())
A=list(map(int,input().split()))
def B(i):
  if i==0:
    return 1
  return A[B(i-1)-1]
C=[1]
for i in range(1,N+1):
  if C.count(B(i))==0:
    C.append(B(i))
  else:
    l=C.index(B(i))+1
    break
if K+1<=l:
  print(C[K])
else:
  print(C[l-2+(K+2-l)%(len(C)-l+1)])

Buggy submission (verdict: Runtime Error):
import numpy as np
N,K=map(int,input().split())
A=list(map(int,input().split()))
def B(i):
  if i==0:
    return 1
  return A[B(i-1)-1]
C=[1]
for i in range(1,N+1):
  if C.count(B(i))==0:
    C.append(B(i))
  else:
    l=C.index(B(i))
    break
if K<=l:
  print(C[K])
else:
  print(C[l+(K+1-l)%(len(C)-l)-1])

Buggy submission (verdict: Runtime Error):
import numpy as np
N,K=map(int,input().split())
A=list(map(int,input().split()))
def B(i):
  if i==0:
    return 1
  return A[B(i-1)-1]
C=[1]
for i in range(1,N+1):
  if B(i)!=1:
    C.append(B(i))
  else:
    break
print(C[K%len(C)])
Problem p02687 (python)

Fixed submission:
S=input()
if S=="ABC":
  print("ARC")
else:
  print("ABC")

Buggy submission (verdict: Runtime Error):
S=input()
if S="ABC":
  print("ARC")
else:
  print("ABC")
Problem p02803 (python)

Fixed submission:
import numpy as np
import queue
H,W=map(int,input().split())
S=list()
for i in range(H):
  S.append(input())
ans=0
  
for i in range(H):
  for j in range(W):
    if S[i][j]==".":
      L=[[-1]*W for i in range(H)]
      L[i][j]=0
      q=queue.Queue()
      q.put([i,j])
      while not q.empty():
        r=q.get()
        for k,l in [[1,0],[0,-1],[0,1],[-1,0]]:
          if r[0]+k>=0 and r[0]+k<H and r[1]+l>=0 and r[1]+l<W and S[r[0]+k][r[1]+l]=="." and L[r[0]+k][r[1]+l]==-1:
            L[r[0]+k][r[1]+l]=L[r[0]][r[1]]+1
            q.put([r[0]+k,r[1]+l])
      ans=max(ans,max(list(map(lambda x:max(x),L))))
print(ans)

Buggy submission (verdict: Runtime Error):
import numpy as np
import queue
H,W=map(int,input().split())
S=list()
for m in range(H):
  S.append(input())
ans=0
i,j=7,6
if S[i][j]==".":
    L=[[-1]*W for i in range(H)]
    L[i][j]=0
    q=queue.Queue()
    q.put([i,j])
    while not q.empty():
      r=q.get()
      for k,l in [[1,0],[0,-1],[0,1],[-1,0]]:
        if r[0]+k>=0 and r[0]+k<H and r[1]+l>=0 and r[1]+l<W and S[r[0]+k][r[1]+l]=="." and L[r[0]+k][r[1]+l]==-1:
          L[r[0]+k][r[1]+l]=L[r[0]][r[1]]+1
          q.put([r[0]+k,r[1]+l])
    ans=max(ans,max(list(map(lambda x: max(x),L))))
print(ans)
Problem p02573 (python)

Fixed submission:
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())

n,m = map(int,input().split())
uf = UnionFind(n)
for i in range(m):
    a,b = map(int,input().split())
    uf.union(a-1,b-1)
ans = 0
for j in range(n):
    check = uf.size(j)
    if ans < check:
        ans = check
print(ans)

Buggy submission (verdict: Runtime Error):
N,M = map(int,input().split())
ls = [0 for _ in range(N)]
flg = 1
for i in range(M):
    a,b = map(int,input().split())
    if ls[a-1] == 0 and ls[b-1]==0:
        ls[a-1]=flg
        ls[b-1]=flg
        flg+=1
    elif ls[a-1] == 0:
        ls[a-1] = ls[b-1]
    elif ls[b-1] == 0:
        ls[b-1] = ls[a-1]
    else:
        check = min(ls[a-1],ls[b-1])
        ls[a-1] = check
        ls[b-1] = check
import collections
c = collections.Counter(ls)
plan = c.most_common()
ans = 0
if plan[0][0] == 0:
    ans = plan[1][1]
else:
    ans = plan[0][1]
print(ans)

Buggy submission (verdict: Runtime Error):
N,M = map(int,input().split())
ls = [0 for _ in range(N)]
flg = 1
for i in range(M):
    a,b = map(int,input().split())
    if ls[a-1] == 0 and ls[b-1]==0:
        ls[a-1]=flg
        ls[b-1]=flg
        flg+=1
    elif ls[a-1] == 0:
        ls[a-1] = ls[b-1]
    elif ls[b-1] == 0:
        ls[b-1] = ls[a-1]
    else:
        check = min(ls[a-1],ls[b-1])
        ls[a-1] = check
        ls[b-1] = check
from statistics import mode
com = mode(ls)
print(ls.count(com))
Problem p02630 (python)

Fixed submission:
import math
data = input()
num = int(data)
o = input().rstrip().split(" ")
list =[]
for i in o:
    list.append(int(i))
p = input()
times = int(p)
ans = sum(list)
num_count=[0 for i in range(100001)]
for i in list:
    num_count[i] += 1
for i in range(times):
    B, C = map(int, input().split(" "))
    a = num_count[B]
    num_count[B] = 0
    num_count[C] += a
    ans += a*(C-B)
    print(ans)

Buggy submission (verdict: Runtime Error):
import math
data = input()
num = int(data)
o = input().rstrip().split(" ")
list =[]
for i in o:
    list.append(int(i))
list.sort()
p = input()
times = int(p)
num_count=[list.count(i) for i in range(100000)]
for i in range(times):
    B, C = map(int, input().split(" "))
    a = num_count[B]
    num_count[B] = 0
    num_count[C] += a
    ans = 0
    for i in range(100000):
        ans = ans + (i) * num_count[i]
    print(ans)