TnT/Multi_CodeNet4Repair huggingface dataset:
Problem: There is a sequence X of length N, where every element is initially 0. Let X_i denote the i-th element of X.  You are given a sequence A of length N. The i-th element of A is A_i. Determine if we can make X equal to A by repeating the operation below. If we can, find the minimum number of operations required.    * Choose an integer i such that 1\leq i\leq N-1. Replace the value of X_{i+1} with the value of X_i plus 1.

Submission attempts (in order):
n = int(input())
x = [int(input()) for _ in range(n)]
f = 0

if x[0]>0: f = 1
for i in range(n-1):
    if x[i]+1 < x[i+1]: f = 1
import sys
if f:
    print(-1)
    sys.exit()
ans = 0
for i in range(n-1):
    if x[i+1] == x[i]+1:
        ans += 1
    else:
        ans += x[i+1]
    print(ans)
print(ans)

n = int(input())
x = [int(input()) for _ in range(n)]
f = 0

if x[0]>0: f = 1
for i in range(n-1):
    if x[i]+1 < x[i+1]: f = 1
import sys
if f:
    print(-1)
    sys.exit()
ans = 0
for i in range(n-1):
    if x[i+1] == x[i]+1:
        ans += 1
    else:
        ans += x[i+1]
print(ans)

Verdicts: Wrong Answer

Accepted
Problem: There is a sequence X of length N, where every element is initially 0. Let X_i denote the i-th element of X.  You are given a sequence A of length N. The i-th element of A is A_i. Determine if we can make X equal to A by repeating the operation below. If we can, find the minimum number of operations required.    * Choose an integer i such that 1\leq i\leq N-1. Replace the value of X_{i+1} with the value of X_i plus 1.

Submission attempts (in order):
n, *a = map(int, open(0).read().split())
ans = 0
if a[0] != 0:
	print(-1)
	exit()
for x, y in zip(a, a[1:]):
	if x + 1 < y:
		print(-1)
		exit()
	if x >= y:
		ans += x
print(ans)


n, *a = map(int, open(0).read().split())
ans = 0
if a[0] != 0:
	print(-1)
	exit()
for x, y in zip(a, a[1:]+[0]):
	if x + 1 < y:
		print(-1)
		exit()
	if x >= y:
		ans += x
print(ans)


Verdicts: Wrong Answer

Accepted
Problem: There is a sequence X of length N, where every element is initially 0. Let X_i denote the i-th element of X.  You are given a sequence A of length N. The i-th element of A is A_i. Determine if we can make X equal to A by repeating the operation below. If we can, find the minimum number of operations required.    * Choose an integer i such that 1\leq i\leq N-1. Replace the value of X_{i+1} with the value of X_i plus 1.

Submission attempts (in order):
print(-1)



def solve(N, A):
    c = 0
    z = 0
    if A[0] != 0:
        return -1
    for i in range(1, N):
        if A[i] == 0:
            z = 0
            c+=A[i-1]
        elif A[i-1] < A[i] - 1:
            return -1
        elif A[i] <= i - z:
            if A[i] != A[i-1]+1:
                c += A[i-1]
        else:
            return -1
        #print("A[%d]=%d, c=%d" % (i, A[i], c))
    c += A[-1]
    return c

def main():
    import sys
    input = sys.stdin.readline
    N = int(input())
    A = [0]*N
    for i in range(N):
        A[i] = int(input())
    print(solve(N, A))

main()


Verdicts: Wrong Answer

Accepted
Problem: There is a sequence X of length N, where every element is initially 0. Let X_i denote the i-th element of X.  You are given a sequence A of length N. The i-th element of A is A_i. Determine if we can make X equal to A by repeating the operation below. If we can, find the minimum number of operations required.    * Choose an integer i such that 1\leq i\leq N-1. Replace the value of X_{i+1} with the value of X_i plus 1.

Submission attempts (in order):
N = int(input())

start = int(input())
flag = 0
if start != 0:
flag = 1
t = 0

for i in range(N-1):
 k = int(input())
 if k == start:
  t += start
 elif k == start + 1:
  t += 1
  start = k
 elif k == 0:
  start = 0
 elif k > start + 1:
  t = -1
  break
 else:
  t += k
  start = k

if flag ==1:
 t = -1
print(t)

N = int(input())

start = int(input())
flag = 0
if start != 0:
flag = 1
t = 0

for i in range(N-1):
 k = int(input())
 if k == start:
  t += start
 elif k == start + 1:
  t += 1
  start = k
 elif k == 0:
  start = 0
 elif k > start + 1:
  t = -1
  break
 else:
  t += k
  start = k

if flag ==1:
 t = -1
print(t)

N = int(input())

start = int(input())
flag = 0
if start != 0:
 flag = 1
t = 0

for i in range(N-1):
 k = int(input())
 if k == start:
  t += start
 elif k == start + 1:
  t += 1
  start = k
 elif k == 0:
  start = 0
 elif k > start + 1:
  t = -1
  break
 else:
  t += k
  start = k

if flag ==1:
 t = -1
print(t)

Verdicts: Runtime Error

Runtime Error

Accepted
Problem: There is a sequence X of length N, where every element is initially 0. Let X_i denote the i-th element of X.  You are given a sequence A of length N. The i-th element of A is A_i. Determine if we can make X equal to A by repeating the operation below. If we can, find the minimum number of operations required.    * Choose an integer i such that 1\leq i\leq N-1. Replace the value of X_{i+1} with the value of X_i plus 1.

Submission attempts (in order):
n = int(input())
a = [int(input()) for _ in range(n)]
ans = 0
if a[0] != 0:
    print(-1)
    exit()
for i in range(n-1):
    if a[i+1] - a[i] > 1:
        print(-1)
        exit()
for _ in range(n):
    if set(a) == set([-1,0]) or set(a) == set([0]):
        break
    i = a.argmax()
    if i == 0:
        print(-1)
        exit()
    if a[i-1] + 1 == a[i]:
        a[i] = -1
        ans += 1
    elif a[i-1] == -1:
        a[i-1] = a[i] - 1
        a[i] = -1
        ans += 1
    else:
        print(-1)
        exit()
print(ans)

n = int(input())
prev = ans = -1
a = [int(input()) for _ in range(n)]
for i in a:
    if i - prev > 1:
        print(-1)
        exit()
    elif i - prev == 1:
        ans += 1
    else:
        ans += i
    prev = i
print(ans)

Verdicts: Runtime Error

