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

Fixed submission:
from collections import deque
n, m = map(int, input().split())
way = [[] for i in range(n + 1)]
ans = [-1 for i in range(n + 1)]
reached = [0 for i in range(n + 1)]
for i in range(m):
    a, b = map(int, input().split())
    way[a].append(b)
    way[b].append(a)
D = deque([1])
while D:
    go = D.popleft()
    for i in way[go]:
        if reached[i] == 0:
            D.append(i)
            reached[i] = 1
            ans[i] = go
print('Yes')
for i in range(2, n + 1):
    print(ans[i])

Buggy submission (verdict: Runtime Error):
from collections import deque
n, m = map(int, input().split())
route =[[] for i in range(m+1)]
for i in range(m):
    a, b = map(int, input().split())
    route[a].append(b)
    route[b].append(a)
visited = [0 for i in range(n+1)]
visited[1] = 1
ans = [0 for i in range(n+1)]
D = deque()
D.append(1)
while D:
    visit = D.popleft()
    for i in route[visit]:
        if visited[i] == 0:
            D.append(i)
            visited[i] = 1
            ans[i] = visit
print('Yes')
for i in range(2, n+1):
    print(ans[i])
Problem p02713 (python)

Fixed submission:
import math
k = int(input())
ansA, ansB, ansC = 0, 0, 0
for a in range(k):
    ansC += a+1
    for b in range(k-a-1):
        GCDab = math.gcd(a+1, a+b+2)
        ansB += GCDab
        for c in range(k-a-b-2):
            GCDabc = math.gcd(GCDab, a+b+c+3)
            ansA += GCDabc
ans = ansA * 6 + ansB * 6 + ansC
print(ans)

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

def gcd(x, y):
    if x / y == 0: return y
    return gcd(y, x % y)

for i in range(1, n + 1):
    for j in range(1, n + 1):
        for k in range(1, n + 1):
            ans += gcd(gcd(i, j), k)
print(ans)

Buggy submission (verdict: Runtime Error):
import math
n=int(input())
ans=0
for i in range(1,n+1):
    for j in range(1,n+1):
        for k in range(1,n+1):
            ans+=gcd(gcd(i,j),k)
print(ans)
Problem p02741 (python)

Fixed submission:
k = int(input())
arr = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
print(arr[k - 1])

Buggy submission (verdict: Runtime Error):
from decimal import *
getcontext().prec = 100
a, b, c = map(int, input().split())
if Decimal(str((c - a - b) ** 2)) - Decimal(str(4 * a * b)) > 0:
    print('Yes')
else:
    print('No')

Buggy submission (verdict: Runtime Error):
k = int(input())
arr = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
print(arr[k + 1])
Problem p02761 (python)

Fixed submission:
n, m = map(int, input().split())
a = [-1 for i in range(n)]

for i in range(m):
    s, c = map(int, input().split())
    if a[s - 1] == -1:
        a[s - 1] = c
    elif a[s - 1] == c:
        pass
    else:
        print('-1')
        exit()

if n == 1 and a[0] == 0:
    print('0')
    exit()
if n == 1 and a[0] == -1:
    print('0')
    exit()
if n != 1 and a[0] == 0:
    print('-1')
    exit()

for i in range(n):
    if a[i] == -1:
        a[i] = 0

if a[0] == 0:
    a[0] = 1
ans = ''
for i in range(n):
    ans += str(a[i])
print(ans)

Buggy submission (verdict: Runtime Error):
n, m = map(int, input().split())
a = [-1 for i in range(n)]
possibility = True
for i in range(m):
    s, c = map(int, input().split())
    if a[s - 1] == -1:
        a[s - 1] = c
    elif a[s - 1] == c:
        pass
    else:
        possibility = False
if a[0] == 0:
    possibility = False

if possibility == True:
    ans = ''
    for i in range(n):
        ans += a[i]
    print(ans)
else:
    print('-1')
Problem p02765 (python)

Fixed submission:
n, r  = map(int, input().split())
if n >=10:
	print(r)
else:
	print(r+1000-100*n)

Buggy submission (verdict: Runtime Error):
n, r  = map(int, input().split())
if n >=10:
	print(r)
else:
	print(r-1000+100n)
Problem p02767 (python)

Fixed submission:
n = int(input())
a = list(map(int,input().split()))
minHP = float('inf')
for i in range(max(a)):
    HP = 0
    for j in range(n):
        HP += (a[j] - (i + 1)) ** 2
    if minHP > HP:
        minHP = HP
