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

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

if A % 3 == 0 or B % 3== 0 or (A + B)%3 == 0:
  print('Possible')
else:
  print('Impossible')

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

if a % 3 == 0 or b % 3 == 0 or (a + b) % 3 ==0:
  print("Possible")
else:
  print("Impossible")
Problem p03773 (python)

Fixed submission:
a, b = map(int, input().split())
 
h = a + b
 
if h < 24:
  print(h)
else:
  print(h - 24)

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

h = a + b

if h < 24:
  print(h)
else:
  print(24 - h)
Problem p03241 (python)

Fixed submission:

#!/usr/bin/env python
# -*- coding: utf-8 -*-

import math

if __name__ == "__main__":
    list = input().split(" ")
    N = int(list[0])
    M = int(list[1])
    list = []
    for i in range(1,int(math.sqrt(M)+1)):
        if M%i == 0:
            list.append(i)
    for i in range(len(list)):
        list.append(int(M/list[i]))
    print(max([i for i in list if i <= M // N]))

Buggy submission (verdict: Runtime Error):
#!/usr/bin/env python
# -*- coding: utf-8 -*-

def is_prime3(q,k=50):
    q = abs(q)
    if q == 2: return True
    if q < 2 or q&1 == 0: return False
    d = (q-1)>>1
    while d&1 == 0:
        d >>= 1
    for i in xrange(k):
        a = random.randint(1,q-1)
        t = d
        y = pow(a,t,q)
        while t != q-1 and y != 1 and y != q-1:
            y = pow(y,2,q)
            t <<= 1
        if y != q-1 and t&1 == 0:
            return False
    return True

if __name__ == "__main__":
    list = input().split(" ")
    N = int(list[0])
    M = int(list[1])
    if is_prime3(M):
        print(1)
        exit()
    for i in range(M):
        if M%(N+i) == 0:
            print(int(M/(N+i)))
            exit()
        if M/(N+i) < 2:
            print(1)
            exit()
Problem p03339 (python)

Fixed submission:
N = int(input())
S = input()
east = S.count("E")
west = 0
min = east

for i in S:
    if i == "E":
        east -= 1
    else:
        west += 1
    if min > east + west:
        min = east + west

print(min)

Buggy submission (verdict: Runtime Error):
N = int(input())
S = input()
num = []

for i in range(N):
    East = S[:i]
    West = S[(i+1):]
    num.append(S[:i].count("W")+S[(i+1)].count("E"))
print(min(num))
Problem p03962 (python)

Fixed submission:
a,b,c = map(int, raw_input().split())
s = set([a, b, c])
print len(s)

Buggy submission (verdict: Runtime Error):
a = input()
b = input()
c = input()
s = set([a, b, c])
print len(s)

Buggy submission (verdict: Runtime Error):
a = input()
b = input()
c = input()
s = set([a, b, c]]
print len(s)
Problem p03136 (python)

Fixed submission:
import functools

n = int(input())
l = list(map(lambda x: int(x), input().split()))
    
longest = functools.reduce(lambda x,y: x if x > y else y, l)
sum = functools.reduce(lambda x,y: x + y, l) - longest

if longest >= sum:
	print('No')
else:
	print('Yes')

Buggy submission (verdict: Runtime Error):
import functools

n = input()
l = input().split()

if n < 3 or 10 < n:
  return 'No'

for _l in l:
	if _l < 1 or 100 < _l:
		return 'No'

longest = functools.reduce(lambda x,y: x if x > y else y, l)
sum = functools.reduce(lambda x,y: x + y, l) - longest

if longest > sum:
	return 'Yes'
else
	return 'No'
Problem p03455 (python)

Fixed submission:
a, b = map(int, input().split())
if a % 2 is 1 and b % 2 is 1:
  print('Odd')
else:
  print('Even')

Buggy submission (verdict: Runtime Error):
a = map(int, input().split())
if a % 2 is 1 and b % 2 is 1:
  print('Odd')
else:
  print('Even')

Buggy submission (verdict: Runtime Error):
a = int(input())
b = int(input())
if a % 2 is 1 and b % 2 is 1:
  print('Odd')
else:
  print('Even')
Problem p03478 (python)

Fixed submission:
n,a,b = map(int, input().split())
out = 0
 
for i in range(0,n+1):
  s = sum([int(j) for j in str(i)])
  if a <= s and s <= b:
    out += i
 
print(out)

Buggy submission (verdict: Runtime Error):
n,a,b = map(int, input())
out = 0

for i in range(0,n+1):
  sum = sum([int(j) for j in str(j)])
  if a <= sum and sum <= b:
    out += i

print(i)
Problem p03574 (python)

Fixed submission:
h,w = map(int, input().split())
m = []
for y in range(h):
  s = input()
  l = []
  for i in s:
    if i == '#':
      l.append(1)
    else:
      l.append(0)
  m.append(l)

for y in range(h):
  s = ''
  for x in range(w):
    bomb = 0
    for i,j in ((-1,-1),(-1,0),(-1,1),(0,-1),(0,1),(1,-1),(1,0),(1,1)):
      if y+j < 0 or x+i < 0 or x+i >= w or y+j >= h:
        continue
      if m[y+j][x+i] == 1:
        bomb += 1
    if m[y][x] == 1:
      bomb = '#'
    s += str(bomb)
  print(s)

Buggy submission (verdict: Runtime Error):
h,w = map(int, input().split())
m = []
for y in range(h):
  s = input()
  l = []
  for i in s:
    if i == '#':
      l.append(1)
    else:
      l.append(0)

print(m)
for y in range(h):
  s = ''
  for x in range(w):
    bomb = 0
    for i,j in ((-1,-1),(-1,0),(-1,1),(0,-1),(0,1),(1,-1),(1,0),(1,1)):
      if y+j < 0 or x+i < 0 or x+i >= w or y+j >= h:
        continue
      if m[y+j][x+i] == 1:
        bomb += 1
    if m[y][x] == 1:
      bomb = '#'
    s += str(bomb)
  print(s)
Problem p03220 (python)

Fixed submission:
N = int(input())
T, A = map(int, input().split())
H = list(map(int, input().split()))

for i in range(N):
    H[i] = abs(A - (T - H[i] * 0.006))
print(H.index(min(H)) + 1)

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

for i in range(N)
    H[i] = abs(A - (T - H[i] * 0.006))
print(H.index(min(H)) + 1)
Problem p03285 (python)

Fixed submission:
N = int(input())
answer = "No"
cake = N//4
nut = N//7

for x in range(cake+1):
  for y in range(nut+1):
    if 4*x + 7*y == N:
      answer = "Yes"

print(answer)

Buggy submission (verdict: Runtime Error):
N = int(input())
answer = "No"

for x in range(N/4+1):
	for y in range(N/7+1):
  		if(4*x + 7*y == N):
    		answer = "Yes"
      		break

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

for x in range(N/4)
	for y in range(N/7)
  		if(4*x + 7*y ==)
    		print("Yes")
      		break
Problem p03407 (python)

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

if a+b >= c:
	print('Yes')
else:
	print('No')

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

if a+b >= c:
	print('Yes')
else:
	print('No')
Problem p03417 (python)

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

if N > M:
	N,M = M,N

if N == 1:
	if M == 1:
		print(1)
	else:
		print(M-2)
else:
	print((M-2)*(N-2))

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

if N > M:
	N,M = M,N

if N == 1:
	if M == 1:
		print(1)
	else:
		print(M-2)
else:
	print(M-2)*(N-2)
Problem p03424 (python)

Fixed submission:
N = int(input())
S = list(input().split())

print('Four' if 'Y' in S else 'Three')

Buggy submission (verdict: Runtime Error):
N = int(input())
S = input().split()

for x in S:
  if x is 'Y'
  	print('Four')
    exit()
  else:
    print('Three')
Problem p03433 (python)

Fixed submission:
N = int(input())
A = int(input())
 
if(N % 500 <= A):
  print("Yes")
else:
  print("No")

Buggy submission (verdict: Runtime Error):
N = input()
A = input()
 
if(N % 500 <= A):
  print("Yes/n")
else:
  print("No/n")

Buggy submission (verdict: Runtime Error):
N = input()
A = input()

if(N % 500 <= A):
  print("Yes")
else:
  print("No")

Buggy submission (verdict: Runtime Error):
N = input()
A = input()

if(N / 500 <= A):
  print("Yes")
else:
  print("No")

Buggy submission (verdict: Runtime Error):
N = input()
A = input()

if(N / 500 < A):
	print("Yes)
else:
    print("No")

Buggy submission (verdict: Runtime Error):
N = input()
A = input()

if(N / 500 < A)
	print("Yes)
else
    print("No")

Buggy submission (verdict: Runtime Error):
if(input() / 500 < input())
	print("Yes")
Problem p03448 (python)

Fixed submission:
A = int(input())
B = int(input())
C = int(input())
X = int(input())
answer = 0
for i in range(A+1):
	for j in range(B+1):
		for k in range(C+1):
			if X == 500*i + 100*j + 50*k:
				answer+=1
print(answer)

Buggy submission (verdict: Runtime Error):
A = int(input())
B = int(input())
C = int(input())
X = int(input())
answer = 0
for i in range(A+1):
	for j in range(B+1):
		for k in range(C+1):
			if X == 500*A + 100*B + 50*C:
				answer++
print(answer)

Buggy submission (verdict: Runtime Error):
A = int(input())
B = int(input())
C = int(input())
X = int(input())
answer = 0
for i in range(A+1):
	for j in range(B+1):
		for k in range(C+1):
			if X == 500*A + 100*B + 50*C
				answer++
print(answer)
Problem p03455 (python)

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

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

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

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

Buggy submission (verdict: Runtime Error):
a = input()
b = input()
c = a*b

if(c%2==0)
	print("Even")
else
	print("Odd")
Problem p03457 (python)

Fixed submission:
import math
import sys

n = int(input())

for i in range(n):
	t,x,y = map(int, input().split())
	d = abs(x)+abs(y)

	if d > t or (d - t) % 2 != 0:
		print('No')
		exit()

print('Yes')

Buggy submission (verdict: Runtime Error):
import math
import sys

n = int(input())

X = 0
Y = 0
T = 0

for i in range(n):
	t,x,y = map(int, sys.stdin.readline().split())

	d = abs(X-x)+abs(Y-y)
	if ((sum)<(T-t)) and ((d - (T-t)) % 2 == 0):
		X = x
		Y = y
		T = t
	else:
		print('No')

print('Yes')
Problem p03470 (python)

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

Buggy submission (verdict: Runtime Error):
N = int(input())
d = []
for i in range(N):
    d.add(int(input()))
print(len(set(d)))

Buggy submission (verdict: Runtime Error):
N = int(input())
d = []
for i in range(N):
    d.add(int(input()))
print(set(len(d)))

Buggy submission (verdict: Runtime Error):
N = int(input())
d = {}
for i in range(N):
    d.add(int(input()))
print(len(d))

Buggy submission (verdict: Runtime Error):
N = int(input())
d = []
for i in range(N):
    d.add(int(input()))
print(len(d))
Problem p03471 (python)

Fixed submission:
N, sum = [int(i) for i in input().split()]

for x in range(N+1):
	for y in range(N+1 - x):
		z = N - x - y
		if 10000*x + 5000*y + 1000*z == sum:
			print(x, y, N - x - y)
			exit()
print(-1, -1, -1)

Buggy submission (verdict: Runtime Error):
#include <bits/stdc++.h>
using namespace std;

int main()
{
    int N, Y;
    cin >> N >> Y;

    for(int x = 0; x <= N; x++){
        for(int y = 0; y <= N - x; y++){
            int z = N - x - y;
            if((10000*x + 5000*y + 1000*z) == sum)
                cout << x << ' ' << y << ' ' << z << endl;
            else
                cout << -1 << ' ' << -1 << ' ' << -1 << endl;
        }
    }
}

Buggy submission (verdict: Runtime Error):
#include <bits/stdc++.h>
using namespace std;

int main()
{
    int N, Y;
    cin >> n >> sum;

    int res;
    for(int x = 0; x <= n; x++){
        for(int y = 0; y <= n - x; y++){
            int z = n - x - y;
            res = 10000 * x + 5000 * y + 1000 * z;
            if(res == sum)
                cout << x << ' ' << y << ' ' << z << endl;
            else
                cout << -1 << ' ' << -1 << ' ' << -1 << endl;
        }
    }
}
Problem p03502 (python)

Fixed submission:
x = input()
sum = 0

for i in range(len(x)):
  sum += int(x[i])
  
if int(x) % sum == 0:
  print("Yes")
else:
  print("No")

Buggy submission (verdict: Runtime Error):
X = input()
sum = 0

for i in range(len(x)):
  sum += int(x[i])
  
if int(x) % sum == 0
  print("Yes")
else
  print("No")
Problem p03636 (python)

Fixed submission:
s = input()
N = len(s)
print(s[0] + str(N - 2) + s[N - 1])

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

print(n[0] + str(len(s) + n[len(s)-2]))

Buggy submission (verdict: Runtime Error):
s = input()
N = s.len(s)
print(s[0] + str(N - 2) + s[N - 1]
Problem p03644 (python)

Fixed submission:
a = [64, 32, 16, 8, 4, 2, 1]
N = int(input())
 
for i in a:
  if i <= N:
    print(i)
    break

Buggy submission (verdict: Runtime Error):
a = [64, 32, 16, 8, 4, 2, 1]
N = int(input())
 
for i in a:
  if i < N:
    print(i)
    return
Problem p04043 (python)

Fixed submission:
abc = [int (x) for x in input().split()]
abc.sort()
print('YES' if abc == [5, 5, 7] else 'NO')

Buggy submission (verdict: Runtime Error):
abc = [int (x) in input().split()]
abc.sort()
print('YES' if abc == [5, 5, 7] else 'NO')
Problem p03136 (python)

Fixed submission:
N = input()
lst = input().split(" ")
lst2 = []
for i in lst:
    int_i = int(i)
    #print(int_i)
    lst2.append(int_i)
#print(lst2)
max  = max(lst2)
#print(max)
sum = sum(lst2)
#print(sum)
if sum - max > max:
    print("Yes")
else:
    print("No")
#input()

Buggy submission (verdict: Runtime Error):
N = input()
lst = input().split(" ")
list(map(int, lst))
max  = max(lst)
sum = sum(lst)
if sum - max < max:
    print("YES")
else:
    print("NO")

Buggy submission (verdict: Runtime Error):
N = input()
lst = input().split(" ")
max  = max(lst)
sum = sum(lst)
if sum - max < max:
  print("YES")
else:
  print("NO")
Problem p03136 (python)

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

L.sort(reverse=True)
max_num = L.pop(0)

if max_num < sum(L):
  print("Yes")
else:
  print("No")

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

L.sort(reverse=True)
max_num = L.pop(0)

if max_num < total(L):
  print("Yes")
else:
  print("No")

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

L.sort(reverse=True)
max_num = L.pop(0)

if max_num < total(L):
  print("Yes")
else:
  print("No")
Problem p04043 (python)

Fixed submission:
A,B,C=map(int,input().split())
a=str(A)
b=str(B)
c=str(C) 
s=a+b+c
if s.count("5")==2 and s.count("7")==1:
    print("YES")
else:
    print("NO")

Buggy submission (verdict: Runtime Error):
N,L=map(int,input().split())
S=[]
S_list=[]
for i in range(N):
    S.append(input())
S.sort()
print(''.join(S))

Buggy submission (verdict: Runtime Error):
N,L=map(int,input().split())
S=[]
S_list=[]
for i in range(N):
    S.append(input())
S.sort()
print("".join(S))
Problem p03437 (python)

Fixed submission:
import sys

if __name__ == "__main__":
    X, Y = map(int, (input().split(' ')))
    max = X
    min = Y
    if X < Y:
        print(X)
        sys.exit()
#        max = Y
#        min = X
    if max % min == 0:
        print(-1)
        sys.exit()
    sho = (pow(10, 18) // X)  + 1
    for i in range(1, sho):
        num = X * i
        if (num % Y != 0):
            print(num)
            sys.exit()
    print(-1)

Buggy submission (verdict: Runtime Error):
import sys

if __name__ == "__main__":
    N = int(input())
    A = list(map(int, (input().split(' '))))
    B = list(map(int, (input().split(' '))))

    a_sum = 0
    for x in A:
        a_sum += x
    b_sum = 0
    for x in B:
        b_sum += x
    if a_sum > b_sum:
        print('No')
        sys.exit()
    if (a_sum + N) < b_sum:
        print('No')
        sys.exit()
    a_plus = 0
    b_plus = 0
    a_plus_cnt = 0
    b_plus_cnt = 0
    A_list = []
    B_list = []
    for i in range(N):
        if A[i] < B[i]:
            a_plus += (B[i] - A[i])
            if A[i] < B[i] - 1:
                a_plus_cnt += ((B[i] - A[i]) // 2)
        elif A[i] > B[i]:
            b_plus += (A[i] - B[i])
            b_plus_cnt += (A[i] - B[i])
    if a_plus < b_plus * 2:
        print('No')
        sys.exit()
    if a_plus_cnt < b_plus_cnt:
        print('No')
        sys.exit()
#    if a_plus // 2 > N:
#        print('No')
#        sys.exit()
#    if a_plus_cnt != b_plus_cnt:
#        print('No')
#        sys.exit()
    print('Yes')

Buggy submission (verdict: Runtime Error):
import sys

if __name__ == "__main__":
    N = int(input())
    A = list(map(int, (input().split(' '))))
    B = list(map(int, (input().split(' '))))

    a_sum = 0
    for x in A:
        a_sum += x
    b_sum = 0
    for x in B:
        b_sum += x
    if a_sum > b_sum:
        print('No')
        sys.exit()
    if (a_sum + N) < b_sum:
        print('No')
        sys.exit()
    a_plus = 0
    b_plus = 0
    for i in range(N):
        if A[i] < B[i]:
            a_plus += (B[i] - A[i])
        else:
            b_plus += (A[i] - B[i])
    if a_plus < b_plus * 2:
        print('No')
        sys.exit()
    print('Yes')
Problem p03438 (python)

Fixed submission:
import sys
if __name__ == "__main__":
    N = int(input())
    A = list(map(int, (input().split(' '))))
    B = list(map(int, (input().split(' '))))

    move = sum(B) - sum(A)
    # A行目が大きい場合は、B行目は+１ずつしかできないので追い越せない。
    if move < 0:
        print('No')
        sys.exit()
    Amove = 0
    Bmove = 0
    # 3 4 2
    # 5 3 4
    for i in range(N):
        # A[i] = 4, B[i] = 3 -> Amove = 1
        if A[i] > B[i]:
            Amove += A[i] - B[i]
        # A[i] = 3, B[i] = 5 -> Bmove = 1
        # A[i] = 2, B[i] = 4 -> Bmove = 1
        elif A[i] < B[i]:
            Bmove += (B[i] - A[i]) // 2
    # Amove = 1, Bmove = 1
    if Amove > Bmove:
        print('No')
    else:
        print('Yes')

Buggy submission (verdict: Runtime Error):
if __name__ == "__main__":
    N = int(input())
    A = list(map(int, (input().split(' '))))
    B = list(map(int, (input().split(' '))))

    move = sum(B) - sum(A)
    # A行目が大きい場合は、B行目は+１ずつしかできないので追い越せない。
    if move < 0:
        print('No')
        return 0
    Amove = 0
    Bmove = 0
    # 3 4 2
    # 5 3 4
    for i in range(N):
        # A[i] = 4, B[i] = 3 -> Amove = 1
        if A[i] > B[i]:
            Amove += A[i] - B[i]
        # A[i] = 3, B[i] = 5 -> Bmove = 1
        # A[i] = 2, B[i] = 4 -> Bmove = 1
        elif A[i] < B[i]:
            Bmove += (B[i] - A[i]) // 2
    # Amove = 1, Bmove = 1
    if Amove > Bmove:
        print('No')
    else:
        print('Yes')
Problem p03645 (python)

Fixed submission:
def solve(n, m, a, b):
    islands = set()

    for i in range(m):
        if(a[i] == 1):
            islands.add(b[i])
        if(b[i] == 1):
            islands.add(a[i])

    for i in range(m):
        if(a[i] == n and b[i] in islands):
            return "POSSIBLE"
        if(b[i] == n and a[i] in islands):
            return "POSSIBLE"
    return "IMPOSSIBLE"

(n, m) = map(int, input().split())
a = []
b = []

for i in range(m):
    (ai, bi) = map(int, input().split())
    a.append(ai)
    b.append(bi)

print(solve(n, m, a, b))

Buggy submission (verdict: Runtime Error):
def solve(n, m, a, b):
    islands = sets()

    for i in range(m):
        if(a[i] == 1):
            islands.append(b[i])
        if(b[i] == 1):
            islands.append(a[i])

    for i in range(m):
        if(a[i] == n and b[i] in islands):
            return "POSSIBLE"
        if(b[i] == n and a[i] in islands):
            return "POSSIBLE"
    return "IMPOSSIBLE"

(n, m) = map(int, input().split())
a = []
b = []

for i in range(m):
    (ai, bi) = map(int, input().split())
    a.append(ai)
    b.append(bi)

print(solve(n, m, a, b))
Problem p03672 (python)

Fixed submission:
s = input()

for i in reversed(range(1, int((len(s)-1)/2+1))):
    if(s[:i] == s[i:2*i]):
        print(2*i)
        break

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

for i in reversed(range(1, int((len(s)-1)/2+1))):
    if(s[:i] == s[i:2*i]):
        print(2*i)
        return
Problem p03680 (python)

Fixed submission:
def solve():
    n = int(input())
    l = []

    for i in range(n):
        l.append(int(input()))

    a = 1
    hist = set([])
    while(True):
        if(a-1 in hist):
            return -1
        if(a-1 == 1):
            return len(hist)
        hist.add(a-1)
        a = l[a-1]

if(__name__ == "__main__"):
    print(solve())

Buggy submission (verdict: Runtime Error):

def f(l, a, hist):
    if(a in hist):
        return -1
    if(a == 1):
        return len(hist)
    hist.append(a)
    return f(l,l[a]-1,hist)

def solve():
    n = int(input())
    l = []

    for i in range(n):
        l.append(int(input()))
        
    print(f(l,l[0]-1,[0]))

if(__name__ == "__main__"):
    solve()

Buggy submission (verdict: Runtime Error):

def f(l, a, hist):
    if(a in hist):
        return -1
    if(a == 1):
        return len(hist)
    hist.append(a)
    return f(l,l[a]-1,hist)

def solve():
    n = int(input())
    l = []

    for i in range(n):
        l.append(int(input()))
        
    print(f(l,l[0]-1,[0]))

if(__name__ == "__main__"):
    solve()

Buggy submission (verdict: Runtime Error):

def f(l, a, hist):
    if(l[a] in hist):
        return -1
    if(l[a] == 1):
        return len(hist)
    hist.append(l[a])
    return f(l,a,hist)

def solve():
    n = int(input())
    l = []

    for i in range(n):
        l.append(int(input()))
        
    print(f(l,l[0],[]))

if(__name__ == "__main__"):
    solve()
Problem p03355 (python)

Fixed submission:
import numpy as np
import heapq


def ii():
    return int(input())


def lii():
    return list(map(int, input().split(' ')))


def lvi(N):
    l = []
    for _ in range(N):
        l.append(ii())
    return l


def lv(N):
    l = []
    for _ in range(N):
        l.append(input())
    return l


def main():
    s = input()
    K = ii()

    sub = []
    for i in range(len(s)):
        sub.append(s[i:])

    heapq.heapify(sub)
    minsub = heapq.heappop(sub)

    if len(minsub) >= K:
        print(minsub[:K])
        return

    cand = []
    for i in range(1, len(minsub)+1):
        cand.append(minsub[:i])
    K -= len(minsub)
    assert K > 0

    while K > 0:
        minsub_ = heapq.heappop(sub)
        for i in range(1, len(minsub_)+1):
            if not minsub_[:i] in cand:
                cand.append(minsub_[:i])
                K -= 1
                if K == 0:
                    print(minsub_[:i])
                    return

if __name__ == '__main__':
    main()

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


def ii():
    return int(input())


def lii():
    return list(map(int, input().split(' ')))


def lvi(N):
    l = []
    for _ in range(N):
        l.append(ii())
    return l


def lv(N):
    l = []
    for _ in range(N):
        l.append(input())
    return l


def main():
    s = input()
    K = ii()

    sub = []
    for i in range(len(s)):
        sub.append(s[i:])

    heapq.heapify(sub)
    minsub = heapq.heappop(sub)

    if len(minsub) >= K:
        print(minsub[:K])
        return

    cand = []
    for i in range(1, len(minsub)+1):
        cand.append(minsub[:i])
    K -= len(minsub)
    assert K > 0

    min2sub = heapq.heappop(sub)
    for i in range(1, len(min2sub)+1):
        if not min2sub[:i] in cand:
            cand.append(min2sub[:i])
            K -= 1
            if K == 0:
                print(min2sub[:i])
                return

    min3sub = heapq.heappop(sub)
    for i in range(1, len(min3sub)+1):
        if not min3sub[:i] in cand:
            cand.append(min3sub[:i])
            K -= 1
            if K == 0:
                print(min3sub[:i])
                return

    print(minsub, min2sub, min3sub)

    raise ValueError


if __name__ == '__main__':
    main()