Accepted
Problem: There is a sequence X of length N, where every element is initially 0. Let X_i denote the i-th element of X.  You are given a sequence A of length N. The i-th element of A is A_i. Determine if we can make X equal to A by repeating the operation below. If we can, find the minimum number of operations required.    * Choose an integer i such that 1\leq i\leq N-1. Replace the value of X_{i+1} with the value of X_i plus 1.

Submission attempts (in order):
n = int(input())
a = []
ans = 0
flag = True
for i in range(n):
    A = int(input())
    a.append(A)
next = 0
for i in range(n-1,-1,-1):
    if a[i] == 0:
        next = 0
        continue
    if next - a[i] == 1:
        next = a[i]
        continue
    if next - a[i] >= 2:
        flag = False
        break
    next = a[i]
    ans += a[i]
if a[0] != 0:
    flag = False
# if flag:
#     #print(ans)
# else:
#     #print(-1)
print(-1)


n = int(input())
a = []
ans = 0
flag = True
for i in range(n):
    A = int(input())
    a.append(A)
next = 0
for i in range(n-1,-1,-1):
    if a[i] == 0:
        next = 0
        continue
    if next - a[i] == 1:
        next = a[i]
        continue
    if next - a[i] >= 2:
        flag = False
        break
    next = a[i]
    ans += a[i]
if a[0] != 0:
    flag = False
if flag:
    #print(ans)
else:
    #print(-1)
print(-1)


n = int(input())
a = []
ans = 0
flag = True
for i in range(n):
    A = int(input())
    a.append(A)
next = 0
for i in range(n-1,-1,-1):
    if next - a[i] >= 2:
        flag = False
        break
    if a[i] == 0:
        next = 0
        continue
    if next - a[i] == 1:
        next = a[i]
        continue
    next = a[i]
    ans += a[i]
if a[0] != 0:
    flag = False
if flag:
    print(ans)
else:
    print(-1)


Verdicts: Wrong Answer

Runtime Error

Accepted
Problem: There is a sequence X of length N, where every element is initially 0. Let X_i denote the i-th element of X.  You are given a sequence A of length N. The i-th element of A is A_i. Determine if we can make X equal to A by repeating the operation below. If we can, find the minimum number of operations required.    * Choose an integer i such that 1\leq i\leq N-1. Replace the value of X_{i+1} with the value of X_i plus 1.

Submission attempts (in order):
# coding: utf-8
# Your code here!
N=int(input())
l=[]
for i in range(N):
    l.append(int(input()))

def calc(list):
    num=0
    sum=0
    l.pop(-1)
    l_max=max(list)
    for i in range(1,l_max+1)[::-1]:
        num+=l.count(i)
        sum+=num
    return sum+1
    

temp=[]
ans=0
judge=True
num=N

while judge:
    num-=1
    
    if (l[num]-l[num-1])!=0 and (l[num]-l[num-1])!=1:
        judge=False
    elif l[num]==1:
        temp=l[num:]
        ans+=calc(temp)
        del l[num:]
        temp.clear
    elif l[num]==0:
        l.pop(0)
    else:
        pass
    if num==0:
        break
    
if judge==False:
    print(-1)
else:
    print(ans)


# coding: utf-8
# Your code here!
N=int(input())

pre=int(input())
if pre!=0:
    print(-1)
    exit()

ans=0
count=0
for _ in range(N-1):
    A=int(input())
    if A-pre>1:
        print(-1)
        exit()
    if A==pre:
        count+=1
    else:
        ans+=pre*count
        if A<pre:
            ans+=(A-1)
        ans+=1
        count=0
        #print(_,ans)
    pre=A

print(ans+pre*count)

Verdicts: Wrong Answer

Accepted
Problem: There is a sequence X of length N, where every element is initially 0. Let X_i denote the i-th element of X.  You are given a sequence A of length N. The i-th element of A is A_i. Determine if we can make X equal to A by repeating the operation below. If we can, find the minimum number of operations required.    * Choose an integer i such that 1\leq i\leq N-1. Replace the value of X_{i+1} with the value of X_i plus 1.

Submission attempts (in order):
n = int(input())
a = []
for i in range(n):
    a.append(int(input()))
if a[0] != 0:
    print("-1")
else:
    v = []
    for i in range(1, len(a)):
        v.append((a[i], -i))
    v.sort()
    x = [0] * len(a)
    wala = False
    for y in v:
        #print(y)
        #print(x)
        if x[-y[1]] == 0:
            continue
        elif x[-y[1] - 1] + 1 == y[0]:
            x[-y[1]] = y[0]
        else:
            wala = True
            break
    if wala:
        print("-1")
    else:
        print(len(a) - a.count(0) + 1)

    

n = int(input())
a = []
for i in range(n):
    a.append(int(input()))
if a[0] != 0:
    print("-1")
else:
    x = [0] * len(a)
    d = [0] * len(a)
    dd = [0] * len(a)

    c = 0
    s = 10**6
    #0 1 1 0 1 2 2 2 3
    wala = False
    for i in range(len(a) - 1, 0, -1):
        #print("-")
        if i <= s and a[i] == 0:
            #print("X")
            continue
        if i - a[i] < 0 or i - a[i] > s:
            #print("Y")
            wala = True
            break
        if s + a[i] == i:
            continue
        s = min(s, i - a[i])
        c += a[i]
    if wala:
        print("-1")
    else:
        print(c)


Verdicts: Wrong Answer

Accepted
Problem: There is a sequence X of length N, where every element is initially 0. Let X_i denote the i-th element of X.  You are given a sequence A of length N. The i-th element of A is A_i. Determine if we can make X equal to A by repeating the operation below. If we can, find the minimum number of operations required.    * Choose an integer i such that 1\leq i\leq N-1. Replace the value of X_{i+1} with the value of X_i plus 1.

Submission attempts (in order):
#!python
# -*- coding: utf-8 -*-


def main():
    N = int(input())
    A = [int(input()) for i in range(N)]
    X = [0 for i in range(N)]

    if A[0] != 0:
        print(-1)
        return

    count = 0

    for i in range(N - 1, -1, -1):
        X[i] = X[i + 1] - 1
        if A[i] == X[i]:
            continue

        count += A[i]
        X[i] = A[i]

    print(count)


if __name__ == '__main__':
    main()


#!python
# -*- coding: utf-8 -*-


