Problem7648--[CSES Problem Set] Substring Order I

7648: [CSES Problem Set] Substring Order I

[Creator : ]
Time Limit : 1.000 sec  Memory Limit : 256 MiB

Description

You are given a string of length $n$. 
If all of its distinct substrings are ordered lexicographically, what is the $k$-th smallest of them?

Input

The first input line has a string of length $n$ that consists of characters a–z.
The second input line has an integer $k$.

Output

Print the $k$-th smallest distinct substring in lexicographical order.

Constraints

$1≤n≤10^5$
$1 \le k \le \frac{n(n+1)}{2}$
It is guaranteed that $k$ does not exceed the number of distinct substrings.

Sample 1 Input

babaacbaab
10

Sample 1 Output

aba
The 10 smallest distinct substrings in order are a, aa, aab, aac, aacb, aacba, aacbaa, aacbaab, ab, and aba.

HINT

相同题目:CSES 2108

Source/Category