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

Fixed submission:
N, K = map(lambda x: int(x), input().split(" "))
As = list(map(lambda x: int(x), input().split(" ")))

visited = set()
visited_list = []
index = 0
visited.add(index)
visited_list.append(0)
count = 0
flag = False
for i in range(K):
    index = As[index] - 1
    count += 1
    if index in visited:
        flag = True
        break
    visited.add(index)
    visited_list.append(index)

temp_index = visited_list.index(index)
K -= count
count = count - temp_index

if flag:
    K %= count
    for i in range(K):
        index = As[index] - 1

print(index+1)

Buggy submission (verdict: Runtime Error):
N, K = map(lambda x: int(x), input().split(" "))
As = list(map(lambda x: int(x), input().split(" ")))

visited = set()
visited_list = []
index = 0
visited.add(index)
visited_list.append(0)
count = 0
flag = False
for i in range(K):
    index = As[index] - 1
    count += 1
    if index in visited:
        flag = True
        break
    visited.add(index)
    visited_list.append(index)

temp_index = visited_list.index(index)
count = count - temp_index

if flag:
    K %= count-temp_index
    for i in range(K):
        index = As[index] - 1

print(index+1)
Problem p02934 (python)

Fixed submission:
import fractions

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

def get_num(a, lcm):
    return lcm // a


N_str = input()
a_str = input()
a_str_list = a_str.split(" ")
a_list = list(map(lambda x: int(x), a_str_list))
lcm = 1
for a in a_list:
    lcm = get_lcm(lcm, a)

sum_a = 0
for a in a_list:
    sum_a += get_num(a, lcm)

result = lcm / sum_a
print(result)

Buggy submission (verdict: Runtime Error):
import math

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

def get_num(a, lcm):
    return lcm // a


N_str = input()
a_str = input()
a_str_list = a_str.split(" ")
a_list = list(map(lambda x: int(x), a_str_list))
lcm = 1
for a in a_list:
    lcm = get_lcm(lcm, a)

sum_a = 0
for a in a_list:
    sum_a += get_num(a, lcm)

result = lcm / sum_a
print(result)

Buggy submission (verdict: Runtime Error):
import math

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

def get_num(a, lcm):
    return lcm // a


N_str = input()
a_str = input()
a_str_list = a_str.split(" ")
a_list = list(map(lambda x: int(x), a_str_list))
lcm = 1
for a in a_list:
    lcm = get_lcm(lcm, a)

Buggy submission (verdict: Runtime Error):
import math

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

def get_num(a, lcm):
    return lcm // a


N_str = input()
a_str = input()
a_str_list = a_str.split(" ")
# a_list = list(map(lambda x: int(x), a_str_list))
a_list = []
for a in a_str:
    a_list.append(int(a))
lcm = 1
for a in a_list:
    lcm = get_lcm(lcm, a)

sum_a = 0
for a in a_list:
    sum_a += get_num(a, lcm)

result = lcm / sum_a
print(result)

Buggy submission (verdict: Runtime Error):
import math

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

def get_num(a, lcm):
    return lcm // a


N_str = input()
a_str = input()
a_str_list = a_str.split(" ")
a_list = list(map(lambda x: int(x), a_str_list))
lcm = 1
for a in a_list:
    lcm = get_lcm(lcm, a)

sum_a = 0
for a in a_list:
    sum_a += get_num(a, lcm)

result = lcm / sum_a
print(result)

Buggy submission (verdict: Runtime Error):
import math

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

def get_num(a, lcm):
    return lcm // a


N_str = input()
a_str = input()
a_str_list = a_str.split(" ")
a_list = mapped_list = map(lambda x: int(x), a_str_list)
lcm = 1
for a in a_list:
    lcm = get_lcm(lcm, a)

sum_a = 0
for a in a_list:
    sum_a = a * get_num(a, lcm)

result = lcm // sum_a
input(result)
Problem p02677 (python)

Fixed submission:
import numpy as np
a,b,h,m=list(map(int,input().split()))
ta=(60*h+m)*0.5%360
tb=(60*h+m)*6%360
print(np.sqrt(a**2+b**2-2*a*b*np.cos(np.radians(tb)-np.radians(ta))))