def main():
    N = int(input())
    A = [int(input()) for i in range(N)]
    X = [0 for i in range(N)]
    A += [0]
    X += [0]

    count = 0

    if A[0] != 0:
        print(-1)
        return

    for i in range(N - 1, -1, -1):
        if A[i - 1] + 1 < A[i]:
            print(-1)
            return

        X[i] = max(0, X[i + 1] - 1)
        if A[i] == X[i]:
            continue

        count += A[i]
        X[i] = A[i]

    print(count)


if __name__ == '__main__':
    main()


Verdicts: Runtime Error

Accepted
Problem: You are given a string s. Among the **different** substrings of s, print the K-th lexicographically smallest one.  A substring of s is a string obtained by taking out a non-empty contiguous part in s. For example, if s = `ababc`, `a`, `bab` and `ababc` are substrings of s, while `ac`, `z` and an empty string are not. Also, we say that substrings are different when they are different as strings.  Let X = x_{1}x_{2}...x_{n} and Y = y_{1}y_{2}...y_{m} be two distinct strings. X is lexicographically larger than Y if and only if Y is a prefix of X or x_{j} > y_{j} where j is the smallest integer such that x_{j} \neq y_{j}.

Submission attempts (in order):
string = input()
k = int(input())
if len(string) >= k:
    substrs = set()
    ls = sorted(list(string))
    for i in range(5):
        for s, c in enumerate(string):
            if c == ls[i]:
                for l in range(1, 5+1):
                    substrs.add(string[s:s+l])
    substrs = list(substrs)
    substrs.sort()
    print(substrs[k-1])

else:
    substrs = set()
    for leng in range(1, len(string)):
        for s in range(0, len(string) - leng):
            substrs.add(string[s:s+leng])
    substrs = list(substrs)
    substrs.sort()
    print(substrs[k-1])


string = input()
k = int(input())
if len(string) >= k:
    substrs = set()
    ls = sorted(list(string))
    for i in range(k):
        for s, c in enumerate(string):
            if c == ls[i]:
                for l in range(1, k+1):
                    substrs.add(string[s:s+l])
    substrs = list(substrs)
    substrs.sort()
    print(substrs[k-1])

else:
    substrs = set()
    for leng in range(1, len(string)):
        for s in range(0, len(string) - leng):
            substrs.add(string[s:s+leng])
    substrs = list(substrs)
    substrs.sort()
    print(substrs[k-1])


string = input()
k = int(input())
if len(string) > k:
    substrs = set()
    ls = sorted(list(string))
    for i in range(k):
        for s, c in enumerate(string):
            if c == ls[i]:
                for l in range(1, k+1):
                    substrs.add(string[s:s+l])
    substrs = list(substrs)
    substrs.sort()
    print(substrs[k-1])

else:
    substrs = set()
    for leng in range(1, len(string) + 1):
        for s in range(0, len(string) - leng + 1):
            substrs.add(string[s:s+leng])
    substrs = list(substrs)
    substrs.sort()
    print(substrs[k-1])


Verdicts: Runtime Error

Runtime Error

Accepted
Problem: You are given a string s. Among the **different** substrings of s, print the K-th lexicographically smallest one.  A substring of s is a string obtained by taking out a non-empty contiguous part in s. For example, if s = `ababc`, `a`, `bab` and `ababc` are substrings of s, while `ac`, `z` and an empty string are not. Also, we say that substrings are different when they are different as strings.  Let X = x_{1}x_{2}...x_{n} and Y = y_{1}y_{2}...y_{m} be two distinct strings. X is lexicographically larger than Y if and only if Y is a prefix of X or x_{j} > y_{j} where j is the smallest integer such that x_{j} \neq y_{j}.

Submission attempts (in order):
def change(n, word):
    for i in range(len(ans)-1, n, -1):
        ans[i] = ans[i-1]
    ans[n] = word

s = input()
k = int(input())
p = min(len(s), k)
key = s[:p]

for i in range(1, len(s)+1-p):
  if key > s[i:i+k]:
    key = s[i:i+k]

ans = [0]*k
for i in range(k):
  if i < p:
    ans[i] = key[:i+1]
  else:
    ans[i] = "zzzzzz"
for i in range(len(s)-p, len(s)):
    for j in range(i+1, len(s)+1):
        print(s[i:j])
        for t in range(k):
            if s[i:j] < ans[t] and s[i:j] not in ans:
                change(t, s[i:j])
print(ans[k])

def change(n, word):
    for i in range(len(ans)-1, n, -1):
        ans[i] = ans[i-1]
    ans[n] = word

s = input()
k = int(input())
p = min(len(s), k)
key = s[:p]

for i in range(1, len(s)+1-p):
  if key > s[i:i+k]:
    key = s[i:i+k]

ans = [0]*k
for i in range(k):
  if i < p:
    ans[i] = key[:i+1]
  else:
    ans[i] = "zzzzzz"
for i in range(len(s)-p, len(s)):
    for j in range(i+1, len(s)+1):
        print(s[i:j])
        for t in range(k):
            if s[i:j] < ans[t] and s[i:j] not in ans:
                change(t, s[i:j])
print(*ans)

s = input()
k = int(input())
n = len(s)
rank = ["zzzzzz"]*k
for i in range(n):
  for j in range(i+1, min([i+k+1, n+1])):
    key = s[i:j]
    for r in range(k):
      if key == rank[r]:
        break
      if key < rank[r]:
        for r2 in range(r, k):
          key2 = rank[r2]
          rank[r2] = key
          key = key2
        break
print(rank[k-1])

Verdicts: Runtime Error

Wrong Answer

Accepted
Problem: You are given a string s. Among the **different** substrings of s, print the K-th lexicographically smallest one.  A substring of s is a string obtained by taking out a non-empty contiguous part in s. For example, if s = `ababc`, `a`, `bab` and `ababc` are substrings of s, while `ac`, `z` and an empty string are not. Also, we say that substrings are different when they are different as strings.  Let X = x_{1}x_{2}...x_{n} and Y = y_{1}y_{2}...y_{m} be two distinct strings. X is lexicographically larger than Y if and only if Y is a prefix of X or x_{j} > y_{j} where j is the smallest integer such that x_{j} \neq y_{j}.

Submission attempts (in order):
s = list(input())
se = (s)
k = int(input())
n = len(s)

se = set()
for i in range(n):
    for j in range(i+1,i+1+k):
#        print(i,j,s[i:j])
        se.add(s[i:j])
#print(se)
l = sorted(list(se))
print(l[k-1])
        










#TLE 


s = input()
se = (s)
k = int(input())
n = len(s)

se = set()
for i in range(n):
    for j in range(i+1,i+1+k):
#        print(i,j,s[i:j])
        se.add(s[i:j])
