Example

Input

crc
1


Output

crc
#include<bits/stdc++.h>
using namespace std;
const int maxn=2011;
char s[maxn]; long long k; int n;
void init(){
    scanf("%s",s+1); cin>>k; n=strlen(s+1);
}
int f[maxn][maxn]; long long g[maxn][maxn];
void print(int a,int b){
//	cout<<endl<<"PRINT "<<a<<' '<<b<<endl;
	if (a>b) return;
    if (a==b){printf("%c",s[a]); return;}
    if (s[a]==s[b]){putchar(s[a]); print(a+1,b-1); putchar(s[b]); return;}
    if (f[a+1][b]+1==f[a][b] && f[a][b-1]+1!=f[a][b]){
        putchar(s[a]); print(a+1,b); putchar(s[a]); return;
    }
    if (f[a+1][b]+1!=f[a][b] && f[a][b-1]+1==f[a][b]){
        putchar(s[b]); print(a,b-1); putchar(s[b]); return;
    }
    if (s[a]<s[b]){
        if (g[a+1][b]<k){k-=g[a+1][b]; putchar(s[b]); print(a,b-1); putchar(s[b]);}
        else {putchar(s[a]); print(a+1,b); putchar(s[a]);}
        return;
    }
    if (g[a][b-1]<k){k-=g[a][b-1]; putchar(s[a]); print(a+1,b); putchar(s[a]);}
    else {putchar(s[b]); print(a,b-1); putchar(s[b]);}
}
void work(){
	memset(f,63,sizeof(f));
	memset(g,0,sizeof(g));
	for (int i=1;i<=n;++i) f[i][i-1]=0,g[i][i-1]=1;
	for (int i=1;i<=n;++i) f[i][i]=0,g[i][i]=1;
    for (int len=2;len<=n;++len) for (int i=1;i<=n;++i){
        int j=i+len-1; if (j>n) break;
        if (s[i]==s[j]) f[i][j]=f[i+1][j-1],g[i][j]=g[i+1][j-1];
        else{
            int tmp=min(f[i+1][j],f[i][j-1]);
            if (f[i+1][j]==tmp) g[i][j]+=g[i+1][j];
            if (f[i][j-1]==tmp) g[i][j]+=g[i][j-1];
            f[i][j]=tmp+1; if (g[i][j]>k) g[i][j]=k+1;
		}
//        cout<<i<<' '<<j<<' '<<f[i][j]<<' '<<g[i][j]<<endl;
    }
	if (g[1][n]<k) puts("NONE"); else print(1,n),putchar('\n');
}
int main(){
//	freopen("G.in","r",stdin); freopen("G.out","w",stdout);
    init();
    work();
    return 0;
}