Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(10 ** 5 + 10)
def input(): return sys.stdin.readline().strip()

def resolve():
    from scipy.sparse.csgraph import connected_components  # https://note.nkmk.me/python-scipy-connected-components/
    from scipy.sparse import csr_matrix
    
    N, M = map(int, input().split())  # 頂点数、辺数
    A, B, C = [0] * M, [0] * M, [1] * M  # A[i]からB[i]へコストC[i]の有向辺。
    # ただし、connected_components()では有向グラフも無向グラフとして扱われる
    for i in range(M):
        A[i], B[i] ,_= map(int, input().split())
        A[i] -= 1  # indexを調整
        B[i] -= 1
    
    csr = csr_matrix((C, (A, B)), shape=(N, N))
    # nは連結成分の個数。labelは各頂点が属する連結成分のラベル
    n, labels = connected_components(csr)
    print(n)

    
resolve()

Fixed submission:
import sys
sys.setrecursionlimit(10 ** 5 + 10)
def input(): return sys.stdin.readline().strip()

def resolve():
    from scipy.sparse.csgraph import connected_components  # https://note.nkmk.me/python-scipy-connected-components/
    from scipy.sparse import csr_matrix
    
    N, M = map(int, input().split())  # 頂点数、辺数
    A, B, C = [0] * M, [0] * M, [1] * M  # A[i]からB[i]へコストC[i]の有向辺。
    # ただし、connected_components()では有向グラフも無向グラフとして扱われる
    for i in range(M):
        A[i], B[i] ,_= map(int, input().split())
        A[i] -= 1  # indexを調整
        B[i] -= 1
    
    csr = csr_matrix((C, (A, B)), shape=(N, N))
    # nは連結成分の個数。labelは各頂点が属する連結成分のラベル
    n, labels = connected_components(csr)
    print(n)

    
resolve()
Buggy python submission (verdict: Time Limit Exceeded):
import sys
sys.setrecursionlimit(10 ** 5 + 10)
def input(): return sys.stdin.readline().strip()

def resolve():
    R,G,B,N=map(int,input().split())
    cnt=0
    for r in range(N+1):
        for g in range(N+1):
            val=(N-R*r-G*g)/B
            if val==int(val) and val>=0:
                cnt+=1
    print(cnt)

resolve()

Fixed submission:
import sys
sys.setrecursionlimit(10 ** 5 + 10)
def input(): return sys.stdin.readline().strip()

def resolve():
    R,G,B,N=map(int,input().split())
    cnt=0
    for r in range(N+1):
        for g in range(N+1):
            val=(N-R*r-G*g)/B
            if val==int(val) and val>=0:
                cnt+=1
    print(cnt)

resolve()
Buggy python submission (verdict: Runtime Error):
from sys import stdin
N = int(input())
S = input()
K = int(input())
def search():
  val = S[K]
  for x in range(1, N):
    if S[x] != val:
      S[x] = *
  return S
print(search())
		

Fixed submission:
import sys
sys.setrecursionlimit(10 ** 5 + 10)
def input(): return sys.stdin.readline().strip()

def resolve():

    n=int(input())
    s=list(input())
    k=int(input())
    val=s[k-1]
    for i in range(n):
        if s[i]!=val:
            s[i]='*'
    print(''.join(s))


resolve()
Buggy python submission (verdict: Runtime Error):
import sys

sys.setrecursionlimit(10 ** 5 + 10)


def input(): return sys.stdin.readline().strip()


def resolve():
    N = int(input())
    if N == 1:
        print(0)
    else:
        S = list(input())

        B = [0] * N
        W = [0] * N

        cntb = 0
        cntw = 0
        for i in range(N):
            if S[i] == '#':
                cntb += 1
                B[i] = cntb
                W[i] = cntw
            else:
                cntw += 1
                B[i] = cntb
                W[i] = cntw
        if cntb == N or cntb == 0:
            print(0)
        else:

            B = [0] + B + B[-1]
            W = [0] + W + W[-1]

            ans = 10 ** 9
            for i in range(1, N + 2):
                ans = min(ans, B[i] + W[-1] - W[i])
            print(ans)


resolve()

Fixed submission:
import sys
sys.setrecursionlimit(10 ** 5 + 10)


def input(): return sys.stdin.readline().strip()


