You are given a string of length $n$ . If all of its substrings (not necessarily distinct) are ordered lexicographically, what is the $k$ th smallest of them?
The first input line has a string of length $n$ that consists of characters a–z.
The second input line has an integer $k$ .
Print the $k$ th smallest substring in lexicographical order.
baabaa 10
\n \n
ab
\n
The 10 smallest substrings in order are a, a, a, a, aa, aa, aab, aaba, aabaa, and ab.