Buggy submission (verdict: Runtime Error):
import numpy as np
import copy
n,m=list(map(int,input().split()))
A=[0]*m
B=[0]*m
ans=[0]*n
for i in range(m):
  A[i],B[i]=list(map(int,input().split()))
C=A.copy()
C.extend(B)
root=1
R=[]
for room in range(1,n+1):
  L= [j for j,k in enumerate(B) if k==root]
  if L==[]:
    exit()
  for l in L:
    if ans[B[l]]0=0:
      ans[B[l]]=root
 	  R.append(B[l])
    
print(A,B)
Problem p02817 (python)

Fixed submission:
n,m=input().split()
print(m+n)

Buggy submission (verdict: Runtime Error):
n,m=list(map(input().split()))
print(m.append(n))
Problem p02608 (python)

Fixed submission:
n = int(input())
import math
lim = math.ceil(math.sqrt(n))
l = [0]*n
for x in range(1, lim):
    for y in range(1, lim):
        for z in range(1, lim):
            i = (x+y+z)**2 - (x*y + y*z + z*x)
            if (0<i) and (i<n+1):
                l[i-1] += 1
for i in l:
    print(i)

Buggy submission (verdict: Runtime Error):
n = int(input())
import math
lim = math.ceil(math.sqrt(n-5))
l = [0]*n
for x in range(1, lim):
    for y in range(1, lim):
        for z in range(1, lim):
            i = (x+y+z)**2 - (x*y + y*z + z*x)
            if (0<i) and (i<n+1):
                l[i-1] += 1
for i in l:
    print(i)
Problem p02612 (python)

Fixed submission:

N = int(input())
ans = 0
for i in range(0,N):
    if i*1000>=N:
        ans = i*1000-N
        break
    if N < 1000:
        ans = 1000 - N
print(ans)

Buggy submission (verdict: Runtime Error):

N = int(input())
for i in range(1,N):
    if i*1000>=N:
        ans = i*1000-N
        break
print(ans)
Problem p02730 (python)

Fixed submission:

s = str(input())
n = len(s)
s1 = s[:int((n-1)/2)]
s2 = s[int((n+3)/2)-1:]

if s == s[::-1] and s1 == s1[::-1] and s2 == s2[::-1]:
    print("Yes")
else:
    print("No")

Buggy submission (verdict: Runtime Error):

s = input()
n = len(s)
s1 = s[:int((n-1)/2)]
s2 = s[int((n+3)/2)-1:]

i = 1
while i < len(s1):
    if not s1[i-1] == s1[-i]:
        print("No")
        break
    i += 1
while i < len(s2):
    if not s2[i+2] == s2[-i]:
        print("No")
    i += 1
print("Yes")
Problem p02765 (python)

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

if N >= 10:
    print(R)
else:
    print(R + 100*(10-N))

Buggy submission (verdict: Runtime Error):
N, R = int(input())

if N >= 10:
    print(R)
else:
    print(R + 100*(10-N))
Problem p02898 (python)

Fixed submission:

n,k = list(map(int, input().split()))
h = list(map(int, input().split()))

cnt = 0
for i in range(n):
    if h[i] >= k:
        cnt += 1
print(cnt)

Buggy submission (verdict: Runtime Error):

n,k = list(map(int, input().split()))
h = list(map(int, input().split()))

cnt = 0
for i in range(k):
    if h[i] >= k:
        cnt += 1
print(cnt)
Problem p03290 (python)

Fixed submission:

def solve():
    d = 0
    c = 0
    for i in range(D):
        d += p[i][0]
    dp = [[0]*(d+1) for i in range(D)]
    for i in range(D):
        for j in range(p[i][0]+1):
            if i == 0:
                if j == p[i][0]:
                    dp[i][j] += p[i][1]
                dp[i][j] += 100*j
            else:
                for k in range(c+1):
                    if j == p[i][0]:
                        dp[i][k+j]=max(dp[i][k+j],dp[i-1][k]+100*j*(i+1)+p[i][1])
                    else:
                        dp[i][k+j]=max(dp[i][k+j],dp[i-1][k]+100*j*(i+1))
        c += p[i][0]
    for i in range(d+1):
        if dp[D-1][i]>=G:
            print(i)
            break    
    
