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

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

x1 = [i for i in x0 if i >= 0]
x2 = list(reversed([i for i in x0 if i < 0]))
count0 = len(x1)
count1 = len(x2)
ans = float('inf')

if count1 == 0:
    print(x1[k-1])
elif count0 == 0:
    print(-x2[k-1])
else:
    if 0 in x1:
        x1.remove(0)
        k -= 1
        count0 -= 1
    for i in range(min(count0, k)):
        if count1 >= k-i-1:
            ans = min(ans, x1[i]*2-x2[k-i-2])
    for i in range(min(count1, k)):
        if count0 >= k-i-1:
            ans = min(ans, -x2[i]*2+x1[k-i-2])
    print(ans)

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

x1 = [i for i in x0 if i >= 0]
x2 = list(reversed([i for i in x0 if i < 0]))
count0 = len(x1)
count1 = len(x2)
ans = float('inf')

if count1 == 0:
    print(x1[k-1])
elif count0 == 0:
    print(x2[k-1])
else:
    for i in range(min(count0, k)):
        ans = min(ans, x1[i]*2-x2[k-i-2])
    for i in range(min(count1, k)):
        ans = min(ans, -x2[i]*2+x1[k-i-2])
    print(ans)
Problem p03361 (python)

Fixed submission:
import sys

H, W = map(int, input().split())
square = []
for i in range(H):
    a = list(map(str, input()))
    square += a

if H == W == 1:
    print('Yes')
    sys.exit()
    
for i in range(H*W):
    if square[i] == '#':
        if i % W != W-1:
            if square[i+1] == '#':
                continue
        if i % W != 0:
            if square[i-1] == '#':
                continue
            
        if i-W >= 0:
            if square[i-W] == '#':
                continue
        if i+W <= H*W:
            if square[i+W] == '#':
                continue
        print('No')
        sys.exit()
        
print('Yes')

Buggy submission (verdict: Runtime Error):
import sys

H, W = map(int, input().split())
square = []
for i in range(H):
    a = list(map(str, input()))
    square += a

for i in range(H*W):
    if square[i] == '#':
        if i % W != 0:
            if square[i+1] == '#' or square[i-1] == '#':
                continue
        else:
            if square[i+1] == '#':
                continue
        if i-W > 0:
            if square[i-W] == '#':
                continue
        if i+W < H*W:
            if square[i+W] == '#':
                continue
        print('No')
        sys.exit()
        
print('Yes')
Problem p03425 (python)

Fixed submission:
from itertools import combinations
N = int(input())
name = [0]*5
ans = 0
for i in range(N):
    a = input()
    if a[0] == 'M': name[0] += 1
    elif a[0] == 'A': name[1] += 1
    elif a[0] == 'R': name[2] += 1
    elif a[0] == 'C': name[3] += 1
    elif a[0] == 'H': name[4] += 1
if sum(name) < 3:
    print(0)
else:
    for i in combinations(name, 3):
        ans += i[0]*i[1]*i[2]
    print(ans)

Buggy submission (verdict: Runtime Error):
N = int(input())
name = [0]*5
ans = 0
for i in range(N):
    a = input()
    if a[0] == 'M': name[0] += 1
    elif a[0] == 'A': name[1] += 1
    elif a[0] == 'R': name[2] += 1
    elif a[0] == 'C': name[3] += 1
    elif a[0] == 'H': name[4] += 1
if sum(name) < 3:
    print(0)
else:
    for i in combinations(name, 3):
        ans += i[0]*i[1]*i[2]
    print(ans)
Problem p03504 (python)

Fixed submission:
def Recording():
    n, c = map(int, input().split())
    num = 2*10**5+1 

    # チャンネルごとにimos配列
    imos = [[0]*num for _ in range(c)]
    
    # imos
    for _ in range(n):
        s, t, c0 = map(int, input().split())
        if imos[c0-1][s*2] < 0 and imos[c0-1][t*2-1] > 0:
            imos[c0-1][s*2] = 0
            imos[c0-1][t*2-1] = 0
        elif imos[c0-1][s*2] < 0:            
            imos[c0-1][s*2] = 0
            imos[c0-1][t*2] -= 1
        elif imos[c0-1][t*2-1] > 0:    
            imos[c0-1][s*2-1] += 1
            imos[c0-1][t*2-1] = 0
        else:
            imos[c0-1][s*2-1] += 1
            imos[c0-1][t*2] -= 1
    ans = [0 for _ in range(num)]
    for i in range(c):
        for j in range(1, num):
            imos[i][j] += imos[i][j-1]
            ans[j] += imos[i][j]
    print(max(ans))
    
