Problem p03353 (python)

Fixed submission:
import sys


def main():
  input = sys.stdin.readline
  S = str(input().strip())
  K = int(input())
  max = min(5, len(S))
  sub = []
  for i in range(len(S)):
    for j in range(1, max+1):
      if i+j > len(S):
        continue
      sub.append(S[i:i+j])
  sub = sorted(list(set(sub)))
  print(sub[K-1])


if __name__ == '__main__':
  main()

Buggy submission (verdict: Runtime Error):
import sys


def main():
  input = sys.stdin.readline
  S = str(input().strip())
  K = int(input())
  max = min(5, len(S))
  sub = []
  for i in range(len(S)):
    for j in range(1, max+1):
      if i+j > len(S):
        continue
      sub.append(S[i:i+j])
  sub = sorted(sub)
  print(sub[K])


if __name__ == '__main__':
  main()

Buggy submission (verdict: Runtime Error):
import sys

def makec(c):
  alph = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm',
          'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z']
  if c[-1] == 'z':
    return makec(c[-1])
  else:
    pos = (alph.index(c[-1]) + 1) % 26
    c = c[:-1] + alph[pos]
    return c


def f(S, K, c, i):
  if K == 0:
    return c[:-1]
  
  if c in S:
    c = c + 'a'
    i = S.index(c[0])
    return f(S, K-1, c, i)
  else:
    if c > S[i:]:
      c = c[:-1]
    c = makec(c)
    return f(S, K, c, 0)

def main():
  input = sys.stdin.readline
  S = str(input().strip())
  K = int(input())
  ans = f(S, K, 'a', 0)
  print(ans)


if __name__ == '__main__':
  main()

Buggy submission (verdict: Runtime Error):
import sys

def makec(c):
  alph = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm',
          'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z']
  if c[-1] == 'z':
    return makec(c[-1])
  else:
    pos = (alph.index(c[-1]) + 1) % 26
    c = c[:-1] + alph[pos]
    return c


def f(S, K, c):
  if K == 0:
    return c[:-1]
  
  if c in S:
    c = c + 'a'
    return f(S, K-1, c)
  else:
    if c > S:
      c = c[:-1]
    c = makec(c)
    return f(S, K, c)

def main():
  input = sys.stdin.readline
  S = str(input().strip())
  K = int(input())
  ans = f(S, K, 'a')
  print(ans)


if __name__ == '__main__':
  main()

Buggy submission (verdict: Runtime Error):
import sys

def makec(c):
  alph = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm',
          'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z']
  if c[-1] == 'z':
    return makec(c[-1])
  else:
    pos = (alph.index(c[-1]) + 1) % 26
    c = c[:-1] + alph[pos]
    return c


def f(S, K, c):
  print(c)
  if K == 0:
    return c[:-1]
  
  if c in S:
    c = c + 'a'
    return f(S, K-1, c)
  else:
    if c > S:
      c = c[:-1]
    c = makec(c)
    return f(S, K, c)

def main():
  input = sys.stdin.readline
  S = str(input().strip())
  K = int(input())
  ans = f(S, K, 'a')
  print(ans)


if __name__ == '__main__':
  main()

Buggy submission (verdict: Runtime Error):
import sys

def makec(c):
  alph = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm',
           'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z']
  if c[-1] == 'z':
    return makec(c[-1])
  else:
    pos = alph.index(c[-1]) + 1
    c = c[:-1] + alph[pos]
    return c


def f(S, K, c):
  if K == 0:
    return c[:-1]
  
  if c in S:
    c = c + 'a'
    return f(S, K-1, c)
  else:
    c = makec(c)
    return f(S, K, c)

def main():
  input = sys.stdin.readline
  S = str(input().strip())
  K = int(input())
  ans = f(S, K, 'a')
  print(ans)


if __name__ == '__main__':
  main()

Buggy submission (verdict: Runtime Error):
import sys

def makec(c):
  alph = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm',
           'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z']
  if c[-1] == 'z':
    return makec(c[-1])
  else:
    pos = (alph.index(c[-1]) + 1) % 26
    c = c[:-1] + alph[pos]
    return c


def f(S, K, c):
  if K == 0:
    return c[:-1]
  
  if c in S:
    c = c + 'a'
    return f(S, K-1, c)
  else:
    c = makec(c)
    return f(S, K, c)

def main():
  input = sys.stdin.readline
  S = str(input().strip())
  K = int(input())
  ans = f(S, K, 'a')
  print(ans)


if __name__ == '__main__':
  main()

Buggy submission (verdict: Runtime Error):
import sys

def makec(c):
  alph = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm',
           'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z']
  if c[-1] == 'z':
    return makec(c[-1])
  else:
    pos = (alph.index(c[-1]) + 1) % 26
    c = c[:-1] + alph[pos]
    return c


def f(S, K, c):
  if K == 0:
    return c[:-1]
  
  if c in S:
    c = c + 'a'
    return f(S, K-1, c)
  else:
    if c > S:
      c = makec(c[-1])
    else:
      c = makec(c)
    return f(S, K, c)

def main():
  input = sys.stdin.readline
  S = str(input().strip())
  K = int(input())
  ans = f(S, K, 'a')
  print(ans)


if __name__ == '__main__':
  main()