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 (GCC 5.4.1) (judge verdict: Runtime Error)

#define _CRT_SECURE_NO_WARNINGS

#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<math.h>

//for
#define REP(i,n) for(int i=0,i##_len=(int)(n);i<i##_len;i++)
#define REPS(i,n) for(int i=1,i##_len=(int)(n);i<=i##_len;i++)
#define RREP(i,n) for(int i=(int)(n)-1;i>=0;i--)
#define RREPS(i,n) for(int i=(int)(n);i>0;i--)
#define FOR(i,s,n) for(int i=(int)(s),i##_len=(int)(n);i<i##_len;i++)

//printf
#define PRINTD(d) printf("%d\n",(d))
#define PRINTL(d) printf("%lld\n",(d))

//memset
#define m0(s) memset(s,0,sizeof(s))
#define ml(s) memset(s,63,sizeof(s))
#define fill(s,c) memset(s,c,sizeof(s))

#define INF 1e9

typedef long long ll;
int diff[4][2] = {
	{ 0, -1 },
	{ -1, 0 },
	{ 1, 0 },
	{ 0, 1 },
};

int Min(int a, int b) {
	return (a)<(b) ? (a) : (b);
}
int Max(int a, int b) {
	return (a) > (b) ? (a) : (b);
}
void Swap(int *a, int *b) {
	int tmp = *a;
	*a = *b;
	*b = tmp;
}
void hSwap(char x[][51], int i, int j)
{
	char temp[51];

	strcpy(temp,x[i]);
	strcpy(x[i],x[j]);
	strcpy(x[j],temp);
}
void ShowData(char x[][51], int left, int right)
{
	int i;
	for (i = left; i <= right; i++)printf("%s\n", x[i]);
	printf("\n");
}
void QSort(char x[][51], int left, int right, int n) {
	int i, j;	//左端,右端
	char pivot[51];	//軸

	i = left;
	j = right;
	strcpy(pivot,x[(left + right) / 2]);

	while (1) {
		if (n > 0) {				//n>0なら昇順、n<=0なら降順
			while ((strcmp(x[i],pivot)<0) && (i <= right))i++;	//軸値より大きい要素
			while ((strcmp(pivot,x[j])<0) && (i <= right))j--;	//軸値より小さい要素
		}
		else {
			while ((x[i] > pivot) && (i <= right))i++;	//軸値より小さい要素
			while ((pivot > x[j]) && (i <= right))j--;	//軸値より大きい要素
		}
		if (i >= j)	break;
		hSwap(x, i, j);
		i++; j--;
	}
	//ShowData(x, left, right);

	if (left < i - 1)QSort(x, left, i - 1, n);
	if (j + 1 <  right)QSort(x, j + 1, right, n);
}



char str[2500][51] = { '\0' };
int main() {
	char s[5001];
	scanf("%s", s);
	int k;
	scanf("%d", &k);
	int len = strlen(s);
	int cnt = 1;
	REP(i, len) {
		REPS(j, len - i) {
			char t[51];
			strncpy(t, s + i, j);
			t[j] = '\0';
			if (i == 0 & j == 1) {
				strcpy(str[0], t);
				continue;
			}
			REP(k, cnt) {
				//printf("%s %s@\n", t, str[k]);
				if (strcmp(t, str[k]) == 0)break;
				if (k == cnt - 1)strcpy(str[cnt++], t);
			}
			//ShowData(str, 0, cnt-1);
		}
	}
	QSort(str, 0, cnt - 1, 1);
	//ShowData(str, 0, cnt-1);
	puts(str[k-1]);
}