print(minHP)

Buggy submission (verdict: Runtime Error):
n = int(input())
a = list(map(int,input().split()))
minHP = float('inf')
for i in range(n):
    HP = 0
    for j in range(100):
        HP += (a[j] - (i + 1)) ** 2
    if minHP > HP:
        minHP = HP
print(minHP)

Buggy submission (verdict: Runtime Error):
n = int(input())
a = list(map(int,input().split()))
minHP = float('inf')
for i in range(n):
    HP = 0
    for j in range(max(a)):
        HP += (a[j] - (i + 1)) ** 2
    if minHP > HP:
        minHP = HP
print(minHP)
Problem p02783 (python)

Fixed submission:
h, a = map(int, input().split())
ans = h // a
if h % a != 0:
    ans += 1

print(ans)

Buggy submission (verdict: Runtime Error):
H, n = map(int, input().split())
List = [[0 for i in range(4)] for j in range(n)]
for i in range(n):
    a, b = map(int, input().split())
    List[i][0] = b / a
    List[i][1] = b / H
    List[i][2] = a
    List[i][3] = b

def recal():
    for i in range(n):
        b = List[i][3]
        List[i][1] = b / H

sList = sorted(List)
MP = 0
k = 0
while H > 0:
    if sList[k][2] <= H:
        H -= sList[k][2]
        MP += sList[k][3]
        recal()
    else:
        if sList[k + 1][2] <= H:
            if sList[k][1] <= sList[k + 1][0]:
                H -= sList[k][2]
                MP += sList[k][3]
                recal()
                break
            else:
                H -= sList[k + 1][2]
                MP += sList[k + 1][3]
                recal()
                k += 1
        else:
            if sList[k][1] <= sList[k + 1][1]:
                H -= sList[k][2]
                MP += sList[k][3]
                recal()
                break
            else:
                H -= sList[k + 1][2]
                MP += sList[k + 1][3]
                recal()
                k += 1
print(MP)
Problem p02802 (python)

Fixed submission:
n, m = map(int, input().split())
c = [input().split() for i in range(m)]
for i in range(m):
    c[i][0] = int(c[i][0])
AC, WA = 0, 0
acwa = [[0, 0] for i in range(n)]
for i in range(m):
    if acwa[c[i][0] - 1][0] == 0:
        if c[i][1] == 'AC':
            acwa[c[i][0] - 1][0] += 1
            AC += 1
            WA += acwa[c[i][0] - 1][1]
        else:
            acwa[c[i][0] - 1][1] += 1

print(AC, WA)

Buggy submission (verdict: Runtime Error):
n, m = map(int, input().split())
c = [input().split() for i in range(m)]
for i in range(m):
    c[i][0] = int(c[i][0])
AC, WA = 0, 0
aclist = [0 for i in range(n)]
for i in range(m):
    if aclist[c[i][0]] == 0:
        if c[i][1] == 'AC':
            aclist[c[i][0]] += 1
            AC += 1
        else:
            WA += 1
print(AC, WA)

Buggy submission (verdict: Runtime Error):
n, m = map(int, input().split())
c = [input().split() for i in range(m)]
for i in range(m):
    c[i][0] = int(c[i][0])
AC, WA = 0, 0
aclist = [0 for i in range(n)]
for i in range(n):
    if aclist[c[i][0]] == 0:
        if c[i][1] == 'AC':
            aclist[c[i][0]] += 1
            AC += 1
        else:
            WA += 1
print(AC, WA)

Buggy submission (verdict: Runtime Error):
n, m = map(int, input().split())
c = [input().split() for i in range(m)]
for i in range(m):
    c[i][0] = int(c[i][0])
AC, WA, i =0, 0, 0
for i in range(n):
    for j in range(m):
        if c[j][0] == i + 1:
            if c[j][1] == 'WA':
                WA += 1
                if j == m:
                    break
            elif c[j][i] == 'AC':
                AC += 1
                break 
print(AC, WA)

Buggy submission (verdict: Runtime Error):
n, m = map(int, input().split())
c = [list(map(int, input().split())) for i in range(n)]
AC, WA, i =0, 0, 0
while i < n:
    if c[i][0] == i + 1:
        if c[i][1] == 'WA':
            WA += 1
        else:
            AC += 1
            i += 1
print(AC, WA)
Problem p02813 (python)