if __name__=="__main__":
    D,G = list(map(int, input().split()))
    p = [list(map(int, input().split())) for _ in range(D)]
    solve()

Buggy submission (verdict: Runtime Error):

def solve():
    d = 0
    c = 0
    for i in range(D):
        d += p[i][0]
    dp = [[0]*(d+1) for i in range(D)]
    for i in range(D):
        for j in range(p[i][0]+1):
            if i == 0:
                if j == p[i][0]:
                    dp[i][j] += p[i][1]
                dp[i][j] += 100*j
            else:
                for k in range(c+1):
                    if j == p[i][0]:
                        dp[i][k+j]=max(dp[i][k+j],dp[i-1][k]+100*j*(i+1)+p[i][1])
                    else:
                        dp[i][k+j]=max(dp[i][k+j],dp[i-1][k]+100*j*(i+1))
        c += p[i][0]
    for i in range(d+1):
        if dp[D-1][i]>=G:
            print(i)
            break    
    
if __name__=="__main__":
    D,G = list(map(int, input().split()))
    pc = [list(map(int, input().split())) for _ in range(D)]
    solve()
Problem p03470 (python)

Fixed submission:
N = int(input())
d = [int(input()) for i in range(N)]
print(len(set(d)))

Buggy submission (verdict: Runtime Error):
N = int(input())
d = [int(input()) for i in range(N)]count = 1
d.sort(reverse=True)
for j in range(N-1):
    if (d[j] != d[j+1]):
        count += 1
print(count)
Problem p03493 (python)

Fixed submission:
print(input().count("1"))

Buggy submission (verdict: Runtime Error):
input()
A = list(map(int, input().split()))
count = 0
while all(a % 2 == 0 for a in A):
    A = [a/2 for a in A]
    count += 1
print(count)

Buggy submission (verdict: Runtime Error):
N = int(input())
A = list(map(int, input().split()))
count = 0
while all(a % 2 == 0 for a in A):
    A = [a/2 for a in A]
    count +=1
print(count)
Problem p02584 (python)

Fixed submission:
x, k, d = map(int, input().split())
  
x = abs(x)

if x > k * d:
  print(x - k * d)
else:
  f = int(x / d)
  x = x - f * d
  g = (k - f) % 2
  if g == 1:
    x = x - d
  print(abs(x))

Buggy submission (verdict: Runtime Error):
x, k, d = map(int, input().split())
  
if abs(x) > k * d:
  r = x - int(abs(x)/x) * k * d
else:
  n = int(abs(x) / d)
  r1 = x - int(abs(x)/x) * n * d
  if r1 == 0:
    r = 0
  else:
    r2 = r1 - int(abs(r1)/r1) * d
    r = min(abs(r1), abs(r2))

print(r)
Problem p02657 (python)

Fixed submission:
n, k = map(int, input().split())
print(n*k)

Buggy submission (verdict: Runtime Error):
n, k = map(int, input().split())
print(N*k)

Buggy submission (verdict: Runtime Error):
n, k = map(int, input().split())
print(N*k)
Problem p02687 (python)

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

Buggy submission (verdict: Runtime Error):
a=input()
if a=="ABC":
  ptint("ARC")
else:
  print("ABC")
Problem p02719 (python)

Fixed submission:
n,k=input().split()
n=int(n)
k=int(k)
i=n//k
j=n-k*i
if j>=abs(j-k):
    print(abs(j-k))
else:
    print(j)

Buggy submission (verdict: Runtime Error):
n,k=int(input().split())
i=n//k
j=n-k*i
if j>=abs(j-k):
    print(abs(j-k))
else:
    print(j)
Problem p02730 (python)

Fixed submission:
n=input()
s=len(n)
d=int((s-1)/2)
p=int((s+3)/2)
m=n[::-1]
n1=n[0:d]
n2=n1[::-1]
n3=n[p-1:]
n4=n3[::-1]
if n==m and n1==n2 and n3==n4:
    print("Yes")