#print(se)
l = sorted(list(se))
print(l[k-1])
        










#TLE 


Verdicts: Runtime Error

Accepted
Problem: You are given a string s. Among the **different** substrings of s, print the K-th lexicographically smallest one.  A substring of s is a string obtained by taking out a non-empty contiguous part in s. For example, if s = `ababc`, `a`, `bab` and `ababc` are substrings of s, while `ac`, `z` and an empty string are not. Also, we say that substrings are different when they are different as strings.  Let X = x_{1}x_{2}...x_{n} and Y = y_{1}y_{2}...y_{m} be two distinct strings. X is lexicographically larger than Y if and only if Y is a prefix of X or x_{j} > y_{j} where j is the smallest integer such that x_{j} \neq y_{j}.

Submission attempts (in order):
ALPHABETS = 26

ORD_A = ord('a')

# fast io
import sys
S,K = sys.stdin.readlines()[:2]

S = [ord(c)-ORD_A for c in S]
while S[-1] < 0:
  S.pop()


N = len(S)
K = int(K)

dp = [None]*(N+1)
dp[N] = 0
indices = [N]*ALPHABETS
s = 1

import sys

old = 1

for i,c in enumerate(reversed(S)):
  dp[i] = s
  if s > K:
    break
  s = 2*s
  s -= dp[indices[c]]
  indices[c] = i


dp.pop()
dp.reverse()
dp.append(0)

indices = [[] for _ in range(ALPHABETS)]
for i,c in enumerate(S):
  indices[c].append(i)
for l in indices:
  l.append(N)

del S

from bisect import bisect_left
def find(k):

  s = []
  i = 0
  while k > 0:
    f = False
    for c,L in enumerate(indices):
      j = L[bisect_left(L, i)]
      t = dp[j]
      if t is None or t >= k:
        s.append(c)
        k -= 1
        i = j+1
        f = True
        break
      else:
        k -= t
    if not f:
      break
  if not s:
    return 'Eel'
  return ''.join(chr(c+ORD_A) for c in s)

print(find(K))


import collections
import string
import heapq
s=input()
n = len(s)
k = int(input())

m = ['zzzzzzz','zzzzzzz','zzzzzzz','zzzzzzz','zzzzzzz']
subs = []
for i in range(n):
    for j in range(i+1, min(i+6, n+1)):
        sub = s[i:j]
        if sub not in subs:
            subs.append(sub)
            subs.sort()
            subs = subs[:5]
print(subs[k-1])


Verdicts: Wrong Answer

Accepted
Problem: You are given a string s. Among the **different** substrings of s, print the K-th lexicographically smallest one.  A substring of s is a string obtained by taking out a non-empty contiguous part in s. For example, if s = `ababc`, `a`, `bab` and `ababc` are substrings of s, while `ac`, `z` and an empty string are not. Also, we say that substrings are different when they are different as strings.  Let X = x_{1}x_{2}...x_{n} and Y = y_{1}y_{2}...y_{m} be two distinct strings. X is lexicographically larger than Y if and only if Y is a prefix of X or x_{j} > y_{j} where j is the smallest integer such that x_{j} \neq y_{j}.

Submission attempts (in order):
s = str(input())
K = int(input())

lis = list(set(list(s)))
lis.sort()

ans_lis = []
for i in range(min(5, len(lis))):
    i = lis[i]
    s2 = s
    while 1:
        idx = s2.find(i)
        if idx==-1:
            break
        ans_lis += [s2[idx:idx+l+1] for l in range(min(5, len(s2)-idx-1))]
        s2 = s2[idx+1:]
ans_lis = list(set(ans_lis))
ans_lis.sort()
print(ans_lis[4])

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

lis = list(set(list(s)))
lis.sort()

ans_lis = []
for i in range(min(5, len(lis))):
    i = lis[i]
    s2 = s
    while 1:
        idx = s2.find(i)
        if idx==-1:
            break
        ans_lis += [s2[idx:idx+l+1] for l in range(min(5, len(s2)-idx))]
        s2 = s2[idx+1:]
ans_lis = list(set(ans_lis))
ans_lis.sort()
print(ans_lis[K-1])

Verdicts: Runtime Error

Accepted
Problem: You are given a string s. Among the **different** substrings of s, print the K-th lexicographically smallest one.  A substring of s is a string obtained by taking out a non-empty contiguous part in s. For example, if s = `ababc`, `a`, `bab` and `ababc` are substrings of s, while `ac`, `z` and an empty string are not. Also, we say that substrings are different when they are different as strings.  Let X = x_{1}x_{2}...x_{n} and Y = y_{1}y_{2}...y_{m} be two distinct strings. X is lexicographically larger than Y if and only if Y is a prefix of X or x_{j} > y_{j} where j is the smallest integer such that x_{j} \neq y_{j}.

Submission attempts (in order):
import copy

n,m=map(int, input().split())
p=list(map(int, input().split()))
q=list()
for i in range(m):
    q.append(set(map(int, input().split())))
count=0
while count!=5000:
    a=q.pop()
    for j in q:
        if len(j&a) != 0:
            j |=a
            count=0
            break
    else:q=[a]+q
    if count>len(q): break
    count+=1

q2=copy.copy(set(p))
for i in q:
    q2 -= i
    
count2=len([i for i in q2 if i==p[i-1]])

for i in q:
    r=list()
    for j in list(i):
        r.append(p[j-1])
    #print(i,r)
    count2 += len(i&set(r))
print(count2)

s=input()
k=int(input())
s1=list(s)
s2=[s[i:i+2] for i in range(len(s)-1)]
s3=[s[i:i+3] for i in range(len(s)-2)]
s4=[s[i:i+4] for i in range(len(s)-3)]
s5=[s[i:i+5] for i in range(len(s)-4)]
sall=sorted(list(set(s1+s2+s3+s4+s5)))
print(sall[k-1])

Verdicts: Runtime Error

Accepted
Problem: You are given a string s. Among the **different** substrings of s, print the K-th lexicographically smallest one.  A substring of s is a string obtained by taking out a non-empty contiguous part in s. For example, if s = `ababc`, `a`, `bab` and `ababc` are substrings of s, while `ac`, `z` and an empty string are not. Also, we say that substrings are different when they are different as strings.  Let X = x_{1}x_{2}...x_{n} and Y = y_{1}y_{2}...y_{m} be two distinct strings. X is lexicographically larger than Y if and only if Y is a prefix of X or x_{j} > y_{j} where j is the smallest integer such that x_{j} \neq y_{j}.

