def o2(f, r, m): flag = False i = 0 j = 0 af = [] ar = [] while i < len(f): if f[i] == r[j]: af.append(f[i]) ar.append(r[j]) i += 1 j += 1 else: if flag: return 'NA' flag = True af.append(r[j]) ar.append(r[j]) j += 1 return ''.join(af) + m + ''.join(ar[::-1]) def odd(s): L = len(s) >> 1 if L == 0: return s + s m = s[L] f = s[:L] l = s[L + 1:] r = l[::-1] if m != f[-1] and m != l[1]: if f == r: return f + m + m + l else: return 'NA' if m == f[-1]: return o2(f[:-1], r, m) elif m == r[-1]: return o2(r[:-1], f, m) def even(s): L = len(s) >> 1 f = s[:L] l = s[L:] r = l[::-1] af = [] ar = [] flag = False i = 0 j = 0 while True: if i == j == L: if not flag: af.append('x') break elif i == L: ar.append(r[j:]) break elif j == L: af.append(f[i:]) break if f[i] == r[j]: af.append(f[i]) ar.append(r[j]) i += 1 j += 1 else: if flag: return 'NA' flag = True if i == j == L - 1: af.append(r[j]) af.append(f[i]) ar.append(r[j]) break elif f[i] == r[j + 1]: af.append(r[j]) af.append(f[i]) ar.append(r[j]) ar.append(r[j + 1]) i += 1 j += 2 elif f[i + 1] == r[j]: af.append(f[i]) af.append(f[i + 1]) ar.append(f[i]) ar.append(r[j]) i += 2 j += 1 else: return 'NA' return ''.join(af) + ''.join(ar[::-1]) def solve(s): if len(s) % 2 == 0: ans = even(s) else: ans = odd(s) print(ans) def main(): s = input() solve(s) if __name__ == '__main__': main()