Fixed submission:
import itertools
n = int(input())
P = int(input().replace(' ', ''))
Q = int(input().replace(' ', ''))
N = [i + 1 for i in range(n)]
per = list(itertools.permutations(N))
lis = []
for oc in per:
    lis.append(int(''.join(map(str, list(oc)))))
a = lis.index(P)
b = lis.index(Q)
print(abs(a - b))

Buggy submission (verdict: Runtime Error):
import itertools
n = int(input())
P = list(map(int, input().replace(' ', '')))
Q = list(map(int, input().replace(' ', '')))
N = [i + 1 for i in range(n)]
per = list(itertools.permutations(N))
lis = []
for oc in per:
    lis.append(int(''.join(map(str, list(oc)))))
a = lis.index(P)
b = lis.index(Q)
print(abs(a - b))

Buggy submission (verdict: Runtime Error):
import itertools
n = int(input())
P = list(map(int, input().replace(' ', '')))
Q = list(map(int, input().replace(' ', '')))
N = [i + 1 for i in range(n)]
per = list(itertools.permutations(N))
lis = []
for oc in range(per):
    lis.append(int(''.join(map(str, list(per)))))
a = lis.index(P)
b = lis.index(Q)
print(abs(a - b))

Buggy submission (verdict: Runtime Error):
n = int(input())
P = list(map(str, input().split()))
Q = list(map(str, input().split()))
p, q = '' , ''
for i in range(n):
    p += P[i]
    q += Q[i]

a, b = 0, 0
num = 10 ** (n - 1)
count = 0
found = False
while found == False:
    num += 1
    waru = num
    conv_num = ''
    while waru != 0:
        conv_num = str(waru % (n + 1)) + conv_num
        waru = waru // (n + 1)
    if 0 in conv_num:
        pass
    else:
        count += 1
        if conv_num == p:
            a = count
        if conv_num == q:
            b = count
    if p != 0 and q != 0:
        found = True
ans = a - b
if ans < 0:
    ans *= -1
print(ans)
Problem p02848 (python)

Fixed submission:
n = int(input())
s = str(input())
ans = ''
for i in s:
    t = (int(ord(i) + n - 64)) % 26
    if t == 0:
        ans += 'Z'
    else:
        ans += chr(t + 64)
print(ans)

Buggy submission (verdict: Runtime Error):
n = int(input())
s = str(input())
if int(ord(s)) + n > 122:
    print(chr(int(ord(s)) + n - 26))
else:
    print(chr(int(ord(s)) + n))

Buggy submission (verdict: Runtime Error):
n = int(input())
s = str(input())
if int(ord(s)) + n > 122:
    print(chr(int(ord(s)) + n - 26))
else:
    print(int(ord(s)) + n)
Problem p03337 (python)

Fixed submission:
a,b = map(int, input().split())
s,t,u=a+b,a-b,a*b
if s>=t and s>=u:
  print(s)
elif t>=s and t>=u:
  print(t)
else:
  print(u)

Buggy submission (verdict: Runtime Error):
a=int(input())
b=int(input())
s,t,u=a+b,a-b,a*b
if s>t and s>u:
  print(s)
elif t>s and t>u:
  print(t)
else:
  print(u)

Buggy submission (verdict: Runtime Error):
a=int(input())
b=int(input())
s,t,u=a+b,a-b,a*b
if s>t and s>u:
  print(s)
elif t>s and t>u:
  print(t)
else:
  print(u)

Buggy submission (verdict: Runtime Error):
a=input()
b=input()
s,t,u=a+b,a-b,a*b
if s>t and s>u:
  print(s)
elif t>s and t>u:
  print(t)
else:
  print(u)
Problem p02706 (python)

Fixed submission:
m,n = list(map(int,input().split()))
li = list(map(int,input().split()))
if sum(li)>m:
  print(-1)
else:
  print(m - sum(li))

Buggy submission (verdict: Runtime Error):
m,n = int(input())
li = list(map(int,input().split()))
if sum(li)>m:
  print(-1)
else:
  print(m - sum(li))
Problem p02801 (python)

Fixed submission:
a = input()
print(chr(ord(a)+1))

