#include<iostream> #include<cstring> #define maxn 500010 #define Maxn 1000010 #define ll long long usingnamespacestd;
int n, t, k;
char s[maxn];
structSAM { int l, L, sz, nxt[26]; } T[Maxn]; int f[Maxn], top, last, rt; voidinit_SAM(){ rt = last = top = 1; T[rt].L = T[rt].l = f[rt] = 0; }
voidextend(int ch){ int np = ++top, p = last; last = np; T[np].L = T[p].L + 1; T[np].sz = 1; while (p && !T[p].nxt[ch]) T[p].nxt[ch] = np, p = f[p]; if (!p) return f[np] = rt, void(); int q = T[p].nxt[ch]; if (T[q].L - 1 == T[p].L) f[np] = q; else { int nq = ++top; T[nq].L = T[p].L + 1; f[nq] = f[q]; for (int i = 0; i < 26; ++i) T[nq].nxt[i] = T[q].nxt[i]; while (p && T[p].nxt[ch] == q) T[p].nxt[ch] = nq, p = f[p]; f[np] = f[q] = nq; } }
int tax[maxn], tp[Maxn], suf[Maxn]; voidrsort(){ for (int i = 1; i <= top; ++i) tax[T[i].L]++; for (int i = 1; i <= n; ++i) tax[i] += tax[i - 1]; for (int i = 1; i <= top; ++i) tp[tax[T[i].L]--] = i; for (int i = top, u = tp[i]; i; u = tp[--i]) if (t) T[f[u]].sz += T[u].sz; else T[u].sz = 1; for (int i = top, u = tp[i]; i; u = tp[--i]) { suf[u] = T[u].sz; for (int j = 0; j < 26; ++j) if (T[u].nxt[j]) suf[u] += suf[T[u].nxt[j]]; } }
cin >> s + 1 >> t >> k; init_SAM(); n = strlen(s + 1); for (int i = 1; i <= n; ++i) extend(s[i] - 'a'); rsort(); if (k > suf[rt]) returncout << "-1\n", 0; int p = rt; while (k) { for (int i = 0; i < 26; ++i) if (k <= suf[T[p].nxt[i]]) { p = T[p].nxt[i]; k -= T[p].sz; cout << (char) ('a' + i); break; } else k -= suf[T[p].nxt[i]]; } return0; }