else:
    print("No")

Buggy submission (verdict: Runtime Error):
n=input()
s=len(n)
d=int((s-1)/2)
p=int(s+3)/2
m=n[::-1]
n1=n[0:d-1]
n2=n1[::-1]
n3=n[p-1:]
n4=n3[::-1]
if n==m and n1==n2 and n3==n4:
    print("Yes")
else:
    print("No")
Problem p02755 (python)

Fixed submission:
import math
import sys
a,b=map(int,input().split())
a2=math.ceil(a/0.08)
a3=math.floor((a+1)/0.08)
if a2>a3:
    print("-1")
    sys.exit()
b2=math.ceil(b/0.1)
b3=math.floor((b+1)/0.1)
if b2>b3:
    print("-1")
    sys.exit()
if b2<a2:
    if a2<(b+1)/0.1:
        print(a2)
    else:
        print("-1")
if a2<b2:
    if b2<(a+1)/0.08:
        print(b2)
    else:
        print("-1")
if a2==b2:
    print(a2)

Buggy submission (verdict: Runtime Error):
import math
import sys
a,b=map(int,input().spliit())
a2=math.ceil(a/0.08)
a3=math.floor((a+1)/0.08)
if a2>a3:
    print("-1")
    sys.exit()
b2=math.ceil(b/0.1)
b3=math.floor((b+1)/0.1)
if b2>b3:
    print("-1")
    sys.exit()
if b2<a2:
    if a2<(b+1)/0.1:
        print(a2)
    else:
        print("-1")
if a2<b2:
    if b2<(a+1)/0.08:
        print(b2)
    else:
        print("-1")
if a2==b2:
    print(a2)
Problem p02760 (python)

Fixed submission:
p1=list(map(int,input().split()))
p2=list(map(int,input().split()))
p3=list(map(int,input().split()))
p=p1+p2+p3
n=int(input())
for _ in range(n):
    b=int(input())
    if b in p:
        p[p.index(b)]=0
if p[0]+p[1]+p[2]==0 or p[3]+p[4]+p[5]==0 or p[6]+p[7]+p[8]==0 or p[0]+p[3]+p[6]==0 or p[1]+p[4]+p[7]==0 or p[2]+p[5]+p[8]==0 or p[0]+p[4]+p[8]==0 or p[2]+p[4]+p[6]==0:
    print("Yes")
else:
    print("No")

Buggy submission (verdict: Runtime Error):
c=[]
w=0
for i in range(3):
    c.append(list(map(int,input().split())))
N=int(input())
d=[]
for y in range(N):
    d.append(int(input()))
for n in d:
    for p in c:
        for j in p:
            if n in j:
                j=0
for t in c:
    for h in t:
        if c.count(0)==3:
            o=1
            break
    else:
        continue
    break
for v in range(3):
    w=0
    for k in c:
        if k[v]==0:
            w+=1
        if w==3:
            o=1
w=0
for ji in range(3):
    if c[ji][ji]==0:
        w+=1
    if w==3:
        o=1
w=0
for ji2 in range(3):
    if c[ji2][3-ji2]==0:
        w+=1
    if w==3:
        o=1
for v1 in range(3):
    w=0
    for k in range(3):
        if c[k][v1]==0:
            w+=1
        if w==3:
            o=1

if o==1:
    print("Yes")
else:
    print("No")

Buggy submission (verdict: Runtime Error):
a=list(map(int,input().split()))
b=len(a)
c=[a]
w=0
for i in range(b-1):
    c.append(list(map(int,input().split())))
N=int(input())
d=[]
for y in range(N):
    d.append(int(input()))
for n in d:
    for p in c:
        for j in p:
            if n in j:
                j=0
for t in c:
    for h in t:
        if c.count(0)==b:
            o=1
            break
    else:
        continue
    break
for v in range(b):
    w=0
    for k in c:
        if k[v]==0:
            w+=1
        if w==b:
            o=1
w=0
for ji in range(b):
    if c[ji][ji]==0:
        w+=1
    if w==b:
        o=1