Submission attempts (in order):
def brute_force(s, K):
    substring_set = set()

    
    for start in range(len(s)):
        
        for length in range(1, 6):
            substring = s[start:start+length]
            substring_set.add(substring)

    substring_list = sorted(list(substring_set))
    print(substring_list)
    print(substring_list[K - 1])

brute_force(s, K)

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


def brute_force(s, K):
    substring_set = set()

    
    for start in range(len(s)):
        
        for length in range(1, 6):
            substring = s[start:start+length]
            substring_set.add(substring)

    substring_list = sorted(list(substring_set))
    print(substring_list[K - 1])

brute_force(s, K)

Verdicts: Runtime Error

Accepted
Problem: You are given a string s. Among the **different** substrings of s, print the K-th lexicographically smallest one.  A substring of s is a string obtained by taking out a non-empty contiguous part in s. For example, if s = `ababc`, `a`, `bab` and `ababc` are substrings of s, while `ac`, `z` and an empty string are not. Also, we say that substrings are different when they are different as strings.  Let X = x_{1}x_{2}...x_{n} and Y = y_{1}y_{2}...y_{m} be two distinct strings. X is lexicographically larger than Y if and only if Y is a prefix of X or x_{j} > y_{j} where j is the smallest integer such that x_{j} \neq y_{j}.

Submission attempts (in order):
s=input()
K=int(input())
N=len(s)
tmp=set()

for i in range(N):
  p=min(i+K,N)
  for j in range(i+1,p+1):
    t= s[i:j]
    print(i,j,t)
    tmp.add(t)
    
lis=sorted(tmp)
#print(lis)
print(lis[K-1])


s=input()
K=int(input())
N=len(s)
tmp=set()

for i in range(N):
  for j in range(K):
    t= s[i:i+j+1]
    #print(i,j,t)
    tmp.add(t)
    
lis=sorted(tmp)
#print(lis)
print(lis[K-1])


Verdicts: Wrong Answer

Accepted
Problem: You are given a string s. Among the **different** substrings of s, print the K-th lexicographically smallest one.  A substring of s is a string obtained by taking out a non-empty contiguous part in s. For example, if s = `ababc`, `a`, `bab` and `ababc` are substrings of s, while `ac`, `z` and an empty string are not. Also, we say that substrings are different when they are different as strings.  Let X = x_{1}x_{2}...x_{n} and Y = y_{1}y_{2}...y_{m} be two distinct strings. X is lexicographically larger than Y if and only if Y is a prefix of X or x_{j} > y_{j} where j is the smallest integer such that x_{j} \neq y_{j}.

Submission attempts (in order):
from collections import deque 
def k_sub():
    s=input()
    k=int(input())
    dq=deque()
    for i in range(1,len(s)+1):
        for j in range(k):
            a.append(s[j:j+i])
    a.sort()
    print(a[k-1])
if __name__=='__main__':
    k_sub()

s=input();k=int(input())    

a=sorted({s[i:i+j+1] for i in range(len(s)) for j in range(k)})[k-1])
print(a)

s=input();k=int(input())    
a=sorted({s[i:i+j+1] for i in range(len(s)) for j in range(k)}[k-1])
print(a)

s=input()
k=int(input())

a=sorted({s[i:i+j+1] for i in range(len(s)) for j in range(k)})[k-1]
print(a)

Verdicts: Runtime Error

Runtime Error

Runtime Error

Accepted
Problem: You are given a string s. Among the **different** substrings of s, print the K-th lexicographically smallest one.  A substring of s is a string obtained by taking out a non-empty contiguous part in s. For example, if s = `ababc`, `a`, `bab` and `ababc` are substrings of s, while `ac`, `z` and an empty string are not. Also, we say that substrings are different when they are different as strings.  Let X = x_{1}x_{2}...x_{n} and Y = y_{1}y_{2}...y_{m} be two distinct strings. X is lexicographically larger than Y if and only if Y is a prefix of X or x_{j} > y_{j} where j is the smallest integer such that x_{j} \neq y_{j}.

Submission attempts (in order):
S = list(input())
K = int(input())
x = set()

for i in range(len(S)):
    for j in range(1,min(len(S) - i + 1, K + 1)):
        x.add(S[i:i + j])

x = list(x)
x.sort()
print(x[K - 1])

S = input()
K = int(input())
x = set()

for i in range(len(S)):
    for j in range(1,min(len(S) - i + 1, K + 1)):
        x.add(S[i:i + j])

x = list(x)
x.sort()
print(x[K - 1])

Verdicts: Runtime Error

Accepted
Problem: You are given a string s. Among the **different** substrings of s, print the K-th lexicographically smallest one.  A substring of s is a string obtained by taking out a non-empty contiguous part in s. For example, if s = `ababc`, `a`, `bab` and `ababc` are substrings of s, while `ac`, `z` and an empty string are not. Also, we say that substrings are different when they are different as strings.  Let X = x_{1}x_{2}...x_{n} and Y = y_{1}y_{2}...y_{m} be two distinct strings. X is lexicographically larger than Y if and only if Y is a prefix of X or x_{j} > y_{j} where j is the smallest integer such that x_{j} \neq y_{j}.

Submission attempts (in order):
s = input()
K = int(input())
ans = []
for i in range(len(s)):
    for k in range(i+1, len(s)):
        ans.append(s[i:k])
ans = set(ans)
ans = list(ans)
ans.sort()
print(ans[K-1])
        

s = input()
ans = set()
k = int(input())
for i in range(len(s)):
    for j in range(1, k+1):
        ans.add(s[i:i+j])
print(sorted(list(ans))[k-1])

Verdicts: Runtime Error

Accepted
Problem: You are given a string s. Among the **different** substrings of s, print the K-th lexicographically smallest one.  A substring of s is a string obtained by taking out a non-empty contiguous part in s. For example, if s = `ababc`, `a`, `bab` and `ababc` are substrings of s, while `ac`, `z` and an empty string are not. Also, we say that substrings are different when they are different as strings.  Let X = x_{1}x_{2}...x_{n} and Y = y_{1}y_{2}...y_{m} be two distinct strings. X is lexicographically larger than Y if and only if Y is a prefix of X or x_{j} > y_{j} where j is the smallest integer such that x_{j} \neq y_{j}.

Submission attempts (in order):
import numpy as np

s = input()
K = int(input())
L = len(s)

candidate = []

for l in range(1, K + 1):
    for j in range(0, L - l):
        candidate.append(s[j:j+l])

print(np.sort(candidate)[K-1])