if __name__ == '__main__':
    Recording()

Buggy submission (verdict: Runtime Error):
def Recording():
    n, c = map(int, input().split())
    num = 30#2*10**5+1 

    # チャンネルごとにimos配列
    imos = [[0]*num for _ in range(c)]
    
    # imos
    for _ in range(n):
        s, t, c0 = map(int, input().split())
        if imos[c0-1][s*2] < 0 and imos[c0-1][t*2-1] > 0:
            imos[c0-1][s*2] = 0
            imos[c0-1][t*2-1] = 0
        elif imos[c0-1][s*2] < 0:            
            imos[c0-1][s*2] = 0
            imos[c0-1][t*2-1] += 1
        elif imos[c0-1][t*2-1] > 0:    
            imos[c0-1][s*2-1] += 1
            imos[c0-1][t*2-1] = 0
        else:
            imos[c0-1][s*2-1] += 1
            imos[c0-1][t*2] -= 1
    ans = [0 for _ in range(num)]
    for i in range(c):
        for j in range(1, num):
            imos[i][j] += imos[i][j-1]
            ans[j] += imos[i][j]
    print(max(ans))
    
if __name__ == '__main__':
    Recording()
Problem p03569 (python)

Fixed submission:
import sys
s = input()
num = len(s)
l, r = 0, num-1
ans = 0

while l < r:
    if s[l] == s[r]:
        l += 1
        r -= 1
    else:
        ans += 1
        if s[l] == 'x':
            l += 1
        elif s[r] == 'x':
            r -= 1
        else:
            print(-1)
            sys.exit()
print(ans)

Buggy submission (verdict: Runtime Error):
s = input()
num = len(s)
l, r = 0, num-1
ans = 0

while l != r:
    if s[l] == s[r]:
        l += 1
        r -= 1
    else:
        ans += 1
        if s[l] == 'x':
            l += 1
        elif s[r] == 'x':
            r -= 1
        else:
            print(-1)
            break
print(ans)

Buggy submission (verdict: Runtime Error):
s = input()
num = len(s)
l, r = 0, num-1

