Problem:
Score : 300 points

Problem Statement

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}.

Constraints

1 ≤ |s| ≤ 5000

s consists of lowercase English letters.

1 ≤ K ≤ 5

s has at least K different substrings.

Partial Score

200 points will be awarded as a partial score for passing the test set satisfying |s| ≤ 50.

Input

Input is given from Standard Input in the following format:

s
K

Output

Print the K-th lexicographically smallest substring of K.

Sample Input 1

aba
4

Sample Output 1

b

s has five substrings: a, b, ab, ba and aba.
Among them, we should print the fourth smallest one, b.
Note that we do not count a twice.

Sample Input 2

atcoderandatcodeer
5

Sample Output 2

andat

Sample Input 3

z
1

Sample Output 3

z

Solution in C++14 (GCC 5.4.1) (judge verdict: Runtime Error)

//#define NDEBUG

#include <bits/stdc++.h>
#include <bits/extc++.h>

#define StarBurstStream ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define iter(a) a.begin(), a.end()
#define riter(a) a.rbegin(), a.rend()
#define lsort(a) sort(iter(a))
#define gsort(a) sort(riter(a))
#define pb(a) push_back(a)
#define eb(a) emplace_back(a)
#define pf(a) push_front(a)
#define pob pop_back()
#define pof pop_front()
#define mp(a, b) make_pair(a, b)
#define F first
#define S second
#define mt make_tuple
#define gt(t, i) get<i>(t)
#define iceil(a, b) (((a) + (b) - 1) / (b))
#define tomax(a, b) ((a) = max((a), (b)))
#define printv(a, b) {bool pvaspace=false; \
for(auto pva : a){ \
    if(pvaspace) b << " "; pvaspace=true;\
    b << pva;\
}\
b << "\n";}

//#define TEST

using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;

using pii = pair<int, int>;
using pll = pair<ll, ll>;
using pdd = pair<ld, ld>;
using tiii = tuple<int, int, int>;

const ll MOD = 1000000007;
const ll MAX = 2147483647;

template<typename A, typename B>
ostream& operator<<(ostream& o, pair<A, B> p){
    return o << '(' << p.F << ',' << p.S << ')';
}

struct Node{
    int cnt = 0;
    vector<int> c;
    Node(){
        c.resize(26, -1);
    }
};

vector<Node> tr;
int ts = 1;

int add(string s, int now, int id){
    if(id == -1) id = ts++;
//    cerr << "test " << s << " " << now << " " << id << "\n";
    tr[id].cnt = 1;
    if(now != s.size() - 1) tr[id].c[s[now + 1] - 'a'] = add(s, now + 1, tr[id].c[s[now + 1] - 'a']);
    return id;
}

string ans;
int k;
int now = 0;
void dfs(int id){
    now += tr[id].cnt;
//    cerr << "dfs " << ans << " " << now << " " << id << "\n";
    if(now >= k){
        cout << ans << "\n";
        exit(0);
    }
    for(int i = 0; i < 26; i++){
        if(tr[id].c[i] != -1){
            ans.push_back('a' + i);
            dfs(tr[id].c[i]);
            ans.pop_back();
        }
    }
}

int main(){
    StarBurstStream

    string s;
    cin >> s;
    int n = s.size();
    cin >> k;

    tr.resize(26 * n);
    for(int i = 0; i < n; i++){
//        cerr << s.substr(i, n - i) << "\n";
        add(s, i - 1, 0);
    }
    tr[0].cnt = 0;

    dfs(0);

    return 0;
}