import numpy as np

s = input()
K = int(input())
L = len(s)

candidate = []

for l in range(1, K + 1):
    for j in range(0, L - l + 1):
        candidate.append(s[j:j+l])

candidate = list(set(candidate))
print(np.sort(candidate)[K-1])

Verdicts: Runtime Error

Accepted
Problem: You are given a string s. Among the **different** substrings of s, print the K-th lexicographically smallest one.  A substring of s is a string obtained by taking out a non-empty contiguous part in s. For example, if s = `ababc`, `a`, `bab` and `ababc` are substrings of s, while `ac`, `z` and an empty string are not. Also, we say that substrings are different when they are different as strings.  Let X = x_{1}x_{2}...x_{n} and Y = y_{1}y_{2}...y_{m} be two distinct strings. X is lexicographically larger than Y if and only if Y is a prefix of X or x_{j} > y_{j} where j is the smallest integer such that x_{j} \neq y_{j}.

Submission attempts (in order):
from itertools import combinations
from collections import deque
s = input()
n = int(input())

le = len(s)
seed = tuple(combinations(range(le + 1), 2))

res = deque()
res.append("zzzzzzzzzzzzzzzzzzzzzzz")
res.append("zzzzzzzzzzzzzzzzzzzzzzz")
res.append("zzzzzzzzzzzzzzzzzzzzzzz")
res.append("zzzzzzzzzzzzzzzzzzzzzzz")
res.append("zzzzzzzzzzzzzzzzzzzzzzz")

for i, j in seed:
    ch = s[i:j]
    if ch in res:
        continue
    elif ch < max(res):
        res.remove(max(res))
        res.append(ch)
        print(res)

ans = sorted(res)
print(ans[n - 1])


from itertools import combinations
s = input()
n = int(input())

le = len(s)
tmp = s[:5]

for i in range(le - 4):
    tmp = min(tmp, s[i:i+5])

seed = tuple(combinations(range(min(6, le+1)), 2))
res = set()
for i, j in seed:
    res.add(tmp[i:j])
ans = sorted(res)
print(ans[n - 1])


Verdicts: Wrong Answer

Accepted
Problem: You are given a string s. Among the **different** substrings of s, print the K-th lexicographically smallest one.  A substring of s is a string obtained by taking out a non-empty contiguous part in s. For example, if s = `ababc`, `a`, `bab` and `ababc` are substrings of s, while `ac`, `z` and an empty string are not. Also, we say that substrings are different when they are different as strings.  Let X = x_{1}x_{2}...x_{n} and Y = y_{1}y_{2}...y_{m} be two distinct strings. X is lexicographically larger than Y if and only if Y is a prefix of X or x_{j} > y_{j} where j is the smallest integer such that x_{j} \neq y_{j}.

Submission attempts (in order):
import numpy as np
N, M = list(map(int, input().split()))
p = list(map(int, input().split()))
x = []
y = []
for _ in range(M):
    xi, yi = list(map(int, input().split()))
    x.append(xi - 1)
    y.append(yi - 1)

def count(l):
    out = 0
    for i, v in enumerate(l):
        if i + 1 == v:
            out += 1
    return out

def swap(l, a, b):
    va = l[a]
    vb = l[b]
    l1 = l.copy()
    l1[a] = vb
    l1[b] = va
    return l1

depth = 0
max_count = count(p)
max_d = M**5
children = [p]
next_children = []
while depth <= max_d:
    for child in children:
        for i in range(M):
            pi = swap(child, x[i], y[i])
            ci = count(pi)
            if ci > max_count:
                max_count = ci
	    if not pi in next_children:
                next_children.append(pi)
    depth += 1
    children = next_children
    next_chldren = []
    if max_count == len(p):
        break

print(max_count)

import numpy as np

s = input()
K = int(input())
L = len(s)

candidate = []

for l in range(1, K + 1):
    for j in range(0, L - l + 1):
        candidate.append(s[j:j+l])

candidate = list(set(candidate))
print(np.sort(candidate)[K-1])

Verdicts: Runtime Error

Accepted
Problem: You are given a string s. Among the **different** substrings of s, print the K-th lexicographically smallest one.  A substring of s is a string obtained by taking out a non-empty contiguous part in s. For example, if s = `ababc`, `a`, `bab` and `ababc` are substrings of s, while `ac`, `z` and an empty string are not. Also, we say that substrings are different when they are different as strings.  Let X = x_{1}x_{2}...x_{n} and Y = y_{1}y_{2}...y_{m} be two distinct strings. X is lexicographically larger than Y if and only if Y is a prefix of X or x_{j} > y_{j} where j is the smallest integer such that x_{j} \neq y_{j}.

Submission attempts (in order):
#s=input()
#N=int(input())
s="atcoderandatcodeer"
N=5
D={}

if(len(s)<=10):
    for i in range(1,len(s)+1):
        for j in range(len(s)):
            if D.get(s[j:j+i],None) == None:
                D[s[j:j+i]]=1
    D=sorted(D)
    print(D[N-1])
    exit()
else:
    t=sorted(s)
    i=0
    k=0
    for c in t:
        if(c!=k):
            i=0
            if(len(D)>=5):
                break
        k=c
        while(i<len(s)):
            if(s[i]==c):
                break
            i+=1
        j=i+1
        while(j<=len(s)):
            D[s[i:j]]=1
            j+=1
        i+=1
    
    D=sorted(D)
    print(D[N-1])
    exit()





s=input()
N=int(input())

#N=5
D={}

if(len(s)<=1):
    for i in range(1,len(s)+1):
        for j in range(len(s)):
            if D.get(s[j:j+i],None) == None:
                D[s[j:j+i]]=1
    D=sorted(D)
    print(D[N-1])
    exit()
else:
    t=sorted(s)
    i=0
    k=0
    for c in t:
        if(c!=k):
            i=0
            if(len(D)>=5):
                break
        k=c
        while(i<len(s)):
            if(s[i]==c):
                break
            i+=1
        j=i+1
        while(j<=min(len(s),i+5)):
            D[s[i:j]]=1
            j+=1
        i+=1
    
    D=sorted(D)
    print(D[N-1])
    exit()

Verdicts: Wrong Answer

Accepted
Problem: You are given a string s. Among the **different** substrings of s, print the K-th lexicographically smallest one.  A substring of s is a string obtained by taking out a non-empty contiguous part in s. For example, if s = `ababc`, `a`, `bab` and `ababc` are substrings of s, while `ac`, `z` and an empty string are not. Also, we say that substrings are different when they are different as strings.  Let X = x_{1}x_{2}...x_{n} and Y = y_{1}y_{2}...y_{m} be two distinct strings. X is lexicographically larger than Y if and only if Y is a prefix of X or x_{j} > y_{j} where j is the smallest integer such that x_{j} \neq y_{j}.

