#include #include #include #include #include #include #include #include using namespace std; #define REP(i,a,b) for(int i=a;i<(int)b;i++) #define rep(i,n) REP(i,0,n) typedef long long ll; int N; string s; string ans; bool dfs(int a, int b, bool used) { if( (N+used) % 2 == 0 && a - 1 == b ) { string t = ans; reverse(t.begin(), t.end()); string u = !used ? "x" : ""; ans = ans + u + t; return true; } if( (N+used) % 2 == 1 && a - 2 == b ) { string t = ans; reverse(t.begin(), t.end()); string u = !used ? "x" : ""; ans = ans + u + t.substr(1); return true; } if(s[a] == s[b]) { ans += s[a]; if(dfs(a+1, b-1, used)) { return true; } ans.pop_back(); } else if(!used) { ans += s[a]; if(dfs(a+1, b, true)) { return true; } ans.back() = s[b]; if(dfs(a, b-1, true)) { return true; } ans.pop_back(); } return false; } int main() { cin >> s; N = s.size(); if(N == 1) { ans = s + s; } else { dfs(0, N-1, false); } if(ans.empty()) { cout << "NA\n"; } else { cout << ans << endl; } return 0; }