w=0
for ji2 in range(b):
    if c[ji2][b-ji2]==0:
        w+=1
    if w==b:
        o=1
for v1 in range(b):
    w=0
    for k in range(b):
        if c[k][v1]==0:
            w+=1
        if w==b:
            o=1

if o==1:
    print("Yes")
else:
    print("No")

Buggy submission (verdict: Runtime Error):
a=list(map(int,input().split()))
b=len(a)
c=[a]
w=0
for i in range(b-1):
    c.append(list(map(int,input().split())))
N=int(input())
d=[]
for y in range(N):
    d.append(int(input()))
for n in d:
    for p in c:
        for j in p:
            if n in j:
                j=0
for t in c:
    for h in t:
        if c.count(0)==b:
            o=1
            break
    else:
        continue
    break
for v in range(b):
    w=0
    for k in c:
        if k[v]==0:
            w+=1
        if w==b:
            o=1
w=0
for ji in range(b):
    if c[ji][ji]==0:
        w+=1
    if w==b:
        o=1
w=0
for ji2 in range(b):
    if c[ji2][b-ji2]==0:
        w+=1
    if w==b:
        o=1
if o==1:
    print("Yes")
else:
    print("No")
Problem p02765 (python)

Fixed submission:
a,b=input().split()
a=int(a)
b=int(b)
if a>=10:
    print(b)
else:
    c=b-100*a+1000
    print(c)

Buggy submission (verdict: Runtime Error):
a=int(input())
b=list(map(int,input().split()))
c=0
m=0
for i in b:
    c+=i
d=c/len(b)
e=str(d)[2]
e=int(e)
if e>=5:
    f=int(str(d)[0])+1
else:
    f=int(str(d)[0])
for g in b:
    m+=(abs(g-f))**2
print(m)
Problem p02813 (python)

Fixed submission:
n=int(input())
p=list(map(int,input().split()))
q=list(map(int,input().split()))
N=[i for i in range(1,n+1)]
p1=[i for i in range(1,n+1)]
q1=[i for i in range(1,n+1)]
def kaijou(x):
    if x==0:
        return 0
    elif x==1:
        return 1
    elif x==2:
        return 2
    elif x==3:
        return 6
    elif x==4:
        return 24
    elif x==5:
        return 120
    elif x==6:
        return 720
    elif x==7:
        return 5040

s1=1
s2=1
j=1
for i in p:
    s1 += kaijou(n-j)*int(p1.index(i))
    j+=1
    p1.remove(i)
j=1
for i in q:
    s2 += kaijou(n-j)*int(q1.index(i))
    j+=1
    q1.remove(i)
k=s1-s2
if k<0:
    print(-k)
else:
    print(k)

Buggy submission (verdict: Runtime Error):
n=int(input())
p=input().split()
q=input().split()
N=[i for i in range(1,n+1)]
def kaijou(x):
    if x==1:
        return 1
    if x==2:
        return 2
    if x==3:
        return 6
    if x==4:
        return 24
    if x==5:
        return 120
    if x==6:
        return 720
    if x==7:
        return 5040

s1=1
s2=1
j=1
for i in p:
    s1 += kaijou(n-j)*(i-1)
    j+=1
j=1
for i in q:
    s2 += kaijou(n-j)*(i-1)
    j+=1
k=s1-s2
if k<0:
    print(-k)
else:
    print(k)
Problem p02818 (python)

Fixed submission:
s=input().split()
a=int(s[0])
b=int(s[1])
k=int(s[2])
if a>=k:
    print(str(a-k)+" "+str(b))
else:
    if a+b>=k:
        print("0 "+str(b+a-k))
    else:
        print("0 0")

Buggy submission (verdict: Runtime Error):
s=input().split()
a=int(s[0])
b=int(s[1])
k=int(s[2])
if a>=k:
    print((a-k)+" "+b)
else:
    if a+b>=k:
        print("0 "+b+a-k)
    else:
        print("0 0")
Problem p02999 (python)

Fixed submission:
a=input()
b=a.split()
if int(b[0])<int(b[1]):
  print(0)
