#C14709. Smallest K-Substring

    ID: 44388 Type: Default 1000ms 256MiB

Smallest K-Substring

Smallest K-Substring

You are given a string s and an integer k. Your task is to find the lexicographically smallest substring of s that has length k. In other words, among all substrings of s of length k, you need to choose the one that would appear first in a dictionary.

Note: If k satisfies $k \leq 0$ or $k > |s|$, where $|s|$ represents the length of s, then output an empty string.

Example:
For s = "azcbob" and k = 3, the possible substrings of length 3 are "azc", "zcb", "cbo", and "bob". Among these, "azc" is lexicographically smallest.

inputFormat

The input is read from standard input (stdin) and consists of two lines:

  1. The first line contains a non-empty string s consisting of only lowercase alphabets.
  2. The second line contains an integer k.

outputFormat

Output the lexicographically smallest substring of s that has length k to standard output (stdout). If k \leq 0 or k > |s|, output an empty string.

## sample
azcbob
3
azc