def resolve():

    N = int(input())
    S = list(input())
    bl = [0]*N
    wh = [0]*N

    from itertools import accumulate

    wh_num = 0
    for i in range(N):
        if S[i] == '#':
            bl[i] = 1
        else:
            wh[i] = 1

    bl = [0] + bl
    wh = [0]+wh

    # 累積和を格納したリスト．A[l:r]の総和はB[r] - B[l]
    bl = list(accumulate(bl))
    wh = list(accumulate(wh))

    # この問題は長さが1-Nの連続部分の和の最大値を出せというものなので以下の通り
    ans = N
    for i in range(N + 1):
        ans = min(ans, bl[i]+(wh[N]-wh[i]))
    print(ans)


resolve()
Buggy python submission (verdict: Time Limit Exceeded):
# import bisect
# from collections import Counter, deque
# import copy
# from fractions import gcd
# from functools import reduce
# from itertools import accumulate, permutations, combinations, combinations_with_replacement, groupby, product
# import math
# import numpy as np
# import sys
# sys.setrecursionlimit(10**9)

def resolve():
    N,Q=map(int,input().split())
    S=str(input())

    L, R = [0] * Q, [0] * Q
    for i in range(Q):
        L[i], R[i] = map(int, input().split())
        L[i], R[i] = L[i]-1, R[i]-1

    where=[]

    for i in range(N-1):
        if S[i:i+2]=='AC':
            where.append(i)

    for j in range(Q):
        cnt=0
        for i in where:
            if L[j]<=i and i+1<=R[j]:
                cnt+=1
        print(cnt)


resolve()

Fixed submission:
# import bisect
# from collections import Counter, deque
# import copy
# from fractions import gcd
# from functools import reduce
from itertools import accumulate, permutations, combinations, combinations_with_replacement, groupby, product
# import math
# import numpy as np
# import sys
# sys.setrecursionlimit(10**9)

def resolve():
    N,Q=map(int,input().split())
    S=str(input())

    L, R = [0] * Q, [0] * Q
    for i in range(Q):
        L[i], R[i] = map(int, input().split())
        L[i], R[i] = L[i]-1, R[i]-1

    A=[0]*N
    for i in range(N-1):
        if S[i:i+2]=='AC':
            A[i]=1

    B = [0] + A
    B = list(accumulate(B))  # 累積和を格納したリスト作成

    # この問題は長さが1-Nの連続部分の和の最大値を出せというものなので以下の通り
    for j in range(Q):
        ans=B[R[j]]-B[L[j]]
        print(ans)



