#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<cassert>
using namespace std;

typedef long long ll;

typedef unsigned long long ul;
typedef unsigned int ui;
const ll mod = 1000000007;
const ll INF = mod * mod;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef pair<ll, ll> LP;
typedef vector<int> vec;
typedef vector<string> svec;
typedef long double ld;
typedef pair<ld, ld> LDP;
const ld eps = 1e-8;

string s;

bool used[2000][2000];
int ans[2000][2000];

int dfs(int l, int r) {
	if (l >= r)return 0;
	if (used[l][r])return ans[l][r];
	used[l][r] = true;
	if (s[l] == s[r]) {
		return ans[l][r] = dfs(l + 1, r - 1);
	}
	else {
		int ret = min(dfs(l + 1, r), dfs(l, r - 1))+1;
		return ans[l][r] = ret;
	}
}

bool chked[2000][2000];
ll num[2000][2000];
ll dfs2(int l, int r) {
	if (l >= r)return 1;
	if (chked[l][r])return num[l][r];
	chked[l][r] = true;
	if (s[l] == s[r]) {
		return num[l][r] = dfs2(l + 1, r - 1);
	}
	else {
		ll ret = 0;
		if (ans[l][r] == dfs(l + 1, r)+1) {
			ret += dfs2(l + 1, r);
		}
		if (ans[l][r] == dfs(l, r - 1)+1) {
			ret += dfs2(l, r - 1);
		}
		if (ret > INF)ret = INF;
		return num[l][r] = ret;
	}
}



void solve() {
	ll k; cin >> s >> k;
	int n = s.length();
	dfs(0, n - 1);
	dfs2(0, n - 1);
	int l = 0, r = n - 1;
	string out;
	while (l < r) {
		//cout << k << " " << l << " " << r << endl;
		if (s[l] == s[r]) {
			out.push_back(s[l]); l++; r--;
		}
		else {
			if (s[l] < s[r]) {
				if (ans[l][r] == dfs(l + 1, r) + 1) {
					ll c = dfs2(l + 1, r);
					if (k <= c) {
						out.push_back(s[l]); l++;
					}
					else {
						if (ans[l][r] == dfs(l, r - 1) + 1) {
							k -= c;
							out.push_back(s[r]); r--;
						}
						else {
							cout << "NONE" << endl; return;
						}
					}
				}
				else {
					out.push_back(s[r]); r--;
				}
			}
			else {
				if (ans[l][r] == dfs(l, r - 1) + 1) {
					ll c = dfs2(l, r - 1);
					if (k <= c) {
						out.push_back(s[r]); r--;
					}
					else {
						if (ans[l][r] == dfs(l + 1, r) + 1) {
							k -= c;
							out.push_back(s[l]); l++;
						}
						else {
							cout << "NONE" << endl; return;
						}
					}
				}
				else {
					out.push_back(s[l]); l++;
				}
			}
		}
	}
	if (k != 1) {
		cout << "NONE" << endl; return;
	}
	string out2 = out; reverse(out2.begin(), out2.end());
	if (l == r)out.push_back(s[l]);
	out += out2;
	cout << out << endl;
}

signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);

	//cout << fixed << setprecision(10);
	//init();
	solve();
	//stop
		return 0;
}

### Prompt

Generate a CPP solution to the following problem:

Example

Input

crc
1


Output

crc

### Response

```cpp
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<cassert>
using namespace std;

typedef long long ll;

typedef unsigned long long ul;
typedef unsigned int ui;
const ll mod = 1000000007;
const ll INF = mod * mod;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef pair<ll, ll> LP;
typedef vector<int> vec;
typedef vector<string> svec;
typedef long double ld;
typedef pair<ld, ld> LDP;
const ld eps = 1e-8;

string s;

bool used[2000][2000];
int ans[2000][2000];

int dfs(int l, int r) {
	if (l >= r)return 0;
	if (used[l][r])return ans[l][r];
	used[l][r] = true;
	if (s[l] == s[r]) {
		return ans[l][r] = dfs(l + 1, r - 1);
	}
	else {
		int ret = min(dfs(l + 1, r), dfs(l, r - 1))+1;
		return ans[l][r] = ret;
	}
}

bool chked[2000][2000];
ll num[2000][2000];
ll dfs2(int l, int r) {
	if (l >= r)return 1;
	if (chked[l][r])return num[l][r];
	chked[l][r] = true;
	if (s[l] == s[r]) {
		return num[l][r] = dfs2(l + 1, r - 1);
	}
	else {
		ll ret = 0;
		if (ans[l][r] == dfs(l + 1, r)+1) {
			ret += dfs2(l + 1, r);
		}
		if (ans[l][r] == dfs(l, r - 1)+1) {
			ret += dfs2(l, r - 1);
		}
		if (ret > INF)ret = INF;
		return num[l][r] = ret;
	}
}



void solve() {
	ll k; cin >> s >> k;
	int n = s.length();
	dfs(0, n - 1);
	dfs2(0, n - 1);
	int l = 0, r = n - 1;
	string out;
	while (l < r) {
		//cout << k << " " << l << " " << r << endl;
		if (s[l] == s[r]) {
			out.push_back(s[l]); l++; r--;
		}
		else {
			if (s[l] < s[r]) {
				if (ans[l][r] == dfs(l + 1, r) + 1) {
					ll c = dfs2(l + 1, r);
					if (k <= c) {
						out.push_back(s[l]); l++;
					}
					else {
						if (ans[l][r] == dfs(l, r - 1) + 1) {
							k -= c;
							out.push_back(s[r]); r--;
						}
						else {
							cout << "NONE" << endl; return;
						}
					}
				}
				else {
					out.push_back(s[r]); r--;
				}
			}
			else {
				if (ans[l][r] == dfs(l, r - 1) + 1) {
					ll c = dfs2(l, r - 1);
					if (k <= c) {
						out.push_back(s[r]); r--;
					}
					else {
						if (ans[l][r] == dfs(l + 1, r) + 1) {
							k -= c;
							out.push_back(s[l]); l++;
						}
						else {
							cout << "NONE" << endl; return;
						}
					}
				}
				else {
					out.push_back(s[l]); l++;
				}
			}
		}
	}
	if (k != 1) {
		cout << "NONE" << endl; return;
	}
	string out2 = out; reverse(out2.begin(), out2.end());
	if (l == r)out.push_back(s[l]);
	out += out2;
	cout << out << endl;
}

signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);

	//cout << fixed << setprecision(10);
	//init();
	solve();
	//stop
		return 0;
}

```