// yukicoder: 238 Mr. K's Another Gift // 2019.6.8 bal4u #include #if 1 #define gc() getchar_unlocked() #define pc(c) putchar_unlocked(c) #else #define gc() getchar() #define pc(c) putchar(c) #endif int ins(char *s) // 文字列の入力 スペース以下の文字で入力終了 { char *p = s; do *s = gc(); while (*s++ > ' '); *--s = 0; return s - p; } void outs(char *s) { while (*s) pc(*s++); } int check(char p, char *a, char *b, char q) { if (p > 0) { if (*b-- != p) return 0; } else { if (*a++ != q) return 0; } while (a < b && *a == *b) a++, b--; return a >= b; } char s[100005]; int main() { int N; char c, d, *p, *q; N = ins(s); if (N == 1) pc(*s), pc(*s); else { p = s, q = s + N - 1; while (p < q && *p == *q) p++, q--; if (p < q) { if (check(*q, p, q, 0)) c = *q, d = *p, *p = 0, outs(s), pc(c), pc(d), outs(p+1); else if (check(0, p, q, *p)) c = *p, d = *q, *q = 0, outs(s), pc(d), pc(c), outs(q+1); else outs("NA"); } else { c = s[N/2], s[N/2] = 0, outs(s), pc(c), pc(c), outs(s+N/2+1); } } pc('\n'); return 0; }