resolve()
Buggy python submission (verdict: Runtime Error):
N, M, C = list(map(int, input().split()))
B = list(map(int, input().split())
A = []
 
for i in range(N):
 A.append(list(map(int, input().split())
 
def main():
cnt = 0
for i in range(N):
 val = C
 for j in range(M):
  val += A[i][j] * B[j]
  if val > 0:
  cnt += 1
return cnt
print(main)

Fixed submission:
# coding: utf-8
# Your code here!
H,W=map(int,input().split())
h,w=map(int,input().split())
print((H-h)*(W-w))

Buggy python submission (verdict: Runtime Error):
N, M, C = list(map(int, input().split()))
B = list(map(int, input().split())
A = []

for i in range(N):
A.append(list(map(int, input().split())

def main():
cnt = 0
for i in range(N):
val = C
for j in range(M):
 val += A[i][j] * B[j]
if val > 0:
cnt += 1
return cnt
print(main)
              

Fixed submission:
# coding: utf-8
# Your code here!
H,W=map(int,input().split())
h,w=map(int,input().split())
print((H-h)*(W-w))
Buggy python submission (verdict: Runtime Error):
N, M, C = list(map(int, input().split()))
B = list(map(int, input().split())
A = []

for i in range(N):
	A.append(list(map(int, input().split())
	
def main():
	cnt = 0
	for i in range(N):
		val = C
		for j in range(M):
			val += A[i][j] * B[j]
		if val > 0:
			cnt += 1
	return cnt
print(main)


Fixed submission:
N, M, C = list(map(int, input().split()))
B = list(map(int, input().split()))
A = []
for i in range(N):
    A.append(list(map(int, input().split())))

def main():
    cnt = 0
    for i in range(N):
        val = C
        for j in range(M):
            val += A[i][j] * B[j]
        if val > 0:
            cnt += 1
    return cnt

print(main())
Buggy python submission (verdict: Runtime Error):
import math

A,B,K=map(int,input().split())
gcd=math.gcd(A,B)
#print(gcd)
l=[]
for i in range(1,gcd+1):
    if gcd%i==0:
        l.append(i)
print(l[len(l)-K])

Fixed submission:
import fractions

A,B,K=map(int,input().split())
gcd=fractions.gcd(A,B)
#print(gcd)
l=[]
for i in range(1,gcd+1):
    if gcd%i==0:
        l.append(i)
#print(l)
print(l[len(l)-K])

Buggy python submission (verdict: Runtime Error):
import fractions

A,B,K=map(int,input().split())
gcd=math.gcd(A,B)
#print(gcd)
l=[]
for i in range(1,gcd+1):
    if gcd%i==0:
        l.append(i)
print(l[len(l)-K])

Fixed submission:
import fractions

A,B,K=map(int,input().split())
gcd=fractions.gcd(A,B)
#print(gcd)
l=[]
for i in range(1,gcd+1):
    if gcd%i==0:
        l.append(i)
#print(l)
print(l[len(l)-K])

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

A,B,K=map(int,input().split())
gcd=math.gcd(A,B)
#print(gcd)
l=[]
for i in range(1,gcd+1):
    if gcd%i==0:
        l.append(i)
print(l)
print(l[len(l)-K])

Fixed submission:
import fractions

A,B,K=map(int,input().split())
gcd=fractions.gcd(A,B)
#print(gcd)
l=[]
for i in range(1,gcd+1):
    if gcd%i==0:
        l.append(i)
#print(l)
print(l[len(l)-K])

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

A,B,K=map(int,input().split())
gcd=math.gcd(A,B)
#print(gcd)
l=[]
for i in range(1,gcd+1):
    if gcd%i==0:
        l.append(i)
#print(l)
print(l[len(l)-K])

Fixed submission:
import fractions

A,B,K=map(int,input().split())
gcd=fractions.gcd(A,B)
#print(gcd)
l=[]
for i in range(1,gcd+1):
    if gcd%i==0:
        l.append(i)
#print(l)
print(l[len(l)-K])

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

A,B,K=map(int,input().split())
gcd=math.gcd(A,B)
#print(gcd)
l=[]
for i in range(1,gcd+1):
    if gcd%i==0:
        l.append(i)
#print(l)
print(l[len(l)-K])

Fixed submission:
import fractions

A,B,K=map(int,input().split())
gcd=fractions.gcd(A,B)
#print(gcd)
l=[]
for i in range(1,gcd+1):
    if gcd%i==0:
        l.append(i)
#print(l)
print(l[len(l)-K])

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

A,B,K=map(int,input().split())
gcd=math.gcd(A,B)
l=[]
for i in range(1,gcd):
    if gcd%i==0:
        l.append(i)

print(l[K-1])

Fixed submission:
import fractions

A,B,K=map(int,input().split())
gcd=fractions.gcd(A,B)
#print(gcd)
l=[]
for i in range(1,gcd+1):
    if gcd%i==0:
        l.append(i)
#print(l)
print(l[len(l)-K])
Buggy python submission (verdict: Runtime Error):
import math

A,B,K=map(int,input().split())
gcd=math.gcd(A,B)
#print(gcd)
l=[]
for i in range(1,gcd+1):
    if gcd%i==0:
        l.append(i)
print(l)
print(l[len(l)-K])

Fixed submission:
N=int(input())
X=[list(map(str,input().split())) for i in range(N)]

ans=0
for i in range(N):
    if X[i][1]=='BTC':
        ans+=float(X[i][0])*380000
    else:
        ans+=float(X[i][0])
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
import sys

sys.setrecursionlimit(10 ** 5 + 10)


def input(): return sys.stdin.readline().strip()


def resolve():
    K, A, B = map(int, input().split())
    cnt = 0
    if B - A >= 3:
        times = (K - (A - 1)) // 2
        if times >= 1:
            cnt += A
            for i in range(times):
                p,mod=divmod(cnt,A)
                temp = p * B
                cnt = temp + mod
            if (K - (A - 1)) // 2 == (K - (A - 1)) / 2:
                pass
            else:
                cnt += 1
        else:
            cnt = 1 + K
    else:
        cnt = 1 + K

    print(cnt)


resolve()

Fixed submission:
import sys

sys.setrecursionlimit(10 ** 5 + 10)


def input(): return sys.stdin.readline().strip()


def resolve():
    K, A, B = map(int, input().split())
    cnt = 0
    if B - A >= 3:
        times = (K - (A - 1)) // 2
        if times >= 1:
            cnt += A
            cnt+=(B-A)*times
            if (K - (A - 1)) // 2 == (K - (A - 1)) / 2:
                pass
            else:
                cnt += 1
        else:
            cnt = 1 + K
    else:
        cnt = 1 + K

    print(cnt)


resolve()

Buggy python submission (verdict: Time Limit Exceeded):
# import string
import sys

sys.setrecursionlimit(10 ** 5 + 10)


def input(): return sys.stdin.readline().strip()


def resolve():
    K, A, B = map(int, input().split())
    cnt = 0
    if B - A >= 3:
        times = (K - (A - 1)) // 2
        if times >= 1:
            cnt += A
            for i in range(times):
                temp= (cnt // A) * B
                temp2 =cnt % A
                cnt=temp+temp2
            if (K - (A - 1)) // 2 == (K - (A - 1)) / 2:
                pass
            else:
                cnt += 1
        else:
            cnt = 1 + K
    else:
        cnt = 1 + K

    print(cnt)


resolve()

Fixed submission:
import sys

sys.setrecursionlimit(10 ** 5 + 10)


def input(): return sys.stdin.readline().strip()


def resolve():
    K, A, B = map(int, input().split())
    cnt = 0
    if B - A >= 3:
        times = (K - (A - 1)) // 2
        if times >= 1:
            cnt += A
            cnt+=(B-A)*times
            if (K - (A - 1)) // 2 == (K - (A - 1)) / 2:
                pass
            else:
                cnt += 1
        else:
            cnt = 1 + K
    else:
        cnt = 1 + K

    print(cnt)


resolve()
Buggy python submission (verdict: Time Limit Exceeded):
N,K=map(int,input().split())
h=list(map(int,input().split()))

#dp[i]はh[i]までにかかるコストの最小値
dp=[float('inf') for _ in range(N)] 
dp[0]=0

for i in range(N-1):
    for j in range(1,min(K+1,N-i)):
        dp[i+j]=min(dp[i+j],dp[i]+abs(h[i+j]-h[i]))
print(dp[N-1])


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

#dp[i]はh[i]までにかかるコストの最小値
dp=[float('inf') for _ in range(N)] 
dp[0]=0

for i in range(N-1):
    for j in range(1,min(K+1,N-i)):
        dp[i+j]=min(dp[i+j],dp[i]+abs(h[i+j]-h[i]))
print(dp[N-1])
Buggy python submission (verdict: Time Limit Exceeded):
# import bisect
# from collections import Counter, deque
# import copy
# from fractions import gcd
# from functools import reduce
# from itertools import accumulate, permutations, combinations, combinations_with_replacement, groupby, product
# import math
# import numpy as np
# import sys
# sys.setrecursionlimit(10**9)

def resolve():
    s = str(input())
    t = str(input())


    # 文字列S, Tのlongest common subsequenceを返す
    # なお、longest common substringではない
    # （要素同士がとなりあっていなくてもいい）ことに注意！
    def lcs(S, T):
        # 初期化
        dp = [[0] * (len(T) + 1) for j in range(len(S) + 1)]

        # dp[i][j]はS[:i]とT[:j]のlcsの長さを表す
        for i in range(len(S)):
            for j in range(len(T)):
                # その前までの値引き継ぎ
                dp[i + 1][j + 1] = max(dp[i][j + 1], dp[i + 1][j])
                # 望まれたニューカマーが来たら足す
                if S[i] == T[j]:
                    dp[i + 1][j + 1] = max(dp[i + 1][j + 1], dp[i][j] + 1)

        # If you want to know just the length of the lcs, return dp[i + 1][j + 1].
        # Here we'll try to print the lcs.

        lcs_str = ''
        i, j = len(S)-1, len(T)-1
        while i >= 0 and j >= 0:
            if S[i] == T[j]:
                lcs_str += S[i]
                i -= 1
                j -= 1
            else:
                if dp[i][j+1] > dp[i+1][j]:
                    i -= 1
                else:
                    j -= 1

        return lcs_str[::-1]

    print(lcs(s, t))


resolve()

Fixed submission:
# import bisect
# from collections import Counter, deque
# import copy
# from fractions import gcd
# from functools import reduce
# from itertools import accumulate, permutations, combinations, combinations_with_replacement, groupby, product
# import math
# import numpy as np
# import sys
# sys.setrecursionlimit(10**9)

def resolve():
    s = str(input())
    t = str(input())


    # 文字列S, Tのlongest common subsequenceを返す
    # なお、longest common substringではない
    # （要素同士がとなりあっていなくてもいい）ことに注意！
    def lcs(S, T):
        # 初期化
        dp = [[0] * (len(T) + 1) for j in range(len(S) + 1)]

        # dp[i][j]はS[:i]とT[:j]のlcsの長さを表す
        for i in range(len(S)):
            for j in range(len(T)):
                # その前までの値引き継ぎ
                dp[i + 1][j + 1] = max(dp[i][j + 1], dp[i + 1][j])
                # 望まれたニューカマーが来たら足す
                if S[i] == T[j]:
                    dp[i + 1][j + 1] = max(dp[i + 1][j + 1], dp[i][j] + 1)

        # If you want to know just the length of the lcs, return dp[i + 1][j + 1].
        # Here we'll try to print the lcs.

        lcs_str = ''
        i, j = len(S)-1, len(T)-1
        while i >= 0 and j >= 0:
            if S[i] == T[j]:
                lcs_str += S[i]
                i -= 1
                j -= 1
            else:
                if dp[i][j+1] > dp[i+1][j]:
                    i -= 1
                else:
                    j -= 1

        return lcs_str[::-1]

    print(lcs(s, t))


resolve()
Buggy python submission (verdict: Runtime Error):
S=list(input())
ans=10**10
for i in range(8):
    if abs(753-int(''.join(S[i:i+3])))<ans:
        ans=abs(753-int(''.join(S[i:i+3])))
print(ans)

Fixed submission:
S=list(input())
ans=10**10
for i in range(len(S)-2):
    if abs(753-int(''.join(S[i:i+3])))<ans:
        ans=abs(753-int(''.join(S[i:i+3])))
print(ans)
Buggy python submission (verdict: Runtime Error):
import statistics
import sys
sys.setrecursionlimit(10 ** 5 + 10)
def input(): return sys.stdin.readline().strip()

def resolve():
    n=int(input())
    A=list(map(int,input().split()))
    val=statistics.mean(A)
    d=[0]*n
    for i in range(n):
        d[i]=abs(val-A[i])
    ans=d.index(min(d))
    print(ans)

    
resolve()

Fixed submission:
import statistics
import sys
sys.setrecursionlimit(10 ** 5 + 10)
def input(): return sys.stdin.readline().strip()

def resolve():
    n=int(input())
    A=list(map(int,input().split()))
    val=statistics.mean(A)
    d=[0]*n
    for i in range(n):
        d[i]=abs(val-A[i])
    ans=d.index(min(d))
    print(ans)

    
resolve()
Buggy python submission (verdict: Runtime Error):
# coding: utf-8
# Your code here!

N=list(input())

for i in range(10):
    if 111*i<N<=111*(i+1):
        print(111*(i+1))


Fixed submission:
N=list(input())
for i in range(3):
    if int(N[i])==1:
        N[i]='9'
    else:
        N[i]='1'
print(''.join(N))
Buggy python submission (verdict: Runtime Error):
A,B=map(int,input().split())
while True:
    for i in range(1,4):
        if A*B*C%2==1:
            print('Yes')
    print('No')

Fixed submission:
# coding: utf-8
# Your code here!
A,B=map(int,input().split())
def mon(A,B):
    while True:
        for i in range(1,4):
            if A*B*i%2==1:
                return 'Yes'
                break
        return 'No'
        break

print(mon(A,B))
Buggy python submission (verdict: Runtime Error):
A,B=map(int,input().split())
print((A-1)*(B-1)))


Fixed submission:
A,B=map(int,input().split())
print((A-1)*(B-1))
Buggy python submission (verdict: Runtime Error):
A=sorted(list(map(int,input.split())))
print(A[2]-A[0])

Fixed submission:
A=sorted(list(map(int,input().split())))
print(A[2]-A[0])

Buggy python submission (verdict: Runtime Error):
A=sorted(list(map(int,input.split())))
print(A[2]-A[0]+1)

Fixed submission:
A=sorted(list(map(int,input().split())))
print(A[2]-A[0])
Buggy python submission (verdict: Runtime Error):
def resolve():
    N=int(input())
    A=list(map(int,input().split()))

    for i in range(N):
        A[i]=A[i]-i-1

    minval = 10 ** 10
    j=0
    temp = 10**10
    while True:
        val=0
        for i in A:
            val+=abs(i-j)
        if val>=temp:
            break
        else:
            temp=val
            minval=min(minval,val)
            j+=1

    minval = 10 ** 10
    j=1
    temp = 10**10
    while True:
        val=0
        for i in A:
            val+=abs(i+j)
        if val>=temp:
            break
        else:
            temp=val
            minval=min(minval,val)
            j+=1
    print(minval)
resolve()


Fixed submission:
from fractions import gcd

N=int(input())

print(int(2 * N / gcd(2, N)))

Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
while True:
    if N%2==1:
        print(2*N)
    else:
        N=N//2


Fixed submission:
from fractions import gcd

N=int(input())

print(int(2 * N / gcd(2, N)))
Buggy python submission (verdict: Runtime Error):
N=int(input())
if N<1000:
    print('ABC',N)
elif:
    print('ABD',N-999)

Fixed submission:
N=int(input())
if N<1000:
    print('ABC')
else:
    print('ABD')
Buggy python submission (verdict: Time Limit Exceeded):
# import bisect
from collections import Counter, deque
# import copy
# from fractions import gcd
# from functools import reduce
# from itertools import accumulate, permutations, combinations, combinations_with_replacement, groupby, product
# import math
# import numpy as np
import sys
sys.setrecursionlimit(10 ** 5 + 10)
# input = sys.stdin.readline

def resolve():
    N=int(input())
    S=list(input())
    ans=10**10
    for i in range(N):
        ans=min(S[:i].count('W')+S[i+1:].count('E'),ans)
    print(ans)


resolve()

Fixed submission:
# import bisect
from collections import Counter, deque
# import copy
# from fractions import gcd
# from functools import reduce
# from itertools import accumulate, permutations, combinations, combinations_with_replacement, groupby, product
# import math
# import numpy as np
import sys
sys.setrecursionlimit(10 ** 5 + 10)
# input = sys.stdin.readline

def resolve():
    N=int(input())
    S=list(input())
    from itertools import accumulate

    W=[0]*N
    E=[0]*N
    for i in range(N):
        if S[i]=='W':
            W[i]=1
        else:
            E[i]=1
    WW=[0]+W
    EE=[0]+E

    from itertools import accumulate

    WW = list(accumulate(WW))
    EE=list(accumulate(EE))# 累積和を格納したリスト作成


    # この問題は長さが1-Nの連続部分の和の最大値を出せというものなので以下の通り
    ans=10**10
    for i in range(1, N + 1):
        ans = min(WW[i-1]+EE[N]-EE[i],ans)
    print(ans)



resolve()
Buggy python submission (verdict: Time Limit Exceeded):
def resolve():

    s=str(input())
    K=int(input())

    ls=[]
    for i in range(len(s)):
        for j in range(i+1,len(s)+1):
            ls.append(s[i:j])

    print(sorted(set(ls))[K-1])


resolve()

Fixed submission:
def resolve():

    s=str(input())
    K=int(input())

    ls=[]
    for i in range(len(s)):
        for j in range(i+1,i+K+1):
            ls.append(s[i:j])

    print(sorted(set(ls))[K-1])


resolve()

Buggy python submission (verdict: Time Limit Exceeded):
def resolve():

    s=str(input())
    K=int(input())

    ls=[]
    for i in range(len(s)):
        for j in range(i+1,len(s)+1):
            ls.append(s[i:j])

    print(sorted(list(set(ls)))[K-1])


resolve()

Fixed submission:
def resolve():

    s=str(input())
    K=int(input())

    ls=[]
    for i in range(len(s)):
        for j in range(i+1,i+K+1):
            ls.append(s[i:j])

    print(sorted(set(ls))[K-1])


resolve()

Buggy python submission (verdict: Time Limit Exceeded):
def resolve():

    s=str(input())
    K=int(input())

    ls=[]
    for i in range(len(s)):
        for j in range(i+1,len(s)+1):
            ls.append(s[i:j])

    print(sorted(list(set(ls)))[K-1])


resolve()

Fixed submission:
def resolve():

    s=str(input())
    K=int(input())

    ls=[]
    for i in range(len(s)):
        for j in range(i+1,i+K+1):
            ls.append(s[i:j])

    print(sorted(set(ls))[K-1])


resolve()