Submission attempts (in order):
s = input()
K = int(input())
ls = []
for i in range(1,len(s)+1):
    for j in range(i,len(s)+1):
        tmp = s[i:j]
        if tmp != "":
            ls.append(s[i:j])
print(sorted(list(set(ls)))[K-1])

s = input()
K = int(input())
print(sorted(set([s[j:j+i] for j in range(len(s)) for i in range(1,K+1)]))[K-1])


Verdicts: Runtime Error

Accepted
Problem: You are given a string s. Among the **different** substrings of s, print the K-th lexicographically smallest one.  A substring of s is a string obtained by taking out a non-empty contiguous part in s. For example, if s = `ababc`, `a`, `bab` and `ababc` are substrings of s, while `ac`, `z` and an empty string are not. Also, we say that substrings are different when they are different as strings.  Let X = x_{1}x_{2}...x_{n} and Y = y_{1}y_{2}...y_{m} be two distinct strings. X is lexicographically larger than Y if and only if Y is a prefix of X or x_{j} > y_{j} where j is the smallest integer such that x_{j} \neq y_{j}.

Submission attempts (in order):
s = input("string:")
K = int(input("K:"))
# substrings = {}
substrings = []
for i in range(1,len(s)+1):
    for j in range(0,len(s)):
        if s[j:j+i] not in substrings:
            
            substrings.append(s[j:j+i])
print(sorted(substrings)[K-1])

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.append(s[j:j+i])
print(sorted(substrings)[K-1])

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

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.append(s[j:j+i])
print(sorted(substrings)[K-1])


Verdicts: Wrong Answer

Runtime Error

Wrong Answer

Accepted
Problem: You are given a string s. Among the **different** substrings of s, print the K-th lexicographically smallest one.  A substring of s is a string obtained by taking out a non-empty contiguous part in s. For example, if s = `ababc`, `a`, `bab` and `ababc` are substrings of s, while `ac`, `z` and an empty string are not. Also, we say that substrings are different when they are different as strings.  Let X = x_{1}x_{2}...x_{n} and Y = y_{1}y_{2}...y_{m} be two distinct strings. X is lexicographically larger than Y if and only if Y is a prefix of X or x_{j} > y_{j} where j is the smallest integer such that x_{j} \neq y_{j}.

Submission attempts (in order):
s= input()
K = int(input())

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

ans_set = set(ans_list)
ans_list_min = sorted(list(ans_set))
print(ans_list_min[K-1])

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

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

ans_set = set(ans_list)
ans_list_min = sorted(list(ans_set))
#print(ans_list_min)
print(ans_list_min[K-1])

Verdicts: Runtime Error

Accepted
Problem: You are given a string s. Among the **different** substrings of s, print the K-th lexicographically smallest one.  A substring of s is a string obtained by taking out a non-empty contiguous part in s. For example, if s = `ababc`, `a`, `bab` and `ababc` are substrings of s, while `ac`, `z` and an empty string are not. Also, we say that substrings are different when they are different as strings.  Let X = x_{1}x_{2}...x_{n} and Y = y_{1}y_{2}...y_{m} be two distinct strings. X is lexicographically larger than Y if and only if Y is a prefix of X or x_{j} > y_{j} where j is the smallest integer such that x_{j} \neq y_{j}.

Submission attempts (in order):
s=input()
n=int(input())
l=[]
for t in range(1,len(s)+3):
    for r in range(len(s)-t+1):
        l.append(s[r:r+t])
print(sorted(sorted(set(l)),key=lambda x:len(x))[n-1])

s=input();print(sorted(set(s[t:t+i]for t in range(9)for i in range(1,9)))[int(input())-1])

s=input();print(sorted(set(s[t:t+i]for t in range(len(s))for i in range(1,9)))[int(input())-1])

Verdicts: Wrong Answer

Wrong Answer

Accepted
Problem: You are given a string s. Among the **different** substrings of s, print the K-th lexicographically smallest one.  A substring of s is a string obtained by taking out a non-empty contiguous part in s. For example, if s = `ababc`, `a`, `bab` and `ababc` are substrings of s, while `ac`, `z` and an empty string are not. Also, we say that substrings are different when they are different as strings.  Let X = x_{1}x_{2}...x_{n} and Y = y_{1}y_{2}...y_{m} be two distinct strings. X is lexicographically larger than Y if and only if Y is a prefix of X or x_{j} > y_{j} where j is the smallest integer such that x_{j} \neq y_{j}.

Submission attempts (in order):
s = str(input())
K = int(input())
L = []
M = []
con = 0
for i in s:
  L.append(i)
L = list(set(L))
L.sort()
for j in range(len(s)):
    if s[j] == L[0]:
      for k in range(1,6):
        if j + k >=len(s):
          M.append(s[j:])
          break
        else:
          M.append(s[j:j+k])

for l in range(len(s)):
  if s[l] == L[1]:
    for m in range(1,6):
      if l + m >= len(s):
        M.append(s[l:])
        break
      else:
        M.append(s[l:l+m]) 
if len(M) < K:
  for n in range(len(s)):
    if s[n] == L[2]:
      for o in range(1,6):
        if n + o >=len(s):
          M.append(s[n:])
          break
        else:
          M.append(s[n:n+o])
M = list(set(M))
M.sort()
print(M)
print(M[K - 1])  
          


s = str(input())
K = int(input())
L = []
M = []
con = 0
for i in s:
  L.append(i)
L = list(set(L))
L.sort()
for j in range(len(s)):
    if s[j] == L[0]:
      for k in range(1,6):
        if j + k >=len(s):
          M.append(s[j:])
          break
        else:
          M.append(s[j:j+k])
if len(L) != 1:
  for l in range(len(s)):
    if s[l] == L[1]:
      for m in range(1,6):
        if l + m >= len(s):
          M.append(s[l:])
          break
        else:
          M.append(s[l:l+m]) 
if len(M) < K:
  for n in range(len(s)):
    if s[n] == L[2]:
      for o in range(1,6):
        if n + o >=len(s):
          M.append(s[n:])
          break
        else:
          M.append(s[n:n+o])
M = list(set(M))
M.sort()
print(M[K - 1])  
          

Verdicts: Runtime Error