Buggy submission (verdict: Runtime Error):
a = input()
print(chr(ord(a)+1)
Problem p02830 (python)

Fixed submission:
size = int(input())
a,b = list(map(str,input().split()))
ans = ""
for i in range(size):
  ans += a[i]
  ans += b[i]
print(ans)

Buggy submission (verdict: Runtime Error):
size = int(input())
a,b = list(map(int,input().split()))
ans = ""
for i in range(size):
  ans += a[i]
  ans += b[i]
print(ans)

Buggy submission (verdict: Runtime Error):
size = int(input())
a,b = list(map(int,input().split()))
ans = ""
for i in size:
  ans += a[i]
  ans += b[i]
print(ans)
Problem p02865 (python)

Fixed submission:
n = int(input())
print((n-1)//2)

Buggy submission (verdict: Runtime Error):
n = int(input())
print n//2
Problem p02934 (python)

Fixed submission:
size = int(input())
li = list(map(int,input().split()))
s = 0
for i in li:
    s += (1/i)
print(1/s)

Buggy submission (verdict: Runtime Error):
size = int(input())
li = list(map(int,input().split()))
s = 0
for i in li:
  s += 1/i
print(1/s
Problem p03587 (python)

Fixed submission:
n = input()
print(n.count('1'))

Buggy submission (verdict: Runtime Error):
n = input()
return n.count('1');
Problem p03337 (python)

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

n_sum = n[0] + n[1]
n_sub = n[0] - n[1]
n_mul = n[0] * n[1]

ans = max(n_sum,n_sub,n_mul)
print(ans)

Buggy submission (verdict: Runtime Error):


N = int(input())
S = input()
#N = 12
#S = 'WEWEWEEEWWWE'


min = 1000000
e = S.count('E')
w = 0

for i in range(0,N-1):
    flag = 0
    now = S[i]
    if now == 'E':
        e = e - 1
    else:
        flag = 1
    sum = w + e
    if min > sum:
        min = sum
    if flag:
        w = w + 1
print(min)
Problem p02612 (python)

Fixed submission:
n = int(input())

x = n // 1000
if n % 1000 == 0:
    print(1000 * x - n)
else:
    print(1000 * (x + 1) - n)

Buggy submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(2000)

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

mod = 10**9 + 7

als = []
test = True
for i in an:
    if i > 0:
        test = False
    als.append([abs(i), i])
if test and k % 2 == 1:
    an.sort(reverse=True)
    ans = 1
    for i in range(k):
        ans = ans * an[i] % mod
    print(ans)
    exit()

als.sort(reverse=True)

ans = 1
min_p = 10**9 + 1
min_m = - 10**9 + 1
cnt = 0
for i in range(k):
    x, y = als[i]
    ans = ans * x % mod
    if y > 0:
        min_p = x
    if y < 0:
        min_m = x
        cnt += 1

if cnt % 2 == 0:
    print(ans)
    exit()

max_p = 0
max_m = 0
for j in range(k, n):
    if als[j][1] > 0:
        max_p = max(max_p, als[j][0])
    if als[j][1] < 0:
        max_m = max(max_m, als[j][0])
    if max_p != 0 and max_m != 0:
        break

def power(x, y):
    if   y == 0     : return 1
    elif y == 1     : return x % mod
    elif y % 2 == 0 : return power(x, y/2)**2 % mod
    else            : return power(x, y/2)**2 * x % mod

if max_m == 0 or max_p / min_m >= max_m / min_p:
    print(ans * max_p * power(min_m, mod-2) % mod)
else:
    print(ans * max_m * power(min_p, mod-2) % mod)
Problem p02639 (python)

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

for i in range(5):
    if x[i] == 0:
        print(i + 1)
        exit()

Buggy submission (verdict: Runtime Error):
from collections import deque
n = int(input())
an = list(map(int, input().split()))

an.sort()
an = deque(an)
ls = deque()
same = -1
while an:
    a = an.popleft()
    t = True
    if same == a:
      continue
    for i in ls:
        if i > a ** (1/2):
            t = False
            break
        if a == i:
            ls.pop()
            same = a
            t = False
            break
        if a % i == 0:
            t = False
            break
    if t:
        ls.append(a)

print(len(ls))

Buggy submission (verdict: Runtime Error):
from collections import deque
n = int(input())
an = list(map(int, input().split()))

an.sort()
an = deque(an)
ls = deque()
same = -1
while an:
    a = an.popleft()
    t = True
    if same == a:
      continue
    for i in ls:
        if a == i:
            ls.pop()
            same = a
            t = False
            break
        if a % i == 0:
            t = False
            break
    if t:
        ls.append(a)

print(len(ls))
Problem p02727 (python)

Fixed submission:
x, y, a, b, c = map(int, input().split())
pn = list(map(int, input().split()))
qn = list(map(int, input().split()))
rn = list(map(int, input().split()))

pn.sort(reverse=True)
qn.sort(reverse=True)

pqr = pn[:x] + qn[:y] + rn
pqr.sort(reverse=True)
  
print(sum(pqr[:x+y]))

Buggy submission (verdict: Runtime Error):
x, y, a, b, c = map(int, input().split())
pn = list(map(int, input().split()))
qn = list(map(int, input().split()))
rn = list(map(int, input().split()))

pn.sort(reverse=True)
qn.sort(reverse=True)
rn.sort(reverse=True)

pn = pn[:x]
qn = qn[:y]
rcount = 0

while min(pn[-1], qn[-1]) <= rn[0]:
  if pn[-1] >= qn[-1]:
    rcount += rn[0]
    del qn[-1]
  else:
    rcount += rn[0]
    del pn[-1]
  del rn[0]
  if len(rn) == 0:
    break
  
print(sum(pn) + sum(qn) + rcount)
Problem p02730 (python)

Fixed submission:
s = input()
n = len(s)

if s[:int((n-1)/2)] == s[int((n+3)/2)-1:] and s[:int((n-1)/2)] == (s[int((n+3)/2)-1:])[::-1]:
  print('Yes')
else:
  print('No')

Buggy submission (verdict: Runtime Error):
s = input()

if s[:(n-1)/2] == s[(n+3)/2:] and s[:(n-1)/2] == s[(n+3)/2:]:
  print('Yes')
else:
  print('No')

Buggy submission (verdict: Runtime Error):
s = input()

n = len(s)
front_s = s[:(n-1)//2]
back_s = s[(n+3)//2-1:]
n1 = len(front_s)

if front_s == back_s[::-1]:
  if (n-1)//2%2 == 1:
    if front_s[:(n1-1)//2] == (front_s[(n1+3)//2-1:])[-1] and back_s[:(n1-1)//2] == (back_s[(n1+3)//2-1:])[::-1]:
      print('Yes')
    else:
      print('No')
  else:
    if front_s[:n1//2] == (front_s[n1//2:])[-1] and back_s[:n1//2] == (back_s[n1//2:])[::-1]:
      print('Yes')
    else:
      print('No')
else:
  print('No')
Problem p02756 (python)

Fixed submission:
import sys
input = sys.stdin.readline

s = input().strip()
q = int(input())
query = [list(input().strip().split()) for _ in range(q)]

left = ''
right = ''
t = False
for ls in query:
    if len(ls) == 1:
        t = not t
    else:
        two, f, c = ls
        if f == '1':
            if t:
                right += c
            else:
                left += c
        else:
            if t:
                left += c
            else:
                right += c

if t:
    print(right[::-1] + s[::-1] + left)
else:
    print(left[::-1] + s + right)

Buggy submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline

s = input()
q = int(input())

j = ''.join
turn = 0
for _ in range(q):
    query = input()
    if len(query) == 1:
        turn += 1
    else:
        two, f, c = query.split()
        if f == '1':
            if turn % 2 == 0:
                s = j([c, s])
            else:
                s = j([s, c])
        else:
            if turn % 2 == 0:
                s = j([s, c])
            else:
                s = j([c, s])

if turn % 2 == 0:
    print(s)
else:
     print(s[::-1])

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

for _ in range(q):
  query = input()
  if query == '1':
    excnange += 1
  else:
    t, f, c = query.split()
    if f == '1':
      s = c + s
    else:
      s = s + c
      
if exchange % 2 == 0:
  print(s)
else:
  print(s[::-1])
Problem p02882 (python)

Fixed submission:
import math

a, b, x = map(int, input().split())
if x >= a**2*b/2:
    print(math.degrees(math.atan((2*b-2*x/a**2)/a)))
else:
    print(math.degrees(math.atan(b**2*a/2/x)))

Buggy submission (verdict: Runtime Error):
import math

a, b, x = map(int, input().split())
print(math.degrees(math.atan(a/(2*b-2*x/a**2))))
Problem p02885 (python)

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

if a <= 2*b:
    print(0)
else:
    print(a-2*b)

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

ln.sort()

def binary_search(x, r):
    left = r + 1
    right = n - 1
    while left < right:
        mid = (left + right) // 2
        if ln[mid] == x:
            return mid
        elif ln[mid] > x:
            right = mid - 1
        else:
            left = mid + 1
    mid = (left + right) // 2
    if ln[mid] > x:
        return mid - 1
    else:
        return mid


ans = 0
for a in range(n-2):
    for b  in range(a+1, n-1):
        cmax = ln[b] + ln[a] - 1
        ans += max(0, binary_search(cmax, b) - b)

print(ans)
Problem p03164 (python)

Fixed submission:
import numpy as np
n, W = map(int, input().split())

dp = [10**10]*(10**5)
dp = np.array(dp)

for _ in range(n):
    w, v = map(int, input().split())
    np.minimum(dp[v:], dp[:-v] + w, out=dp[v:])
    np.minimum(w, dp[:v], out=dp[:v])
    
#print(dp[:101])
#print(dp[91])
value = 10**5
for i in dp[::-1]:
    if i <= W:
        print(value)
        exit()
    value -= 1

Buggy submission (verdict: Runtime Error):
import numpy as np
n, max_w = map(int, input().split())

dp = [0]*(max_w+1)
dp = np.array(dp)

for _ in range(n):
    w, v = map(int, input().split())
    np.maximum(dp[:-w] + v, dp[w:], out=dp[w:])

print(max(dp))
Problem p03316 (python)

Fixed submission:
N = input()
numN = int(N)
S =0
for i in range(len(N)):
    S += int(N[i])
 
if numN % S == 0:
    print('Yes')
else:
    print('No')

Buggy submission (verdict: Runtime Error):
N = input()
numN = int(N)
S =0
for i in range(len(N)):
    S += int(N[i])
 
if nunN % S == 0:
    print('Yes')
else:
    print('No')

Buggy submission (verdict: Runtime Error):
N = input()
numN = int(N)
S =0
for i in range(len(N)):
    S += int(N[i])

if N % S == 0:
    print('Yes')
else:
    print('No')
Problem p03323 (python)

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

if A <= 8 and B <= 8:
    print("Yay!")

else:
    print(":(")

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

if A <= 8 and B <= 8:
    print("Yay!")

else:
    print(":\)")
Problem p03355 (python)

Fixed submission:
s = input()
K = int(input())
# substrings = {}
substrings = []
for i in range(1,6):
    for j in range(0,len(s)):
        if s[j:j+i] not in substrings:
            # substrings[s[j:j+1]] = True
            substrings.append(s[j:j+i])
print(sorted(substrings)[K-1])

Buggy submission (verdict: Runtime Error):
s = input()
K = int(input())
# substrings = {}
substrings = []
for i in range(1,6:
    for j in range(0,len(s)):
        if s[j:j+i] not in substrings:
            # substrings[s[j:j+1]] = True
            substrings.append(s[j:j+i])
print(sorted(substrings)[K-1])
Problem p02678 (python)

Fixed submission:
from collections import deque

n, m = map(int, input().split())

to = [[] for _ in range(n + 1)]
for i in range(m):
    a, b = map(int, input().split())
    to[a].append(b)
    to[b].append(a)

q = deque([1])
dist = [-1] * (n + 1)
# print(to)

while q:
    v = q.popleft()

    for u in to[v]:
        if dist[u] != -1:
            continue
        q.append(u)
        dist[u] = v

print("Yes")
# print(dist)

for i in range(2, n + 1):
    print(dist[i])

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

n, m = map(int, input().split())

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

q = deque([1])
dist = [-1] * (n + 1)
# print(to)

while q:
    v = q.popleft()

    for u in to[v]:
        if dist[u] != -1:
            continue
        q.append(u)
        dist[u] = v

print("Yes")
# print(dist)

for i in range(2, n + 1):
    print(dist[i])

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

INF = 1001001001
n, m = map(int, input().split())

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

q = deque([0])
dist = [-1] * n
dist[0] = 0
# print(to)

while q:
    v = q.popleft()

    for u in to[v]:
        if dist[u] != -1:
            continue
        dist[u] = v
        q.append(u)

print("Yes")
# print(dist)

for i in range(n):
    if i == 0:
        continue
    print(dist[i] + 1)

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

INF = 1001001001
n, m = map(int, input().split())

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

q = deque([0])
dist = [-1] * n
dist[0] = 0
# print(to)

while q:
    v = q.popleft()

    for u in to[v]:
        if dist[u] != -1:
            continue
        dist[u] = v
        q.append(u)

print("Yes")
# print(dist)

for i in range(n):
    if i == 0:
        continue
    print(dist[i] + 1)