for i in range(num//2):
    if s[l] == s[r]:
        l += 1
        r -= 1
    else:
        if s[l] == 'x' or s[r] == 'x':
            ans += 1
            l += 1
        else:
            print(-1)
            break
print(ans)
Problem p03575 (python)

Fixed submission:
import queue
n, m = map(int, input().split())
route = [[] for _ in range(n)]
vals = []
for _ in range(m):
    a, b = map(int, input().split())
    route[a-1].append(b-1)
    route[b-1].append(a-1)
    vals.append([a-1, b-1])
ans = m
for i in range(m):
    route2 = set()
    q = queue.Queue()
    q.put(0)
    route[vals[i][0]].remove(vals[i][1])
    route[vals[i][1]].remove(vals[i][0])
    while not q.empty():
        a = q.get()
        if not a in route2:
            route2.add(a)
            for j in route[a]:
                q.put(j)
        if len(route2) == n:
            ans -= 1
            break
    route[vals[i][0]].append(vals[i][1])
    route[vals[i][1]].append(vals[i][0])
print(ans)

Buggy submission (verdict: Runtime Error):
import queue
n, m = map(int, input().split())
route = [[] for _ in range(n)]
vals = []
for _ in range(m):
    a, b = map(int, input().split())
    route[a-1].append(b-1)
    route[b-1].append(a-1)
    vals.append([a-1, b-1])
ans = m
for i in range(m):
    route2 = set()
    q = queue.Queue()
    q.put(i)
    try:
        route[vals[i][0]].remove(vals[i][1])
        route[vals[i][1]].remove(vals[i][0])
    except:
        pass
    while not q.empty():
        a = q.get()
        if not a in route2:
            route2.add(a)
            for j in route[a]:
                q.put(j)
        if len(route2) == n:
            ans -= 1
            break
    try:
        route[vals[i][0]].append(vals[i][1])
        route[vals[i][1]].append(vals[i][0])
    except:
        pass
print(ans)

Buggy submission (verdict: Runtime Error):
import queue
n, m = map(int, input().split())
route = [[] for _ in range(n)]
vals = []
for _ in range(m):
    a, b = map(int, input().split())
    route[a-1].append(b-1)
    route[b-1].append(a-1)
    vals.append([a-1, b-1])
ans = m
for i in range(m):
    route2 = set()
    q = queue.Queue()
    q.put(i)
    route[vals[i][0]].remove(vals[i][1])
    route[vals[i][1]].remove(vals[i][0])
    while not q.empty():
        a = q.get()
        if not a in route2:
            route2.add(a)
            for j in route[a]:
                q.put(j)
    if len(route2) == n:
        ans -= 1
    route[vals[i][0]].append(vals[i][1])
    route[vals[i][1]].append(vals[i][0])
    
print(ans)
Problem p03606 (python)

Fixed submission:
n = int(input())
c = [0]*10**5
for i in range(n):
    a, b = map(int, input().split())
    for j in range(a, b+1):
        c[j-1] = 1
print(sum(c))

Buggy submission (verdict: Runtime Error):
n = int(input())
c = [0]*10**5
for i in range(n):
    a, b = map(int, input().split())
    for j in range(a, b+1):
        c[j] = 1
print(sum(c))
Problem p03607 (python)

Fixed submission:
N = int(input())
ans = set()

for _ in range(N):
    a = int(input())
    if not a in ans:
        ans.add(a)
    else:
        ans.remove(a)
print(len(ans))

Buggy submission (verdict: Runtime Error):
N = int(input())
ans = [0]*(10**9)

for _ in range(N):
    a = int(input())
    if ans[a-1] == 0:
        ans[a-1] += 1
    else:
        ans[a-1] = 0

print(sum(ans))
Problem p03645 (python)

Fixed submission:
import sys
N, M = map(int, input().split())
route = [[] for i in range(N)]
for _ in range(M):
    a, b = map(int, input().split())
    route[a-1].append(b)
    
for i in route[0]:
    if len(route) != 1:
        for j in route[i-1]:
            if j == N:
                print('POSSIBLE')
                sys.exit()
    else:
        if i == N:
            print('POSSIBLE')
            sys.exit()
                
print('IMPOSSIBLE')

Buggy submission (verdict: Runtime Error):
import sys
N, M = map(int, input().split())
route = [[] for i in range(M)]
for _ in range(M):
    a, b = map(int, input().split())
    route[a-1].append(b)
    
for i in route[0]:
    if len(route) != 1:
        for j in route[i-1]:
            if j == N:
                print('POSSIBLE')
                sys.exit()
    else:
        if i == N:
            print('POSSIBLE')
            sys.exit()
                
print('IMPOSSIBLE')
Problem p03994 (python)

Fixed submission:
s = list(input())
k = int(input())
num = len(s)

for i in range(num):
    a = 122-ord(s[i])+1
    if a <= k and s[i] != 'a':
        k -= a
        s[i] = 'a'
if k > 0:
    s[-1] = chr(ord(s[-1])+k%26)
print(*s, sep='')

Buggy submission (verdict: Runtime Error):
s = list(input())
k = int(input())
num = len(s)
for i in range(num):
    a = 122-ord(s[i])+1
    if a <= k:
        k -= a
        s[i] = 'a'
if k > 0:
    s[-1] = chr(ord(s[-1])+k)
print(*s, sep='')
Problem p03000 (python)

Fixed submission:
inp = input().split(" ")
n = int(inp[0])
x = int(inp[1])
l = input().split(" ")
d = 0
count = 1

for i in range(n):
  d += int(l[i])
  if d <= x:
    count += 1
  else:
    break
  
print(count)

Buggy submission (verdict: Runtime Error):
variable = input().split(" ")
n = int(variable[0])
x = int(variable[1])
l = input().split(" ")
d = 0
i = 0

while d <= x:
  d += int(l[i])
  i += 1
  
print(i)

Buggy submission (verdict: Runtime Error):
variable = input().split(" ")
n = int(variable[0])
x = int(variable[1])
l = input().split(" ")
d = 0
i = 0

while d < x:
  d += int(l[i])
  i += 1
  
print(i)
Problem p02573 (python)

Fixed submission:
# from pprint import pprint
#
# N, M = map(int, input().split())
#
# G = [[0 for _ in range(N)] for _ in range(N)]
#
# for _ in range(M):
#     a, b = list(map(int, input().split()))
#     G[a-1][b-1] = G[b-1][a-1] = 1
#
# pprint(sum(sum(g) for g in G) // 2)

from collections import Counter

class UnionFindBasic():
    """via https://note.nkmk.me/python-union-find/
    """
    def __init__(self, n: int):
        # < 0 は根
        self.n = n
        self.parents = [-1] * n

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

    def union(self, x: int, y: int):
        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 main():
    N, M = map(int, input().split())

    if M == 0:
        print(1)
        return

    uf = UnionFindBasic(N)

    for _ in range(M):
        a,b = list(map(lambda x: int(x)-1, input().split()))
        uf.union(a,b)

    ans = 0
    for i in range(N):
        ans = max(ans, uf.size(i))
    print(ans)

if __name__ == '__main__':
    main()

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

class UnionFindBasic():
    """via https://note.nkmk.me/python-union-find/#_3
    """
    def __init__(self, n):
        self.parents = list(range(n))

    def find(self, x: int) -> int:
        if self.parents[x] == x: return x
        return self.find(self.parents[x])

    def union(self, x: int, y: int):
        x = self.find(x)
        y = self.find(y)
        if x == y: return
        if x > y: x,y = y,x
        self.parents[y] = x

if __name__ == '__main__':
    N, M = map(int, input().split())

    if M == 0:
        print(0)
        return

    uf = UnionFindBasic(N)

    for _ in range(M):
        a,b = list(map(lambda x: int(x)-1, input().split()))
        uf.union(a,b)

    print(Counter(uf.parents).most_common()[0][1])

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

class UnionFindBasic():
    """via https://note.nkmk.me/python-union-find/#_3
    """
    def __init__(self, n):
        self.parents = list(range(n))

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

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if x == y: return
        self.parents[y] = x

if __name__ == '__main__':
    N, M = map(int, input().split())

    uf = UnionFindBasic(N)

    for _ in range(M):
        a,b = list(map(lambda x: int(x)-1, input().split()))
        if a < b:
            uf.union(a,b)
        else:
            uf.union(b,a)

    print(Counter(uf.parents).most_common()[0][1])
Problem p02608 (python)

Fixed submission:
N = int(input())
ans = [0 for _ in range(1,10101)]

for x in range(1,101):
    for y in range(1,101):
        for z in range(1,101):
            n = x*x + y*y + z*z + x*y + y*z + z*x
            if n < N+1:
                ans[n-1] += 1

print(*ans[:N],sep='\n')

Buggy submission (verdict: Runtime Error):
N=int(input());a=[0]*10_001;X=Y=Z=range(1,101)
for x in X:
    for y in Y:
        for z in Z:
            if (n:=x*x+y*y+z*z+x*y+y*z+z*x)<N+1:a[n-1]+=1
print(*a[:N],sep='\n')
Problem p02612 (python)

Fixed submission:
N = int(input())

if N % 1000 == 0:
    print(0)
else:
    print(1000 - (N % 1000))

Buggy submission (verdict: Runtime Error):
print(1000 - (int(input()) % 1000)) % 1000
Problem p02683 (python)

Fixed submission:
import sys
import itertools
# import math
# from pprint import pprint
import numpy as np


N,M,X = map(int, sys.stdin.readline().strip().split())
C = []
for _ in range(0, N):
    C.append(list(map(int, sys.stdin.readline().strip().split())))

# N = 3
# M = 3
# X = 10
#
# C = [
#     [60,2,2,4],
#     [70,8,7,9],
#     [50,2,3,9],
# ]

C.sort(key=lambda x:x[0])

ans = None
for i in range(1, N+1):
    for j in itertools.combinations(C, i):
        l = [k[1:] for k in j]
        # pprint(l)
        if len(l) > 1:
            ll = np.sum(l, axis=0)
            # print(ll)
            flag = all((m >= X) for m in ll)
        else:
            flag = all((m >= X) for m in l[0])
        if flag:
            n = np.sum(j, axis=0)[0]
            if ans == None or  ans > n:
                ans = n

if ans:
    print(ans)
else:
    print(-1)

Buggy submission (verdict: Runtime Error):
import sys
import itertools
# import math
# from pprint import pprint
import numpy as np


N,M,X = map(int, sys.stdin.readline().strip().split())
C = []
for _ in range(0, N):
    C.append(list(map(int, sys.stdin.readline().strip().split())))

# N = 3
# M = 3
# X = 10
#
# C = [
#     [60,2,2,4],
#     [70,8,7,9],
#     [50,2,3,9],
# ]

C.sort(key=lambda x:x[0])

for i in range(1, N+1):
    for j in itertools.combinations(C, i):
        l = [k[1:] for k in j]
        # pprint(l)
        if len(l) > 1:
            ll = np.sum(l, axis=0)
            # print(ll)
            flag = all((m >= X) for m in ll)
        else:
            flag = all((m >= X) for m in l[0])
        if flag:
            print(np.sum(j, axis=0)[0])
            sys.exit()
print(-1)
Problem p02843 (python)

Fixed submission:
X = int(input())

l = [1,2,3,4,5]
a = X // 100
b = X % 100

ans = 0
for i in l:
    if b % i == 0:
        if b // i <= a:
            ans = 1
            break

print(ans)

Buggy submission (verdict: Runtime Error):
X = int(input())

l = [0,1,2,3,4,5]
a = X // 100
b = X % 100

if ((b // a) in l) and ((b % a) in l):
    print('1')
else:
    print('0')

Buggy submission (verdict: Runtime Error):
X = int(input())

a = X // 100
b = X % 100
print(1 if (b // a in [0,1,2,3,4,5]) and (b % a in [0,1,2,3,4,5]) else 0)
Problem p03720 (python)

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

ans = [0] * N

for _ in range(M):
    a,b = map(int, input().split())
    ans[a-1] += 1
    ans[b-1] += 1

print(*ans, sep='\n')

Buggy submission (verdict: Runtime Error):
N,_,*L=map(int,open(0).read().split());for n in range(N):print(L.count(n+1))
Problem p02747 (python)

Fixed submission:
a = input()
l = list(a)
num = len(l)
TorF = True

if num % 2 == 0:
    b = int(num/2)
    for i in range(b):
        if not (a[2*i] == 'h' and a[2*i + 1] == 'i'):
            TorF = False
            break
else:
    TorF = False

if TorF == True:
    print('Yes')
else:
    print('No')

Buggy submission (verdict: Runtime Error):
a = input()
l = list(a)
num = len(l)
TorF = True

if num % 2 == 0:
    b = num/2
    for i in range(b):
        if not a(2*i ) == 'h' and a(2*i + 1) == 'i':
            TorF = False
            break
else:
    TorF = False

if TorF == True:
    print('Yes')
else:
    print('No')
Problem p02646 (python)

Fixed submission:
AV = input().split()
BW = input().split()
T = int(input())

if(int(AV[0]) > int(BW[0])):
  T *= -1

a = int(AV[0]) + int(AV[1]) * T
b = int(BW[0]) + int(BW[1]) * T

if(T >=0 and a >= b):
  print('YES')
elif(T <= 0 and a <= b):
  print('YES')
else:
  print('NO')

Buggy submission (verdict: Runtime Error):
AV = input().split()
BW = input().split()
T = int(input())

if(int(AV[0]) > int(BW[0])):
  T *= -1

a = int(AV[0]) + int(AV[1]) * T
b = int(BW[0]) + int(BW[1]) * T

if(T >=0 && a >= b):
  print('YES')
elif(T <= 0 && a >= b):
  print('YES')
else:
  print('NO')
Problem p02658 (python)

Fixed submission:
n = int(input())
str_list = input().split()

list = [int(k) for k in str_list]

list.sort(reverse=True)

result = 1

if(0 in list):
  print('0')
  exit()

for i in range(n):
  result = result * list[i]
  if(result > 1000000000000000000):
    print('-1')
    exit()

print(result)

Buggy submission (verdict: Runtime Error):
n = int(input())
str_list = input().split()

list = [int(k) for k in str_list]

list.sort(reverse=True)

result = 1

if(0 in list):
  print('0')
  return

for i in range(n):
  result = result * list[i]
  if(result >= 1000000000000000000):
    print('-1')
    return

print(result)

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

list.sort(reverse=True)

result = 1

if(0 in list):
  print('0')
  return

for i in range(n):
  result = result * list[i]
  if(result >= 1000000000000000000):
    print('-1')
    return

print(result)

Buggy submission (verdict: Runtime Error):
n = int(input())
str_list = input().split()

result = 1

for i in range(n):
  result = result * int(str_list[i])
  
t = 1
for j in range(18)
  t = t * 10
if(result > t):
  print('-1')
else:
  print(result)

Buggy submission (verdict: Runtime Error):
n = int(input())
str_list = input().split()

result = 1

for i in range(n):
  result = result * int(str_list(i))
  
t = 1
for j in range(18)
  t = t * 10
if(result > t):
  print('-1')
else:
  print(result)

Buggy submission (verdict: Runtime Error):
n = int(input())
str_list = input().split()

result = 1

for i in range(n):
  result = result + str_list(i)
  
t = 1
for j in range(18)
  t = t * 10
if(result > t):
  print('-1')
else:
  print(result)
Problem p02796 (python)

Fixed submission:
def main():
    N = int(input())
    X = []
    L = []
    for i in range(N):
        x, l = [int(s) for s in input().split()]
        X.append(x)
        L.append(l)

    ranges = []
    for i in range(N):
        ranges.append((X[i] - L[i], X[i] + L[i]))
    ranges.sort(key=lambda x: x[1])

    cnt = len(ranges)
    end = ranges[0][1]
    for i in range(1, len(ranges)):
        if ranges[i][0] < end:
            cnt -= 1
        else:
            end = ranges[i][1]
    print(cnt)


if __name__ == "__main__":
    main()

Buggy submission (verdict: Runtime Error):
def main():
    N = int(input())
    X = []
    L = []
    for i in range(N):
        x, l = [int(s) for s in input().split()]
        X.append(x)
        L.append(l)

    ranges = []
    for i in range(N):
        ranges.append((X[i] - L[i], X[i] + L[i]))
    ranges.sort(key=lambda x: x[0])

    i = 0
    while True:
        if ranges[i][1] > ranges[i + 1][0]:
            ranges.pop(i + 1)
        else:
            i += 1
        if i == len(ranges) - 1:
            break
    print(len(ranges))


if __name__ == "__main__":
    main()

Buggy submission (verdict: Runtime Error):
    def main():
        N = int(input())
        X = []
        L = []
        for i in range(N):
            x, l = [int(s) for s in input().split()]
            X.append(x)
            L.append(l)
     
        ranges = []
        for i in range(N):
            ranges.append((X[i] - L[i], X[i] + L[i]))
        ranges.sort(key=lambda x: x[0])
     
        while True:
            dup = [0 for i in range(len(ranges))]
            for i in range(len(ranges) - 1):
                if ranges[i][1] > ranges[i + 1][0]:
                    dup[i] += 1
                    dup[i + 1] += 1
     
            remove_index = [(i, dup[i]) for i in range(len(dup))]
            remove_index.sort(key=lambda x: x[1], reverse=True)
            if remove_index[0][1] == 0:
                break
            ranges.pop(remove_index[0][0])
        print(len(ranges))
     
     
    if __name__ == "__main__":
        main()
Problem p02678 (python)

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

to = [[] for i in range(100010)]

for i in range(M):
    a, b = map(int, input().split())
    to[a].append(b)
    to[b].append(a)

dist = [0] * (N+1)
q = [1]
dist[0] = -1
#print(to[:4])

dist = [0] * N
pre = [0] * N

while len(q) != 0:
    a = q.pop(0)
    for i in to[a]:
        if dist[i-1] == 0:
            dist[i-1] = dist[a-1] + 1
            pre[i-1] = a
            q.append(i)
    #print(q)

print("Yes")
for i in range(1, N):
    print(pre[i])

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

to = [[] for i in range(100010)]

for i in range(M):
    a, b = map(int, input().split())
    to[a].append(b)
    to[b].append(a)

dist = [0] * (N+1)
q = [1]

#print(to[:4])

dist = [0] * N
pre = [0] * N

while len(q) != 0:
    a = q.pop(0)
    for i in to[a]:
        if dist[i-1] == 0:
            dist[i-1] = dist[a-1] + 1
            pre[i-1] = a
            q.append(i)
    print(q)

print("Yes")
for i in range(1, N):
    print(pre[i])