else:
  print(10)

Buggy submission (verdict: Runtime Error):
a=input()
b=input()
c=a.split()
d=b.split()
e=0
k=1
u=int(c[1])
for i in range(len(d)):
        e+=int(d[i])
        k+=1
        if e>u:
                break
print(k)

Buggy submission (verdict: Runtime Error):
a=input()
b=input()
c=a.split()
d=b.split()
e=0
k=0
u=int(c[1])
for i in range(len(d)):
        e+=int(d[i])
        k+=1
        if e>u:
                break
print(k)
Problem p03161 (python)

Fixed submission:
n,k=map(int,input().split())
h=list(map(int,input().split()))
cost=[float("inf")]*n
cost[0]=0
for i in range(n-1):
    for j in range(1,min(k+1,n-i)):
        cost[i+j]=min(cost[i+j],cost[i]+abs(h[i+j]-h[i]))

print(cost[-1])

Buggy submission (verdict: Runtime Error):
n,k=map(int,input().split())
h=list(map(int,input().split()))
cost=[float("inf")]*n
cost[0]=0
for i in range(n-1):
    for j in range(1,min(k+1,n-i):
        cost[i+j]=min(cost[i+j],cost[i]+abs(h[i+j]-h[i]))

print(cost[-1])

Buggy submission (verdict: Runtime Error):
n,k=map(int,input().split())
h=list(map(int,input().split()))
cost=[9999]*n
cost[0]=0
for i in range(n-1):
    for j in range(1,min(k+1,n-i+1):
        cost[i+j]=min(cost[i+j],cost[i]+abs(h[i+j]-h[i]))

print(cost[-1])
Problem p03163 (python)

Fixed submission:
n,ww=map(int,input().split())
waight=[0]
value=[0]
for _ in range(n):
    a,b=map(int,input().split())
    waight.append(a)
    value.append(b)
dp=[[0]*(ww+1) for _ in range(n+1)]
for i in range(n):
    for w in range(ww+1):
        if w-waight[i+1]>=0:
            dp[i+1][w]=max(dp[i][w],dp[i][w-waight[i+1]]+value[i+1])
        else:
            dp[i+1][w]=dp[i][w]
print(dp[-1][-1])

Buggy submission (verdict: Runtime Error):
n,ww=map(int,input().split())
waight=[0]
value=[0]
for _ in range(n):
    a,b=map(int,input().split())
    waight.append(a)
    value.append(b)
dp=[[0]*(ww+1) for _ in range(n+1)]
for i in range(n):
    for w in range(ww+1):
        if w-waight[i+1]>=0:
            dp[i+1][w]=max(dp[i][w],dp[i][w-waight[i+1]]+value(i+1))
        else:
            dp[i+1][w]=dp[i][w]
print(dp[-1][-1])
Problem p04044 (python)

Fixed submission:
a,b=map(int,(input().split()))
li=[]
for i in range(a):
    li.append(input())
li2=sorted(li)
c=li2[0]
for j in range(1,a):
    c+=li2[j]
print(c)

Buggy submission (verdict: Runtime Error):
a,b=map(int,(input().split()))
li=[]
for i in range(a):
    li.append(input())
li.sort
a=li[0]
for j in range(1,a):
    a+=li[j]
print(a)
Problem p04045 (python)

Fixed submission:
N,K=map(int,(input().split()))
li=[]
m=set(input())
for j in range(N,100000):
    if len(set(m & set(str(j))))==0:
        print(j)
        break

Buggy submission (verdict: Runtime Error):
N,K=map(int,(input().split()))
li=[]
for i in range(K):
    li.append(int(input()))
for j in range(N,10000):
    k=0
    for t in str(j):
        if int(t) in li:
            k=1
            break
    else:
        if k==0:
            print(j)
Problem p02647 (python)

Fixed submission:
# -*- coding: utf-8 -*-
"""
@author: H_Hoshigi
"""

def simulation(N, K, A_list):
    for k in range(min(K, 42)):
        #next_A_list = [0 for i in range(N)]
        imos_list = [0 for i in range(N)]
        for i in range(N):
            d = A_list[i]
            imos_list[max(i-d, 0)] += 1
            if i+d+1 <= N-1:
                imos_list[i+d+1] -= 1
            #for j in range(i-d, i+d+1):
            #    if j >= 0 and j <= N-1:
            #        next_A_list[j] += 1
        for i in range(1, N):
            imos_list[i] += imos_list[i-1]
        A_list = imos_list[:]
        #print(" ".join([ str(i).zfill(2) for i in A_list]))
    return A_list

def main():
    N, K = map(int, input().split())
    A_list = list(map(int, input().split()))
    print(" ".join([ str(i) for i in simulation(N, K, A_list)]))

if __name__ == "__main__":
    main()

Buggy submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-
"""
@author: H_Hoshigi
"""

def naive_simulation(N, A_list):
    next_A_list = [0 for i in range(N)]
    for i in range(N):
        d = A_list[i]
        for j in range(i-d, i+d+1):
            if j >= 0 and j <= N-1:
                next_A_list[j] += 1
    A_list = next_A_list[:]
    return A_list

def imos_simulation(N, A_list):
        imos_list = [0 for i in range(N)]
        for i in range(N):
            d = A_list[i]
            imos_list[max(i-d, 0)] += 1
            if i+d+1 <= N-1:
                imos_list[i+d+1] -= 1
        for i in range(1, N):
            imos_list[i] += imos_list[i-1]
        A_list = imos_list[:]
    return A_list

def whole_simulation(N, K, A_list):
    for k in range(min(K, 42)):
        #A_list = naive_simulation(N, A_list)
        A_list = imos_simulation(N, A_list)
        #print(" ".join([ str(i).zfill(2) for i in A_list]))
    return A_list

def main():
    N, K = map(int, input().split())
    A_list = list(map(int, input().split()))
    print(" ".join([ str(i) for i in simulation(N, K, A_list)]))

if __name__ == "__main__":
    main()
Problem p02678 (python)

Fixed submission:
# -*- coding: utf-8 -*-
"""
@author: H_Hoshigi
"""

import queue

def main():
    N, M = map(int, input().split())

    connedted_room_list = [ [] for i in range(N)] # ここでNとMを書き間違えていた。
    for i in range(M):
        A, B = map(int, input().split())
        connedted_room_list[A-1].append(B-1)
        connedted_room_list[B-1].append(A-1)

    answer_list = [ -1 for i in range(N)]
    answer_list[0] = 0

    next_rooms_queue = queue.Queue()
    next_rooms_queue.put(0)
    now_room = int()
    while not next_rooms_queue.empty():
        now_room = next_rooms_queue.get()
        for i in connedted_room_list[now_room]:
            if answer_list[i] == -1:
                answer_list[i] = now_room
                next_rooms_queue.put(i)

    
    is_escapable = True
    for i in range(1, N):
        if answer_list[i] == -1:
            is_escapable = False
            break

    if is_escapable:
        print("Yes")
        for i in range(1, N):
            print(answer_list[i]+1)
    else:
        print("No")

if __name__ == "__main__":
    main()

Buggy submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-
"""
@author: H_Hoshigi
"""

import queue

def main():
    N, M = map(int, input().split())

    connedted_room_list = [ [] for i in range(M)]
    for i in range(M):
        A, B = map(int, input().split())
        connedted_room_list[A-1].append(B-1)
        connedted_room_list[B-1].append(A-1)

    answer_list = [ -1 for i in range(N)]
    answer_list[0] = 0

    next_rooms_queue = queue.Queue()
    next_rooms_queue.put(0)
    now_room = int()
    while not next_rooms_queue.empty():
        now_room = next_rooms_queue.get()
        for i in connedted_room_list[now_room]:
            if answer_list[i] == -1:
                answer_list[i] = now_room
                next_rooms_queue.put(i)

    is_escapable = True
    for i in range(1, N):
        if answer_list[i] == -1:
            is_escapable = False
            break
    
    if is_escapable:
        print("Yes")
        for i in range(1, N):
            print(answer_list[i]+1)
    else:
        print("No")

if __name__ == "__main__":
    main()