#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const ll MAX_K = 1000000000000000000LL;
const ll INF = MAX_K * 2;

int N;
char S[2010];
ll K;
pll dp[2010][2010];

pll dfs(int head, int tail){
  if(dp[head][tail].first >= 0) return dp[head][tail];
  pll res;
  if(head == tail) res = make_pair(1, 1); // 26???????????????
  else if(head > tail) res = make_pair(0, 1);
  else{
    // ?????????????°???????????????????????????????, ?????????????¨??????????
    // ????????§??????10^18(MAX_K)????¶??????????, INF????????°????????????
    if(S[head] == S[tail]){
      // ????????´???, ??????????????????
      res = dfs(head + 1, tail - 1);
      res.first += 2;
    }
    else{
      // head???tail?????????????????????????????????????????¢??¨??????
      // ?????????????????????????????????. ????????´?????????????????????????????????
      pll tmp1 = dfs(head + 1, tail);
      pll tmp2 = dfs(head, tail - 1);
      if(tmp1.first == tmp2.first){
        res = make_pair(tmp1.first + 2, tmp1.second + tmp2.second);
        // INF????????°??????????????????
        if(res.second > MAX_K) res.second = INF;
      }
      else{
        res = min(tmp1, tmp2);
        res.first += 2;
      }
    }
  }
  return dp[head][tail] = res;
}

// DP??????????????????, K?????????palindrome???????????????
void solve(int head, int tail, ll K, string &ans){
  if(head == tail || head > tail){
    if(K != 0) cout<<"NONE"<<endl;
    else{
      string suffix = ans;
      reverse(suffix.begin(), suffix.end());
      if(head == tail) ans += S[head];
      ans += suffix;
      cout<<ans<<endl;
    }
  }
  else{
    // ??????
    if(S[head] == S[tail]){
      ans += S[head];
      solve(head + 1, tail - 1, K, ans);
    }
    else{
      pll tmp1 = dfs(head + 1, tail);
      pll tmp2 = dfs(head, tail - 1);
      // ?°?????????????????????????????????????????????????????????????
      if(tmp1.first < tmp2.first){
        ans += S[head];
        solve(head + 1, tail, K, ans);
      }
      else if(tmp1.first > tmp2.first){
        ans += S[tail];
        solve(head, tail - 1, K, ans);
      }
      else{
        // S[head]??¨S[tail]??§, ???????????§?°?????????????????????????
        if(S[head] < S[tail]){
          if(tmp1.second <= K){
            ans += S[tail];
            solve(head, tail - 1, K - tmp1.second, ans);
          }
          else{
            ans += S[head];
            solve(head + 1, tail, K, ans);
          }
        }
        else{
          if(tmp2.second <= K){
            ans += S[head];
            solve(head + 1, tail, K - tmp2.second, ans);
          }
          else{
            ans += S[tail];
            solve(head, tail - 1, K, ans);
          }
        }
      }      
    }
  }
}

int main(){

  cin>>S;
  N = strlen(S);
  cin>>K;
  // DP??§, ????°????palindrome??¨, ???????????°????¨????
  for(int i = 0;i < 2010; i++)
    for(int j = 0;j < 2010; j++)
      dp[i][j] = make_pair(-1, -1);

  string ans;
  solve(0, N - 1, K - 1, ans);
  
  return 0;
}
### Prompt

In Cpp, your task is to solve the following problem:

Example

Input

crc
1


Output

crc

### Response

```cpp
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const ll MAX_K = 1000000000000000000LL;
const ll INF = MAX_K * 2;

int N;
char S[2010];
ll K;
pll dp[2010][2010];

pll dfs(int head, int tail){
  if(dp[head][tail].first >= 0) return dp[head][tail];
  pll res;
  if(head == tail) res = make_pair(1, 1); // 26???????????????
  else if(head > tail) res = make_pair(0, 1);
  else{
    // ?????????????°???????????????????????????????, ?????????????¨??????????
    // ????????§??????10^18(MAX_K)????¶??????????, INF????????°????????????
    if(S[head] == S[tail]){
      // ????????´???, ??????????????????
      res = dfs(head + 1, tail - 1);
      res.first += 2;
    }
    else{
      // head???tail?????????????????????????????????????????¢??¨??????
      // ?????????????????????????????????. ????????´?????????????????????????????????
      pll tmp1 = dfs(head + 1, tail);
      pll tmp2 = dfs(head, tail - 1);
      if(tmp1.first == tmp2.first){
        res = make_pair(tmp1.first + 2, tmp1.second + tmp2.second);
        // INF????????°??????????????????
        if(res.second > MAX_K) res.second = INF;
      }
      else{
        res = min(tmp1, tmp2);
        res.first += 2;
      }
    }
  }
  return dp[head][tail] = res;
}

// DP??????????????????, K?????????palindrome???????????????
void solve(int head, int tail, ll K, string &ans){
  if(head == tail || head > tail){
    if(K != 0) cout<<"NONE"<<endl;
    else{
      string suffix = ans;
      reverse(suffix.begin(), suffix.end());
      if(head == tail) ans += S[head];
      ans += suffix;
      cout<<ans<<endl;
    }
  }
  else{
    // ??????
    if(S[head] == S[tail]){
      ans += S[head];
      solve(head + 1, tail - 1, K, ans);
    }
    else{
      pll tmp1 = dfs(head + 1, tail);
      pll tmp2 = dfs(head, tail - 1);
      // ?°?????????????????????????????????????????????????????????????
      if(tmp1.first < tmp2.first){
        ans += S[head];
        solve(head + 1, tail, K, ans);
      }
      else if(tmp1.first > tmp2.first){
        ans += S[tail];
        solve(head, tail - 1, K, ans);
      }
      else{
        // S[head]??¨S[tail]??§, ???????????§?°?????????????????????????
        if(S[head] < S[tail]){
          if(tmp1.second <= K){
            ans += S[tail];
            solve(head, tail - 1, K - tmp1.second, ans);
          }
          else{
            ans += S[head];
            solve(head + 1, tail, K, ans);
          }
        }
        else{
          if(tmp2.second <= K){
            ans += S[head];
            solve(head + 1, tail, K - tmp2.second, ans);
          }
          else{
            ans += S[tail];
            solve(head, tail - 1, K, ans);
          }
        }
      }      
    }
  }
}

int main(){

  cin>>S;
  N = strlen(S);
  cin>>K;
  // DP??§, ????°????palindrome??¨, ???????????°????¨????
  for(int i = 0;i < 2010; i++)
    for(int j = 0;j < 2010; j++)
      dp[i][j] = make_pair(-1, -1);

  string ans;
  solve(0, N - 1, K - 1, ans);
  
  return 0;
}
```