Accepted
Problem: You are given a string s. Among the **different** substrings of s, print the K-th lexicographically smallest one.  A substring of s is a string obtained by taking out a non-empty contiguous part in s. For example, if s = `ababc`, `a`, `bab` and `ababc` are substrings of s, while `ac`, `z` and an empty string are not. Also, we say that substrings are different when they are different as strings.  Let X = x_{1}x_{2}...x_{n} and Y = y_{1}y_{2}...y_{m} be two distinct strings. X is lexicographically larger than Y if and only if Y is a prefix of X or x_{j} > y_{j} where j is the smallest integer such that x_{j} \neq y_{j}.

Submission attempts (in order):
s = input()
N = len( s )
K = int( input() )

s_set = set()
for i in range( N - K + 1 ):
  for j in range( 1, K + 1 ):
    t = s[ i : i + j ]
    s_set.add(t)

print( sorted( list( s_set ) )[ K - 1 ] )

s = input()
N = len( s )
K = int( input() )

s_set = set()
for j in range( 1, K + 1 ):
  for i in range( N - j + 1 ):
    t = s[ i : i + j ]
    s_set.add(t)

print( sorted( list( s_set ) )[ K - 1 ] )

Verdicts: Runtime Error

Accepted
Problem: You are given a string s. Among the **different** substrings of s, print the K-th lexicographically smallest one.  A substring of s is a string obtained by taking out a non-empty contiguous part in s. For example, if s = `ababc`, `a`, `bab` and `ababc` are substrings of s, while `ac`, `z` and an empty string are not. Also, we say that substrings are different when they are different as strings.  Let X = x_{1}x_{2}...x_{n} and Y = y_{1}y_{2}...y_{m} be two distinct strings. X is lexicographically larger than Y if and only if Y is a prefix of X or x_{j} > y_{j} where j is the smallest integer such that x_{j} \neq y_{j}.

Submission attempts (in order):
s = str(input())
k = int(input())
result = []
for i in range(1, k+1):
    for j in range(len(s)-i):
        result.append(s[j:j+i])
r = set(result)
out = list(r)
out.sort()
print(out[k-1])

def main():
    s = str(input())
    s += '0'
    k = int(input())
    result = set()
    for i in range(1, 6):
        for j in range(len(s)-i):
            result.add(s[j:j+i])
    out = list(result)
    out.sort()
    print(out[k-1])
if __name__ =='__main__':
    main()

Verdicts: Runtime Error

Accepted
Problem: You are given a string s. Among the **different** substrings of s, print the K-th lexicographically smallest one.  A substring of s is a string obtained by taking out a non-empty contiguous part in s. For example, if s = `ababc`, `a`, `bab` and `ababc` are substrings of s, while `ac`, `z` and an empty string are not. Also, we say that substrings are different when they are different as strings.  Let X = x_{1}x_{2}...x_{n} and Y = y_{1}y_{2}...y_{m} be two distinct strings. X is lexicographically larger than Y if and only if Y is a prefix of X or x_{j} > y_{j} where j is the smallest integer such that x_{j} \neq y_{j}.

Submission attempts (in order):
s = input()
K = int(input())
ans_lis = []
s_length = len(s)
lis = [[] for i in range(26)]

for i in range(s_length):
    lis[ord(s[i]) - ord('a')].append(i)


for i in range(26):
    k = 1
    while k <= s_length:
        for j in lis[i]:
            ans_lis.append(s[j:j + k + 1])
        k += 1
        ans_lis = sorted(list(set(ans_lis)))
    if len(ans_lis) >= K:
        print(ans_lis[K - 1])
        exit()


s = input()
K = int(input())
ans_lis = []
s_length = len(s)
lis = [[] for i in range(26)]

for i in range(s_length):
    lis[ord(s[i]) - ord('a')].append(i)


for i in range(26):
    k = 1
    while k <= s_length:
        for j in lis[i]:
            ans_lis.append(s[j:j + k + 1])
        k += 1
        ans_lis = sorted(list(set(ans_lis)))
        if len(ans_lis) >= K:
            print(ans_lis[K - 1])
            exit()


s = input()
K = int(input())
ans_lis = []
s_length = len(s)
lis = [[] for i in range(26)]

for i in range(s_length):
    lis[ord(s[i]) - ord('a')].append(i)


for i in range(26):
    k = 1
    while k <= K:
        for j in lis[i]:
            ans_lis.append(s[j:j + k])
        k += 1
        ans_lis = sorted(list(set(ans_lis)))
    if len(ans_lis) >= K:
        print(ans_lis[K - 1])
        exit()


Verdicts: Wrong Answer

Wrong Answer

Accepted
Problem: You are given a string s. Among the **different** substrings of s, print the K-th lexicographically smallest one.  A substring of s is a string obtained by taking out a non-empty contiguous part in s. For example, if s = `ababc`, `a`, `bab` and `ababc` are substrings of s, while `ac`, `z` and an empty string are not. Also, we say that substrings are different when they are different as strings.  Let X = x_{1}x_{2}...x_{n} and Y = y_{1}y_{2}...y_{m} be two distinct strings. X is lexicographically larger than Y if and only if Y is a prefix of X or x_{j} > y_{j} where j is the smallest integer such that x_{j} \neq y_{j}.

Submission attempts (in order):
s = input()
K = int(input())

ct = 0
alp = 'abcdefghijklmnopqrstuvwxyz'
for i in alp:
    ct += s.count(i)
    if ct >= K:
        key = i
        break

list_rank = []
for i in range(len(s)):
    if s[i] > key:
        continue
    if i < len(s) - K + 1:
        for j in range(K):
            if s[i:i+j+1] not in list_rank:
                list_rank.append(s[i:i+j+1])
    else:
        for j in range(len(s)-i):
            if s[i:i+j+1] not in list_rank:
                list_rank.append(s[i:i+j+1])

list_rank.sort()
print(list_rank[K-1])


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

ct = 0
alp = 'abcdefghijklmnopqrstuvwxyz'
for i in alp:
    ct += s.count(i)
    if ct >= K:
        break

key = i

list_rank = []
for i in range(len(s)):
    if s[i] > key:
        continue
    if i < len(s) - K + 1:
        for j in range(K):
            if s[i:i+j+1] not in list_rank:
                list_rank.append(s[i:i+j+1])
    else:
        for j in range(len(s)-i):
            if s[i:i+j+1] not in list_rank:
                list_rank.append(s[i:i+j+1])

list_rank.sort()
print(list_rank[K-1])


Verdicts: Runtime Error

Accepted