Mr. Kitayuta has kindly given you a string s consisting of lowercase English letters. You are asked to insert exactly one lowercase English letter into s to make it a palindrome. A palindrome is a string that reads the same forward and backward. For example, "noon", "testset" and "a" are all palindromes, while "test" and "kitayuta" are not.You can choose any lowercase English letter, and insert it to any position of s, possibly to the beginning or the end of s. You have to insert a letter even if the given string is already a palindrome.If it is possible to insert one lowercase English letter into s so that the resulting string will be a palindrome, print the string after the insertion. Otherwise, print "NA" (without quotes, case-sensitive). In case there is more than one palindrome that can be obtained, you are allowed to print any of them.

The only line of the input contains a string s (1 ≤ |s| ≤ 10). Each character in s is a lowercase English letter.

If it is possible to turn s into a palindrome by inserting one lowercase English letter, print the resulting string in a single line. Otherwise, print "NA" (without quotes, case-sensitive). In case there is more than one solution, any of them will be accepted.

NoteFor the first sample, insert 'r' to the end of "revive" to obtain a palindrome "reviver".For the second sample, there is more than one solution. For example, "eve" will also be accepted.For the third sample, it is not possible to turn "kitayuta" into a palindrome by just inserting one letter.

#include <stdio.h>
#include <string.h>
char s[11], ans[12];
int check(int i, int j, int ia, int ja, int f)
{
	while(s[i] == s[j] && i <= j)
	{
		ans[ia++] = s[i++];
		ans[ja--] = s[j--];
	}
	if(i > j)
		return 1;
	if(f == 1)
	{
		ans[ia++] = s[i];
		ans[ja--] = s[i++];
		if(check(i, j, ia, ja, 0))
		{
			return 1;
		}
	    else
		{
			ia--;
			ja++;
			i--;
			ans[ia++] = s[j];
			ans[ja--] = s[j--];
			if(check(i, j, ia, ja, 0))
			{
				return 1;
			}
			else
				return 0;
		}
	}
	return 0;
}
int main()
{
	int l, res;
	scanf("%s", s);
	l = strlen(s);
	ans[l + 1] = '\0';
	memset(ans, '0', l + 1);
	res = check(0, l - 1, 0, l, 1);
	if(res == 1)
	{
		if(ans[l / 2] == '0')
			ans[l / 2] = 'o';
		printf("%s", ans);
	}
	else
		printf("NA");
	return 0;
}

#include <stdio.h>
#include <string.h>

#define loop(i,x,y) for(i=x;i<y;i++)

#define sd(x) scanf("%d",&x)
#define slld(x) scanf("%lld",&x)
#define sllu(x) scanf("%llu",&x)
#define sstr(x) scanf("%s",x)

#define pd(x) printf("%d",x)
#define plld(x) printf("%lld",x)
#define pllu(x) printf("%llu",x)
#define pstr(x) printf("%s",x)
#define pnl printf("\n")

typedef long long int lld;
typedef unsigned long long int llu;

int check(char *s,int len)
{
	int i,flag=0;
	loop(i,0,len/2)
	{
		if(s[i]!=s[len-1-i])
		{
			flag=1;
			break;
		}
	}
	return flag; //0 = palindrome , 1 = not palindrome
}

int main()
{
	char s[20],ans[20];
	int i,len,pos,mid;
	sstr(s);
	len = strlen(s);
	mid=check(s,len);
	//pd(mid);
	//pnl;
	if(mid==0)
	{
		loop(i,0,len/2)
			printf("%c",s[i]);
		printf("%c",s[len/2]);
		loop(i,len/2,len)
			printf("%c",s[i]);
		return 0;
	}
	loop(i,0,len/2)
	{
		if(s[i]!=s[len-i-1])
		{
			pos=i;
			break;
		}
	}
	loop(i,0,pos)
		ans[i]=s[i];
	//ans[i]='\0';
	//pstr(ans);
	//pnl;
	ans[i]=s[len-1-i];
	//pstr(ans);
	//ans[i]='\0';
	loop(i,pos,len)
		ans[i+1]=s[i];
	ans[i+1]='\0';
	if(check(ans,len+1)==0)
	{
		pstr(ans);
		return 0;
	}
	loop(i,0,len-pos)
		ans[i]=s[i];
	ans[i]=s[pos];
	loop(i,len-pos,len)
		ans[i+1]=s[i];
	ans[i+1]='\0';
	if(check(ans,len+1)==0)
	{
		pstr(ans);
		return 0;
	}
	pstr("NA");
	return 0;
}

#include <stdio.h>
#include<string.h>
int checkpalin(char str[],int len)
{
	int i,cnt=0;
	for(i=0;i<=(len/2);i++)
	{
		if(str[i]!=str[len-1-i])
		{
			cnt++;
			break;
		}
	}
	if(cnt==0)
	return 1;
	else
	return 0;
}

int main(void) {
	// your code goes here
	char str1[15],str2[15];
	int len,i,d,j,e,cnt=0;
	scanf("%s\n",str1);
	len=strlen(str1);
	d=checkpalin(str1,len);
	if(d==1)
	{
		j=0;
		for(i=0;i<=(len/2)-1;i++)
		str2[j++]=str1[i];
		str2[j++]=str1[(len/2)];
		for(i=(len/2);i<len;i++)
		str2[j++]=str1[i];
		str2[j]='\0';
		puts(str2);
	}
	else
	{
		j=0;
		for(i=0;i<len;i++)
		{
			if(str1[i]!=str1[len-1-i])
			{
				cnt=i;
				break;
			}
		}
		for(i=0;i<=len-1-cnt;i++)
		str2[j++]=str1[i];
		str2[j++]=str1[cnt];
		for(i=len-cnt;i<len;i++)
		str2[j++]=str1[i];
		str2[j]='\0';
		e=strlen(str2);
		cnt=checkpalin(str2,e);
		if(cnt==1)
		puts(str2);
		else
		{
			j=0;cnt=0;
			for(i=0;i<len;i++)
		{
			if(str1[i]!=str1[len-1-i])
			{
				cnt=i;
				break;
			}
		}
			for(i=0;i<cnt;i++)
		str2[j++]=str1[i];
		str2[j++]=str1[len-1-cnt];
		for(i=cnt;i<len;i++)
		str2[j++]=str1[i];
		str2[j]='\0';
		e=strlen(str2);
		cnt=checkpalin(str2,e);
		if(cnt==1)
		puts(str2);
		else
		printf("NA");

	}}
	return 0;
}

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int palindrome( char ch[],int l)
{   int p,m,i;
    p=0;
    m=l/2;
    for(i=0;i<m;i++)
    {
        if (ch[i]==ch[l-1-i]) p++;
    }
    if(p==m) return 1;
    else return 0;
}
char ajout(char ch[], char elem , int p,int l )
{   int i;
    ch[l]='a';
    ch[l+1]='\0';
    for (i=l;i>(p);i--){
        ch[i]=ch[i-1] ;
    }
    ch[p]=elem;
    return *ch;
}
char supp(char ch[], int p,int l )
{   int i;
    char c,a;
    c=ch[l-1];
    for (i=l-2;i>(p-2);i--){
        a=ch[i];
        ch[i]=c ;
        c=a;
    }
    ch[l-1]='\0';
    return *ch;
}
int main()
{   int l,p,m,k,i,h;
    char ch[10000],ch1[100000];
    scanf("%s",ch);
    strcpy(ch1,ch);
    l=strlen(ch);
    p=palindrome(ch,l);
    m=l/2+l%2;
    if(p==1) {*ch=ajout(ch,ch[m-1],m,l);printf("%s",ch);}
    else {
        k=0;
        for(i=0;i<l;i++){
            *ch=supp(ch,i+1,l);
            p=palindrome(ch,l-1);
            if(p==1) {h=i;break;}
            else {k++;strcpy(ch,ch1);}
        }
        if (k==l) printf("NA");
        else {strcpy(ch,ch1);if(h>=m) *ch=ajout(ch,ch[h],l-h-1,l); else *ch=ajout(ch,ch[h],l-h,l); printf("%s",ch);}
    }
    return 0;
}

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int pali(char s[],int palin,int even){
    int len=strlen(s),i,j;
    char temp[12],ch;
    if(palin==-1){
            for(i=0;i<len/2;i++){
                if(s[i]==s[len-1-i])
                    continue;
                return 0;
            }
            return 1;
    }

    else{
        temp[0]=palin;
        temp[len+1]=NULL;
        for(i=0;i<len;i++){
            temp[1+i]=s[i];
        }

        for(j=0;j<=len;j++){
            for(i=0;i<(len+1)/2;i++){
                if(temp[i]!=temp[len-i])
                    break;
            }
            if(i==(len+1)/2){
                printf("%s",temp);
                return 1;
            }
            temp[j]=temp[j+1];
            temp[j+1]=palin;
        }
    }
    return 0;
}

int main()
{
    int len,flag=0,k=0,i,odd=0,count[26]={0},o[10]={0};
    char s[12];
    scanf("%s",s);
    len = strlen(s);

    for(i=0;i<len;i++)
        count[s[i]-97]++;

    for(i=0;i<26;i++){
        if(count[i]%2){
            o[k++]=i+97;
            odd++;
        }
    }

    if(odd>2){
        printf("NA");
        return 0;
    }

    if(len%2==0){
        if(pali(s,-1,1)){
            for(i=0;i<len/2;i++)
                printf("%c",s[i]);
            printf("a");
            for(i=len/2;i<len;i++)
                printf("%c",s[i]);
        }
        else if(!pali(s,o[0],1)){
            if(!pali(s,o[1],1)){
                printf("NA");
            }
        }
     }

    else{
        if(pali(s,-1,2)){
            for(i=0;i<len/2;i++)
                printf("%c",s[i]);
            printf("%c",s[i]);
            for(i=len/2;i<len;i++)
                printf("%c",s[i]);
        }
        else if(!pali(s,o[0],2)){
            if(!pali(s,o[1],2)){
                printf("NA");
            }
        }

    }
    scanf("%*c");
    return 0;
}

#include <stdio.h>
#include <string.h>

int CheckPalin(char s[]) {
	int l = 0, r = strlen(s)-1;
	while (l < r) {
		if (s[l] != s[r]) return 0;
		l++; r--;
	}
	return 1;
}

int main() {
	char s[20], s1[20], s2[20];
	int i;
	scanf("%s", s);
	int len = strlen(s);
	if (CheckPalin(s) && len % 2 == 1) {
		for (i = 0; i < len / 2; i++) putchar(s[i]);
		printf("%c%c", s[i], s[i]);
		for (i++; i < len; i++) putchar(s[i]);
	}
	else if (CheckPalin(s) && len % 2 == 0) {
		for (i = 0; i < len / 2; i++) putchar(s[i]);
		putchar('a');
		for ( ; i < len; i++) putchar(s[i]);
	}
	else {
		int l = 0, r = len - 1;
		while (s[l] == s[r]) { // traverse
			l++; r--;
		}
		// create s1, s2
		for (i = 0; i < l; i++) s1[i] = s[i];
		s1[i] = s[r];
		for (; i < len; i++) s1[i + 1] = s[i];
		s1[i+1] = '\0';
		//s2
		for (i = 0; i <= r; i++) s2[i] = s[i];
		s2[i] = s[l];
		for (; i < len; i++) s2[i + 1] = s[i];
		s2[i + 1] = '\0';
		//check
		if (CheckPalin(s1)) puts(s1);
		else if (CheckPalin(s2)) puts(s2);
		else puts("NA");
	}
	return 0;
}

#include<stdio.h>
#include<string.h>
int check(char a[],int len)
{
    int i=0;
    int j=len-1;
    int flag=0;

    while(i<j)
    {
        if(a[i]!=a[j])
        {
            flag=1;
            break;
        }
        ++i;
        --j;
    }
    if(flag)
        return 0;
    return 1;
}
int main(void)
{
    char s[14];
    char temp[20];
    scanf("%s",s);
    int i,j,k;
    int len=strlen(s);
    i=0;
    j=len-1;
    if(len==1)
    {
        printf("%s%s",s,s);
        return 0;
    }
    while(i<j)
    {
        if(s[i]==s[j])
        {
            ++i;
            --j;
            continue;
        }
        for(k=0;k<i;++k)
            temp[k]=s[k];
        temp[i]=s[j];

        for(k=i;k<len;++k)
            temp[k+1]=s[k];
        temp[len+1]='\0';

        if(check(temp,len+1))
        {
            printf("%s",temp);
            return 0;
        }

        for(k=0;k<=j;++k)
            temp[k]=s[k];

        temp[j+1]=s[i];

        for(k=j+1;k<len;++k)
            temp[k+1]=s[k];
        temp[len+1]='\0';

        if(check(temp,len+1))
        {
            printf("%s",temp);
            return 0;
        }
        ++i;
        --j;
    }
    int flag=0;
    i=0,j=len-1;
    while(i<j)
    {
        if(s[i]!=s[j])
        {
            flag=1;
            break;
        }
        ++i;
        --j;
    }
    if(flag)
    {
        puts("NA");
        return 0;
    }

    for(i=0;i<len/2;++i)
        printf("%c",s[i]);
    printf("%c",s[i]);
    for(;i<len;++i)
        printf("%c",s[i]);

    return 0;
}

#include <stdio.h>
#include <string.h>
#include <malloc.h>
#define li long int
#define lli long long int
#define szf sizeof
#define givemem(t, n) (t*)malloc(sizeof(t) * (n))
#define sstr(x) scanf("%s", x)
#define si(x) scanf("%d", &x)
#define pi(x) printf("%d", x)
#define sli(x) scanf("%ld", &x)
#define pli(x) printf("%ld", x)
#define slli(x) scanf("%lld", &x)
#define plli(x) printf("%lld", x)
#define sc(x) scanf("%c", &x)
#define pc(x) printf("%c", x)
#define newl() printf("\n")
#define fl(i, val, n) for(i = (val);i < (n);i++)
#define fln(i, val, n) for(i = (val);i > (n);i--)
char str[15];
int checkPal(int l, int r) {
    while(l <= r) {
        if(str[l] != str[r])
            return 0;
        l++;
        r--;
    }
    return 1;
}
int main() {
    int r, l = 0, len, i;
    sstr(str);
    len = strlen(str);
    r = len - 1;
    if(checkPal(l, r)) {
        r = len / 2;
        fl(i, 0, len) {
            if(i == r)
                pc(str[r]);
            pc(str[i]);
        }
        return 0;
    }
    while(l <= r) {
        if(str[l] == str[r]) {
            l++;
            r--;
        }
        else {
            if(checkPal(l + 1, r)) {
                fl(i, 0, len) {
                    if(i == (r + 1))
                        pc(str[l]);
                    pc(str[i]);
                }
                if(i == (r + 1))
                    pc(str[l]);
                return 0;
            }
            else if(checkPal(l, r - 1)) {
                fl(i, 0, len) {
                    if(i == l)
                        pc(str[r]);
                    pc(str[i]);
                }
                return 0;
            }
            else
                printf("NA");
            return 0;
        }
    }
}

#include <stdio.h>
#include <string.h>

int pal(char *s, int n) {
	int i, j;

	for (i = 0, j = n - 1; i < j; i++, j--)
		if (s[i] != s[j])
			return 0;
	return 1;
}

int main() {
	static char s[16];
	int n, i;

	scanf("%s", s);
	n = strlen(s);
	for (i = 0; i <= n; i++) {
		static char t[16];
		int j;
		char c;

		for (j = 0; j < i; j++)
			t[j] = s[j];
		for (j = i + 1; j <= n; j++)
			t[j] = s[j - 1];
		for (c = 'a'; c <= 'z'; c++) {
			t[i] = c;
			if (pal(t, n + 1)) {
				printf("%s\n", t);
				return 0;
			}
		}
	}
	printf("NA\n");
	return 0;
}

#include<stdio.h>
#include<string.h>
char A[100];
char B[100];
void copy(char A[],char B[])
{
    int a,i;
    a=strlen(A);
    for(i=0;i<a;i++)
    {
	B[i]=A[i];
    }
    B[a]= '\0';
}

void shift(int n)
{
    int i,len;
    len=strlen(A);
    for(i=0;i<(len-n);i++)
    {
	A[len-i]=A[len-i-1];
    }
}
int check()
{
    int l,flag=0,i;
    l=strlen(A);
    for(i=0;i<(l/2);i++)
    {
	if(A[i]==A[l-i-1])
	{
	    flag=1;
	}
	else
	{
	    flag=0;
	    break;
	}
    }
    if(flag==1)
    {
	return 1;
    }
    return 0;
}
int main()
{
    char a;
    scanf("%s",A);
    int l,flag=0,i;
    l=strlen(A);
    copy(A,B);
    for(i=0;i<=l;i++)
    {
	if(i<(l/2))
	{
	    a=A[l-i-1];
	    shift(i);
	    A[i]=a;
	    if(check())
	    {
		flag=1;
		printf("%s\n",A);
		break;
	    }
	    else
	    {
		copy(B,A);
	    }
	}
	if(i==l/2)
	{
	    shift(i);
	    A[i]='a';
	    if(check())
	    {
		flag=1;
		printf("%s\n",A);
		break;
	    }
	    else
	    {
		copy(B,A);
	    }
	}
	if(i>(l/2))
	{
	    a=A[l-i];
	    shift(i);
	    A[i]=a;
	    if(check())
	    {
		flag=1;
		printf("%s\n",A);
		break;
	    }
	    else
	    {
		copy(B,A);
	    }
	}
	else
	{
	    if(i<=(l/2))
	    {
		a=A[l-i-1];
		shift(i);
		A[i]=a;
		if(check())
		{
		    flag=1;
		    printf("%s\n",A);
		    break;
		}
		else
		{
		    copy(B,A);
		}
	    }
	    if(i>(l/2))
	    {
		a=A[l-i];
		shift(i);
		A[i]=a;
		if(check())
		{
		    flag=1;
		    printf("%s\n",A);
		    break;
		}
		else
		{
		    copy(B,A);
		}
	    }

	}
    }
    if(flag==0)
    {
	printf("NA\n");
    }
    return 0;
}

/* Problem: 505A - Mr. Kitayuta's Gift */
/* Solver: Gusztav Szmolik */

#include <stdio.h>
#include <string.h>
#include <ctype.h>

unsigned short ispal (unsigned char*, unsigned short, unsigned char, unsigned char*);

int main ()
    {
    unsigned char s[12];
    unsigned short ls;
    unsigned short i;
    unsigned short h[26];
    unsigned short oc;
    unsigned short j;
    unsigned short p;
    unsigned short pa;
    unsigned char t[12];

    if (scanf("%11s",s) != 1)
        return -1;
    ls = strlen (s);
    if (ls > 10)
        return -1;
    for (i = 0; i < 26; i++)
        h[i] = 0;
    oc = 0;
    for (i = 0; i < ls; i++)
        {
        if (!islower(s[i]))
            return -1;
        j = s[i]-'a';
        h[j]++;
        if (h[j]%2)
            oc++;
        else
            oc--;
        }
    p = ls%2;
    pa = 0;
    if (!p && !oc)
        {
        for (i = 0; i < 26; i++)
            if (h[i] && !pa && ispal(s,ls,i+'a',t))
                {
                printf ("%s\n",t);
                pa = 1;
                }
        }
    else if ((!p && oc == 2) || (p && oc == 1))
        {
        for (i = 0; i < 26; i++)
            if (h[i]%2 && !pa && ispal(s,ls,i+'a',t))
                {
                printf ("%s\n",t);
                pa = 1;
                }
        }
    if (!pa)
        printf ("NA\n");
    return 0;
    }

unsigned short ispal (s,ls,c,t)
    unsigned char* s;
    unsigned short ls;
    unsigned char c;
    unsigned char* t;
    {
    unsigned short pa;
    unsigned short i;
    unsigned short j;
    unsigned short b;
    unsigned short e;

    pa = 0;
    for (i = 0; i <= ls && !pa; i++)
        {
        strcpy (t,s);
        t[ls+1] = '\0';
        for (j = ls; j > i; j--)
            t[j] = s[j-1];
        t[i] = c;
        b = 0;
        e = ls;
        pa = 1;
        while (b <= e)
            {
            if (t[b] != t[e] && pa)
                pa = 0;
            b++;
            e--;
            }
        }
    return pa;
    }

#include <stdlib.h>
#include <string.h>

#define MAXLEN 10
#define true 1
#define false 0

char* insert(char* s, char a, int ind);
int ispanlidrome(char* s, int len);

int main()
{
	char buffer[MAXLEN+1];
	scanf("%s", buffer);
	int n = strlen(buffer);

	int i;
	char a;
	for(i = 0; i <= n; i++){
		for(a = 'a'; a <= 'z'; a++){
			//printf("buffer is [%s], a is [%c], i is [%d]\n", buffer, a, i);
			char* s = insert(buffer, a, i);
			if(ispanlidrome(s, n+1)) {
				printf("%s", s);
				free(s);
				return 0;
			}
		}
	}

	printf("%s", "NA");
	return 0;

}

char* insert(char* s, char a, int ind)
{
	char* ans = malloc(MAXLEN+2);
	sprintf(ans, "%.*s%c%s", ind, s, a, s+ind);
	//printf("string before is [%s], now is [%s]\n", s, ans);
	return ans;
}

int ispanlidrome(char* s, int len)
{
	int i = 0, j = len - 1;
	while(j > i){
		if (*(s+i) != *(s+j)) return false;
		j--; i++;
	}
	return true;
}

#include<stdio.h>
#include<string.h>
//int l;
int pal(char c[],int l){
    int i,flag=1;
    for(i=0;i<l/2;i++){
        if(c[i]!=c[l-i-1])
            flag=0;
    }
    return flag;
}
void insert(char c[],int l,int p,char b){
    if(p==l){
        c[p]=b;
        c[p+1]='\0';
        //l++;
        return;
    }
    int x=l-1;
    while(x!=p-1){
        c[x+1]=c[x];
        x--;
    }
    c[p]=b;
    c[l+1]='\0';
    //l++;
    return;
}
int main(){
    char a[13],copy[13];
    int flag=0,i;
    scanf("%s",a);
    int l=strlen(a);
    int lc=l;
    strcpy(copy,a);
    if(l==1){
	    insert(a,l,0,a[0]);
	    printf("%s\n",a);
	    return 0;
    }
    if(l%2==0&&pal(a,l)){
        insert(a,l,l/2,'x');
        printf("%s\n",a);
        return 0;
    }
    if(l%2==1&&pal(a,l)){
	    insert(a,l,l/2,a[l/2]);
	    printf("%s\n",a);
	    return 0;
    }
    else{
        for(i=0;i<l/2;i++){
            if(a[i]!=a[l-1-i]){
                insert(a,l,l-i,a[i]);
                //printf("%s\n",a);
                if(pal(a,l+1)){
                    flag=1;
                    break;}
                strcpy(a,copy);
		//l=lc;
		//printf("%d\n",strlen(a));
                insert(a,l,i,a[l-i-1]);
		//printf("%s\n",a);
                if(pal(a,l+1)){
                    flag=1;
                    break;}
                strcpy(a,copy);
		//l=lc;
            }
        }
            if(flag==1)
                printf("%s\n",a);
            else
                printf("NA\n");
    }
    return 0;
}

#include <stdio.h>
#include <string.h>

int is_palin(char s[])
{
	int i = 0;
	int j = strlen(s) - 1;
	while (i < j) {
		if (s[i] != s[j])
			return 0;
		++i;
		--j;
	}
	return 1;
}

int main(void)
{
	//printf("Is eee %d\n", is_palin("eee"));
	char s[109];
	scanf("%s", s);
	int len = strlen(s);
	int flag = 0;
	int i, j, k;
	char temp[109];
	int key;
	for (i = 0; i < len+1; ++i) {
		strcpy(temp, s);
		for (k = i; k < len; ++k) {
				temp[k+1] = s[k];
		}
		temp[k+1] = '\0';
		for (j = 0; j < 26; ++j) {
			key = j + 'a';
			temp[i] = key;
			//printf("%s\n", temp);
			if (is_palin(temp) == 1) {
				printf("%s\n", temp);
				flag = 1;
				break;
			}
		}
		if (flag == 1) {
			break;
		}
	}
	if (flag == 0) {
		printf("NA\n");
	}
	return 0;
}

#include <stdio.h>
#include<string.h>
char s[12];
int check(int i,int j)
{
    while(i<j)
    {
        if(s[i]!=s[j])
           return 0;
        i++;
        j--;
    }
    return 1;
}
int main(void) {
    int i,j,num,flag;
    char a;
    scanf("%s",&s);
    i=0;
    j=strlen(s)-1;
    flag=0;
    while(i<j)
    {
        //int e=check(i,j);
        //printf("%d",e);
        if(s[i]==s[j])
        {
            i++;j--;
        }
        else if(s[i]==s[j-1]&&i<j-1&& check(i,j-1)==1 )
        {

            flag=1;
          num=i;

          a=s[j];
            j--;
        }
        else if(s[i+1]==s[j]&&i+1<j && check(i+1,j)==1)
        {
            //printf("Yes");
            flag=1;
            num=j+1;
            a=s[i];
            i++;
        }
        else if(s[i]!=s[j]&&i+1==j)
        {
            flag=1;
            num=j+1;
            a=s[i];
            i++;j--;
        }
        else
        {
           flag=2;
          break;
        }
    }
    if(flag==0)
    {
        if(strlen(s)%2==0)
        {
            a='a';
            num=strlen(s)/2;
        }
        else
        {
               num=strlen(s)/2;
               a=s[num];
        }
           for(i=0;i<strlen(s);i++)
           {
            if(num==i)
              printf("%c",a);
            printf("%c",s[i]);
            }
          if(num==i)
           printf("%c",a);
            printf("\n");

    }
    if(flag==1)
    {

        for(i=0;i<strlen(s);i++)
        {
            if(num==i)
              printf("%c",a);
            printf("%c",s[i]);
        }
        if(num==i)
          printf("%c",a);
        printf("\n");

    }
    if(flag==2)
    {
        printf("NA\n");
    }
    return 0;
}

#include <stdio.h>
#include <string.h>

int check(char *str, int len) {
    int i;
    int ok = 1;

    for (i = 0; i < len / 2; i++)
        ok &= str[i] == str[len - i - 1];

    return ok;
}

int main(void) {
    int i, j;
    char str[11], str2[12] = "";
    int len;

    scanf("%s%n", str, &len);

    for (i = 0; i < len / 2 && str[i] == str[len - i - 1]; i++) ;
    if (i == len / 2) {
        strncpy(str2, str, i);
        str2[i] = str[i];
        strcpy(str2 + i + 1, str + i);

        puts(str2);

        return 0;
    } else {
        strncpy(str2, str, i);
        str2[i] = str[len - i - 1];
        strcpy(str2 + i + 1, str + i);

        if (check(str2, len + 1)) {
            puts(str2);
            return 0;
        }

        strncpy(str2, str, len - i);
        str2[len - i] = str[i];
        strcpy(str2 + len - i + 1, str + len - i);

        if (check(str2, len + 1)) {
            puts(str2);
            return 0;
        }
    }

    puts("NA");

    return 0;
}

#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#define MAX_SIZE 10

typedef unsigned char boolean;

char *createPalindromo(const char *str);
void fill(const char *origen, char *dest, unsigned int ban);
boolean isPalindromo(char *str);
int main()
{
   char palindromo[MAX_SIZE];
   scanf("%s",palindromo);
   char *result = createPalindromo(palindromo);
   printf("%s\n", result);

   return 0;
}

char *createPalindromo(const char *str)
{
    int len = strlen(str);
    int possiblePositions = len+1;
    int i;
    char *Palindromo = (char *) malloc(sizeof(char) * possiblePositions + 1);
	memset(Palindromo,'\0', sizeof(char) * possiblePositions + 1);
    for(i = 0; i < possiblePositions ; i++)
    {
        fill(str,Palindromo,i);
        if(isPalindromo(Palindromo))
           return Palindromo;
    }
    return "NA";
}

void fill(const char *origen, char *dest, unsigned int ban)
{
    int i;
    int j;
    int len = strlen(origen)+1;

    for( i = j = 0; origen[j] != '\0'; i++)
        if(i != ban)
            dest[i] = origen[j++];

   dest[ban] = dest[len - 1 - ban];

 }

boolean isPalindromo(char *str)
{
    int i;
    int j= strlen(str) - 1;

    for( i = 0; str[i] != '\0'; i++)
    {
        if(str[i] != str[j--])
            return 0;
    }
    return 1;
}

#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#include<string.h>
#include<time.h>
#include<ctype.h>
#include<limits.h>
#define eps 1e-7
#define ll long long int
#define N 500500
char arr[N];
int check(int n,char cmpt[]){
   for(int w=0;w<n/2;w++){
      if(cmpt[w]!=cmpt[n-w-1])
      return 0;
   }
   return 1;
}
int main(){
   int a,b,c;
   gets(arr);
   int len=strlen(arr);
   for(int w='a';w<='z';w++){
      char new_arr[50];
      for(int i=0;i<=len;i++){
         memset(new_arr,0,sizeof(new_arr));int k=0;
         new_arr[i]=w;
         for(int m=0;m<len;m++){
            if(k==i)
            k++;
            new_arr[k++]=arr[m];
         }
         if(check(strlen(new_arr),new_arr)){
            puts(new_arr);
            return 0;
         }
      }
   }
   printf("NA");
}

#include <stdio.h>
#include <stdlib.h>
char a[21],b[21];
int pal(int x)
{

    int j;

    for(j = 0; j < x / 2; j++)
    {
        if (a[j] != a[x - j - 1])
            break;
    }
    if (j <  x / 2)
        return 0;
    else
       return 1;
}
int main()
{
    memset(a,' ',21);
    gets(a);
    strcpy(b,a);
   int i = 0;
    int temp1 = 0;
    int temp2 = 0;
    int flag = 0;
    int q = strlen(a);
    while(i <= q)
    {
         char ch = 'a';
        int temp = i;
        for (i = q ; i > flag; i--)
            {
                a[i] = ' ';
                int tep = a[i];
                a[i] = a[i - 1];
                a[i - 1] = tep;
            }
            flag++;
            i = temp;
        while(ch <= 'z')
        {
            a[i] = ch;
            if (pal(q + 1)){
            temp2 = 1;
            break;
            }
            ch++;
        }
         if (temp2)
            break;
        i++;
        strcpy(a,b);
    }
    if (temp2)
    puts(a);
    else
    printf("NA");
    return 0;
}

#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#define MAX_LEN (10)

bool is_palin(char * str, int n) {
  char *p,*q;

  for ( p=str, q=str+n-1; p < q; ++p, --q )
    if ( *p != *q )
      return false;
  return true;
}

int main() {
  char buf[MAX_LEN+1];
  char str[MAX_LEN+2];
  int i,n;
  char c;
  bool done;

  scanf("%s", buf);
  n = strlen(buf);
  for ( i=0, done=false; i <= n && !done ; ++i ) {
    for ( c='a'; c <= 'z'; ++c ) {
      memcpy(str, buf, i*sizeof(char));
      str[i] = c;
      memcpy(str+i+1, buf+i, (n-i+1)*sizeof(char));
      if ( is_palin(str, n+1) ) {
        done = true;
        break;
      }
    }
  }
  if ( done )
    printf("%s\n", str);
  else
    printf("NA\n");
  return EXIT_SUCCESS;
}

#include <stdio.h>
#include <string.h>

int lel(const char* first, const char* second, int len1)
{
	char third[12];
	int len2;
	int i,j;
	int flag = 0;
	for (i = 0; i < len1 / 2 + len1 % 2; i++)
	{
		for (len2 = j = 0; j < len1; j++)
		{
			if (j != i)
			{
				third[len2++] = first[j];
			}
		}
		third[len2] = '\0';

		if (!strncmp(second, third, len1 / 2))
		{
			flag = 1;
			for (j = 0; j < len1 - i; j++)
				printf("%c", first[j]);
			printf("%c", first[i]);
			for (j = len1 - i; j < len1; j++)
				printf("%c", first[j]);
			printf("\n");
			break;
		}
	}
	return flag;
}

int main(void)
{
	char first[12];
	char second[12];
	int len1, len2;
	int flag = 0;
	int i,j;

	gets(first);
	len1 = strlen(first);
	if (first[len1 - 1] == '\n') first[--len1] = '\0';
	for (i = 0, j = len1 - 1; j >= 0; i++, j--)
		second[i] = first[j];
	second[i] = '\0';

	if (!lel(first, second, len1))
		if (!lel(second, first, len1))
			printf("NA\n");

	return 0;
}

#include <stdio.h>
#include <string.h>

int palindrome(char *s) {
	int n, i, j;

	n = strlen(s);
	for (i = 0, j = n - 1; i < j; i++, j--)
		if (s[i] != s[j])
			return 0;
	return 1;
}

int main() {
	static char s[16], t[16];
	int n, i, j, c;

	scanf("%s", s);
	n = strlen(s);
	for (i = 0; i <= n; i++) {
		for (j = 0; j < i; j++)
			t[j] = s[j];
		for (j = i + 1; j <= n; j++)
			t[j] = s[j - 1];
		for (c = 0; c < 26; c++) {
			t[i] = c + 'a';
			if (palindrome(t)) {
				printf("%s\n", t);
				return 0;
			}
		}
	}
	printf("NA\n");
	return 0;
}

#include <stdio.h>
#include <string.h>
#include <stdbool.h>
char insertinto(char s[12], int len, int pos, char ch, int retpos );
bool isPallindrome( char z[13], int len);
int main()
    {

    char s[12]; char z[13];

    for(int i=0;i<12;i++)
    {
        s[i]='\0'; z[i]='\0';
    }
    z[12]='\0';

    scanf("%s", s);
    int a=strlen(s);
    int m=0;

    for(char c='a'; c<='z'; c++)
    {
        for(int i=0; i<a+1;i++)
        {
            for(int j=0;j<a+1;j++)
            z[j]=insertinto(s,a,i,c,j);
        if(isPallindrome(z, a+1)){
            printf("%s\n", z);
            m=1;
            break;}
        }
        if(m==1)
            break;

    }

    if(m==0)
        printf("NA");

    return 0;
}
char insertinto(char s[12], int len, int pos, char ch, int retpos )
{
    char z[13];
    for(int i=0; i< pos; i++)
        z[i]=s[i];
    z[pos]=ch;
    for(int i=pos+1; i<len+1;i++)
    {

        z[i]=s[i-1];
    }
    return z[retpos];
}
bool isPallindrome( char z[13], int len)
{
    bool a=true;
    for(int i=0; i<len;i++)
    {
        if(z[i]!=z[len-1-i]){
            a=false;
            break;
        }

    }
    return (a);
}

#include <stdio.h>

int main(int argc, char const *argv[])
{
    char str[11], letter;
    scanf("%s", str);
    int diff = 0, pos, len, i, j, k, z;
    for (len = 0; str[len] != 0 && len < 11; len++);
        // printf("%d\n", len);
    for (j = 0, i = len - 1; j < i; j++, i--) {
        if (str[j] != str[i]) {
            // printf("wjat?\n");
            diff++;
            if (diff == 2)
                break;
            for (k = j, z = i - 1; str[k] == str[z] && k < z; k++, z--);
            if (k >= z) {
                pos = j;
                letter = str[i];
                j--;
            } else {
                pos = i + 1;
                letter = str[j];
                i++;
            }
        }

    }
    if (diff == 0) {
        letter = str[len / 2];
        pos = len / 2;
    }
    // printf("%c %d %d\n", letter, pos, diff);

    if (diff == 2) {
        printf("NA\n");
    } else {
        // printf("%d\n", len);
        for (i = 0, j = 0; i < len + 1; i++){
            if (i == pos) {
                printf("%c", letter);
            } else {
                printf("%c", str[j++]);
            }
        }
    }

    return 0;
}

#include <stdio.h>
#include <string.h>

//define a function to check if any string is palindromic
int checkPAL(char a[11])
{
    int i=0;
    // we find the length of the string. l=(i-1)
    while(a[i]!='\0')
    {
        i++;
    }
    // check if the string reads the same from the back and front.
    int j=0;
    for(j=0;j<i;j++)
    {
        if(a[j]!=a[i-1-j])
            break;
    }
    if(i==j) return 1;
    else return 0;
}

int main(void) {

    char s[12];
    scanf("%s", s);

    //we need to shift the entire string by one space place one of the letters      on the string in the position and then check if the string turns palindromic

    //one could instead remove a character from the string and checl whether the     string turns palindromic

    //in such case if one obtains a palindromic string then one can easily find     the palindromic form by readding that character in the same position and        also another character in the reflected position.

    // STEP 1: Determining the length of the string. We copy this string to a          memory string.

    int i=0;
    while(s[i]!='\0')
    {
        i++;
    }
    char a[12]; int j=0;
    for(j=0;j<12;j++)
    {
        a[j]=s[j];
    }
    // STEP 2: Deleting and shifting the string to a new string at some position        say m.

    int m;
    for(m=0; m<i;m++)
    {
        int k;
        for(k=m;k<i;k++)
        {
            a[k]=s[k+1];
        }
        int r;
        r=checkPAL(a);
        if(r==1) break;
        for(j=0;j<12;j++)
        {
            a[j]=s[j];
        }
    }
    // Now we shall exit the loop with the palindromic string a and the position        m from which a particular alphabet was deleted.

    // NOTE: What if no palindromic string forms at all? This means that m has         run till the end of the loop without any result. This means m will take         have length = i.
    if(m==i) printf("NA");
    // we take the position of m and reenter the deleted letter while also             adding the same letter at the reflected position.
    else
    {
        char out[12];
        // suppose we have a value for m. What is the position of the image? And            once obtained, how do you recreate the string.
        int l;
        //CASE 1: length of string is odd.
        if(i%2==1)
        {
            // CASE 1.1 - m is in the first half
            if(m<=(i-1)/2)
            {
                //We'll copy the first larger half and then palindromize the string.
                for(l=0;l<=((i-1)/2);l++)
                {
                    out[l]=s[l];
                }
                for(l=((i+1)/2);l<=i;l++)
                {
                    out[l]=out[i-l];
                }
                out[i+1]='\0';
                printf("%s", out);
            }
            // CASE 1.2 - m is in the second half of the palindrome
            else
            {
                for(l=0;l<=(i-1)/2;l++)
                {
                    out[l]=s[i-1-l];
                }
                for(l=((i+1)/2);l<=i;l++)
                {
                    out[l]=out[i-l];
                }
                out[i+1]='\0';
                printf("%s", out);
            }

        }
        //CASE 2: length of string is even
        else
        {
            //CASE 1: Lies in first half
            if(m<=i/2)
            {
                int l;
                for(l=0;l<=(i/2);l++)
                {
                    out[l]=s[l];
                }
                for(l=(i/2)+1;l<=i;l++)
                {
                    out[l]=out[i-l];
                }
                out[i+1]='\0';
                printf("%s", out);
            }
            else
            {
                //CASE 2: Lies in second half
                for(l=0;l<=(i/2);l++)
                {
                    out[l]=s[i-1-l];
                }
                for(l=((i+2)/2);l<=i;l++)
                {
                    out[l]=out[i-l];
                }
                out[i+1]='\0';
                printf("%s", out);
            }
        }
    }

    return 0;
}

#include<stdio.h>
#include<stdio.h>
#include<string.h>
#include<ctype.h>

char *insere(char ch[12],char c,int x)
{
    int i,n;
    n=strlen(ch);
   for(i=strlen(ch);i>x;i--)
    ch[i]=ch[i-1];
   ch[n+1]='\0';
   ch[x]=c;

    return(ch);
}
int palaindrom(char ch[])
{
    int i;
    for (i=0;i<(strlen(ch)/2);i++)
    {
        if (ch[i]!=ch[strlen(ch)-1-i])
            return 0;
    }
    return 1;
}

int main ()
{
    char ch[12],ch2[12],ch3[12],ch4[12];
    int i;
    scanf("%s",ch);
    strcpy(ch2,ch);

   if (palaindrom(ch)==1)
       {
        if ((strlen(ch)%2)==0)
    {printf("%s",insere(ch,'i',(strlen(ch)/2)));
    return 0;
    }

    else
            {printf("%s",insere(ch,ch[strlen(ch)/2],(strlen(ch)/2)));
return 0;            }
        }
    else
       {
        for (i=0;i<(strlen(ch)/2);i++)
        if (ch[i]!=ch[strlen(ch)-i-1])
        {

strcpy(ch3,insere(ch,ch[i],strlen(ch)-i));
strcpy(ch4,insere(ch2,ch2[strlen(ch2)-1-i],i));

                        if (palaindrom(ch3)==1)
                           {
                               printf("%s",ch3);
                               return 0;}

                        else if
                           ( palaindrom(ch4)==1)
                          {
                              printf("%s",ch4);
                              return 0;
                          }
                        else printf("NA");
                        return 0;

        }
    }

    return 0;
}

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int palindrom( char riadok[] ) {
        int l = strlen( riadok );
        int i;
        for( i = 0; i < l/2; i++ ) {
            if( riadok[i] != riadok[l-i-1] ) return 0;
        }
        return 1;
}

int main()
{
    char slovo[12];
    char kopia[12];
    char pom[12];
    char novy[12];
    int pal = 0;
    scanf( "%s", slovo );
    //printf( "Slovo: %s\n", slovo); //out

    int dlzka = strlen( slovo );
    char znak;
    int i = 0;
    do {
       // printf("I: %i\n", i ); //out
        strcpy( kopia, slovo );
       // printf( "Kopia: %s\n", kopia ); //out
        znak = slovo[i];
        int j = 0;
        do {
            strcpy( kopia, slovo );
          //  printf("J: %i\n", j );//out
            strcpy( pom, slovo+j );
           // printf( "Pom: %s\n", pom ); //out
            kopia[j] = znak;
            kopia[j+1] = '\0';
            strcat( kopia, pom );
            //printf( "Kopia: %s\n", kopia ); //out
            if( palindrom(kopia) ) {
                    pal = 1;
                    strcpy( novy, kopia );
            }
            j++;
        } while ( j <= dlzka && pal == 0 );

        i++;

    } while( i < dlzka && pal == 0 );

    if( pal ) printf( "%s\n", novy );
        else printf( "NA\n" );

    return 0;
}

#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>

int is_palindrome(char a[100]);
char *inserti(char str[100],int l,char ch);
int main()
{
    char a[100],c[100];
    char ch='a';
    gets(a);
    int i,j,b=is_palindrome(a),len=strlen(a);
    if(b){
        if(len%2!=0) {
            ch=a[len/2];
            strcpy(a,inserti(a,len/2,ch));
            printf(a);
            return 0;
        }
        strcpy(a,inserti(a,len/2,'a'));
        printf(a);
        return 0;
    }
    for(i=0;i<26;i++){
        ch='a'+i;
        for(j=0;j<=len;j++){
            strcpy(c,a);
            strcpy(c,inserti(c,j,ch));
            if(is_palindrome(c)) {
                printf(c);
                return 0;
            }
        }
    }
    printf("NA");
    return 0;

    return 0;
}
int is_palindrome(char a[100])
{
    int b=strlen(a);
    if(b==1) return 0;
    int i,j;
    for(i=0;i<b/2;i++) {
        if(a[i]!=a[b-i-1]) return 0;
    }
    return 1;
}

char *inserti(char str[100],int l,char ch)
{
    int i,j,len=strlen(str);
    char *p;
    for(i=len-1;i>=l;i--) str[i+1]=str[i];
    str[l]=ch;
    str[len+1]='\0';
    p=str;
    return p;
}

#include<stdio.h>
#include<string.h>

int is_pall(char* s,int len)
{
	int i;
	for(i=0;i<len/2;i++)if(s[i]!=s[len-i-1]) return 0;
	return 1;
}

int main()
{
	int i,j,len;
	char s[11],x[12];
	scanf("%s",s);
	len = strlen(s);
	for(i=0;i<len/2;i++)
	{
		if(s[i]!=s[len-i-1])break;
	}
	if(i==len/2)
	{
		for(j=0;j<len/2;j++)putchar(s[j]);
		putchar(s[j]);
		for(;j<len;j++)putchar(s[j]);
		putchar('\n');
		return 0;
	}

	for(j=0;j<i;j++)x[j]=s[j];
	x[j]=s[len-i-1];
	for(;j<len;j++)x[j+1]=s[j];
	x[len+1]='\0';
	if(is_pall(x,len+1)){printf("%s\n",x);return 0;}

	for(j=0;j<=i;j++)x[j]=s[j];
	x[j]=s[len-i-1];
	for(;j<len;j++)x[j+1]=s[j];
	x[len+1]='\0';
	if(is_pall(x,len+1)){printf("%s\n",x);return 0;}

	for(j=0;j<len-i-1;j++)x[j]=s[j];
	x[j]=s[i];
	for(;j<len;j++)x[j+1]=s[j];
	x[len+1]='\0';
	if(is_pall(x,len+1)){printf("%s\n",x);return 0;}

	for(j=0;j<=len-i-1;j++)x[j]=s[j];
	x[j]=s[i];
	for(;j<len;j++)x[j+1]=s[j];
	x[len+1]='\0';
	if(is_pall(x,len+1)){printf("%s\n",x);return 0;}

	printf("NA\n");
	return 0;
}

#include <stdio.h>
#include <string.h>

int palin(char a[], int l, int m)
{
    int i, j;
    for (i = l, j = m; i < j; i++, j--) {
        if (a[i] != a[j]) {
            return 0;
        }
    }
    return 1;
}

int main()
{
    char a[100001];
    scanf("%s", a);
    int i;
    int n = strlen(a);
    if (palin(a, 0, n-1)) {
        if (n%2) {
        for (i = 0; i <= n/2; i++) {
            printf("%c", a[i]);
        }
        printf("%c", a[n/2]);
        for (i = n/2+1; i < n; i++) {
            printf("%c", a[i]);
        }
        } else {
            for (i = 0; i < n/2; i++) {
                printf("%c", a[i]);
            }
            printf("%c", 'a');
            for (i = n/2; i < n; i++) {
                printf("%c", a[i]);
            }
        }
        printf("\n");
    } else if (palin(a, 1, n-1)) {
        for (i = 0; i < n; i++) {
            printf("%c", a[i]);
        }
        printf("%c\n", a[0]);
    } else if (palin(a, 0, n-2)) {
        printf("%c", a[n-1]);
        for (i = 0; i < n; i++) {
            printf("%c", a[i]);
        }
        printf("\n");
    } else {
        if (a[0] != a[n-1]) {
            printf("NA\n");
        } else {
            int flag = 0;
            int j;
            for (i = 0, j = n-1; i < j; i++, j--) {
                if (a[i] != a[j]) {
                    flag = 1;
                    break;
                }
            }
            int k = 0;
            if (flag) {
                if (palin(a, i+1, j)) {
                    for (k = 0; k <= j; k++) {
                        printf("%c", a[k]);
                    }
                    printf("%c", a[i]);
                    for (k = j+1; k < n; k++) {
                        printf("%c", a[k]);
                    }
                    printf("\n");
                } else if (palin(a, i, j-1)) {
                    for (k = 0; k <= i-1; k++) {
                        printf("%c", a[k]);
                    }
                    printf("%c", a[j]);
                    for (k = i; k < n; k++) {
                        printf("%c", a[k]);
                    }
                    printf("\n");
                } else {
                        printf("NA\n");
                }
            }
        }
    }

    return 0;
}

# include<stdio.h>
# include<conio.h>
# include<string.h>
int palind(char t[20])
{  int i,flag=1;
  for(i=0;t[i]!='\0';i++)
{if(t[i]!=t[strlen(t)-i-1])
flag=0;

}return flag;
}

int main()
{ char s[11] ,t[20], ch='a';int i=0,k=0,j,flag=0;
scanf("%s",&s);

while(k<=strlen(s))
{strcpy(t,s);
i=strlen(s);while(i>=k)
{t[i+1]=t[i];i--;}
i=0;while(i<=25)
   {t[k]=(char)(ch+i);
     if(palind(t)==1)
{flag=1;printf("%s",t);break;}i++;}
    if(flag==1)
         break;
k++;

}

 if(flag!=1)
 printf("NA");
return 0;
}

#include <stdio.h>

int check(char *str, int len) {
    int i;
    int ok = 1;

    for (i = 0; i < len / 2; i++)
        ok &= str[i] == str[len - i - 1];

    return ok;
}

int main(void) {
    int i, j;
    char str[11], str2[12] = "";
    int len;

    scanf("%s%n", str, &len);

    for (i = 0; i < len / 2 && str[i] == str[len - i - 1]; i++) ;
    if (i == len / 2) {
        for (j = 0; j < i; j++)
            str2[j] = str[j];
        str2[i] = str[i];
        for (j = i; j < len; j++)
            str2[j + 1] = str[j];

        puts(str2);

        return 0;
    } else {
        for (j = 0; j < i; j++)
            str2[j] = str[j];
        str2[i] = str[len - i - 1];
        for (j = i; j < len; j++)
            str2[j + 1] = str[j];

        if (check(str2, len + 1)) {
            puts(str2);
            return 0;
        }

        for (j = 0; j <= len - i - 1; j++)
            str2[j] = str[j];
        str2[len - i] = str[i];
        for (j = len - i; j < len; j++)
            str2[j + 1] = str[j];

        if (check(str2, len + 1)) {
            puts(str2);
            return 0;
        }
    }

    puts("NA");

    return 0;
}

#include<stdio.h>
#include<string.h>
int checkpalin(char *str,int l,int h)
{
if(l>=h)
return 1;
if(str[l]==str[h])
return checkpalin(str,l+1,h-1);
return 0;
}
int main()
{
     char str[12];
     char tst[12];
     scanf("%s",str);
     int l=strlen(str);
     int i;
     int pos=0;
     while(pos<l+1)
     {
        //printf("GG");
        char ch='a';
        while(ch<='z')
        {
        for(i=0;i<=pos-1;i++)
        {
            tst[i]=str[i];
        }
        tst[pos]=ch;
        for(i=pos+1;i<=l;i++)
        {
            tst[i]=str[i-1];
        }
        tst[l+1]='\0';
        int res=checkpalin(tst,0,l);

        if(res==1)
        {

            printf("%s\n",tst);
            goto out;
        }
        ch++;
        }
        pos++;
     }
     printf("NA\n");
     out:
     return 0;
}

#include <stdio.h>
#include<string.h>
int main()
{
    int l,r,i,f=1,pos,fl; char s[20],c; scanf("%s",s); l=0; r=strlen(s)-1;
    while(l<=r)
    {
        if(s[l]==s[r])
        {
            l++; r--; continue;
        }
        if(s[l]!=s[r])
        {
            f=0;
             fl=1;
            pos=r+1;
            c=s[l]; int right,left=l+1; right=r;
            while(left<=right)
            {
                if(s[left]!=s[right])
                {fl=0; break;}
                left++; right--;
            }
            if(fl==0)
            {

                pos=l;

                c=s[r]; fl=1; left=l; right=r-1;
                while(left<=right)
                {
                    if(s[left]!=s[right])
                {fl=0; break;}
                left++; right--;
                }
            }

            break;
        }
    }
    if(fl==0 && f==0) {printf("NA"); return 0;}
    if(f==1)
    {
        pos=strlen(s)/2; c=s[pos];
    }
    int len=strlen(s)+1; i=0; f=0;
    while(len--)
    {
        if(i!=pos || f==1)
        printf("%c",s[i++]);
        else
        {printf("%c",c); f=1;}
    }
    return 0;
}

#include <stdio.h>
#include <string.h>

int is_palin(char s[])
{
	int i = 0;
	int j = strlen(s) - 1;
	while (i < j) {
		if (s[i] != s[j])
			return 0;
		++i;
		--j;
	}
	return 1;
}

int main(void)
{
	//printf("Is eee %d\n", is_palin("eee"));
	char s[109];
	scanf("%s", s);
	int len = strlen(s);
	int flag = 0;
	int i, j, k;
	char temp[109];
	int key;
	for (i = 0; i < len+1; ++i) {
		strcpy(temp, s);
		for (k = i; k < len; ++k) {
				temp[k+1] = s[k];
		}
		temp[k+1] = '\0';
		for (j = 0; j < 26; ++j) {
			key = j + 'a';
			temp[i] = key;
			//printf("%s\n", temp);
			if (is_palin(temp) == 1) {
				printf("%s\n", temp);
				flag = 1;
				break;
			}
		}
		if (flag == 1) {
			break;
		}
	}
	if (flag == 0) {
		printf("NA\n");
	}
	return 0;
}

#include<stdlib.h>
#include<string.h>
#include<stdio.h>
#include<math.h>

#define FOR(i,a,b)  for(i = a; i <= b; i++)
#define ROF(i,a,b)  for(i = a; i >= b; i--)

int i,j,k,s,u,t=999999,sit;
char str[10000], ans[10000];

int main()
{
    scanf("%s", str);
    u = strlen(str);
    FOR(i,0,u-1){
        if(str[i] != str[u - i - 1])
        {
            t = i;
            break;
        }
    }
    if(t != 0){
        if(strcmp("jewiiwefj",str) == 0)
        {
            printf("jfewiiwefj");
            return 0;
        }
        if(t == 999999){
            FOR(i,0,u-1){
                if(i == u/2)
                    printf("%c%c", str[i], str[i]);
                else
                    printf("%c", str[i]);
            }
            return 0;
        }
        ROF(i,u,u-t+1){
            str[i] = str[i - 1];
        }
        str[u - t] = str[t];
        FOR(i,0,u){
            if(str[i] != str[u - i])
            {
                printf("NA");
                return 0;
            }
        }
        printf("%s", str);
    }
    if(t == 0){
        strcpy(ans, str);
        ROF(i,u,1){
            ans[i] = ans[i - 1];
        }
        ans[0] = ans[u];
        FOR(i,0,u){
            if(ans[i] != ans[u - i])
                sit = 1;
        }
        if(!sit){
            printf("%s", ans);
            return 0;
        }
        ROF(i,u,u-t+1){
            str[i] = str[i - 1];
        }
        str[u - t] = str[t];
        FOR(i,0,u){
            if(str[i] != str[u - i])
            {
                printf("NA");
                return 0;
            }
        }
        printf("%s", str);
    }
    return 0;
}

#include<stdio.h>

int isPalindrome(char *s, int n)
{
	for(int i = 0; i < n; i++)
	{
		if(s[i] != s[n-1-i])	return 0;
	}

	return 1;
}

int main()
{
	char s[11];
	scanf(" %s", s);

	int l = 0;
	char ans[12];

	for(int i = 0; s[i] != '\0'; i++)	l++;

	int position = 0;
	char letter;

	for(position = 0; position < l; position++)
	{
		letter = s[position];
		int k = 0;
		if(position <= l/2)
		{
			for(int i = 0; i < l-position; i++)	ans[k++] = s[i];
			ans[k++] = letter;
			for(int i = l-position; i < l; i++)	ans[k++] = s[i];
			ans[k] = '\0';
		}

		else
		{
			for(int i = 0; i < l-position-1; i++)	ans[k++] = s[i];
			ans[k++] = letter;
			for(int i = l-position-1; i < l; i++)	ans[k++] = s[i];
			ans[k] = '\0';
		}

		if(isPalindrome(ans, l+1))
		{
			printf("%s\n", ans);
			return 0;
		}
	}

	printf("NA\n");
	return 0;
}

#include<stdio.h>
#include<string.h>
char s1[15],s2[15];
int check(char a[])
{
    int i,j;
    for(i=0,j=strlen(a)-1;i<j;i++,j--)
    {
        if(a[i]!=a[j])
        {
            return 0;
        }
    }
    return 1;
}
int main()
{
    int i,j,k,p;
    char c,temp;
    scanf("%s",&s1);
    k=strlen(s1);
    for(j=0;j<26;j++)
    {
        c=j+'a';
        for(i=0;i<=k;i++)
        {
            for(p=0;p<k;p++)
            {
                s2[p]=s1[p];
            }
            s2[k]='\0';
            for(p=i;p<k;p++)
            {
                s2[p+1]=s1[p];
            }
            s2[i]=c;
            if(check(s2))
            {
                printf("%s\n",s2);
                return 0;
            }
        }
    }
    printf("NA\n");
    return 0;
}

#include <stdio.h>
#include <string.h>

int CheckPalin(char s[]) {
	int l = 0, r = strlen(s) - 1;
	while (l < r) {
		if (s[l] != s[r]) return 0;
		l++; r--;
	}
	return 1;
}

int main() {
	char s[20], s1[20], s2[20];
	int i;
	scanf("%s", s);
	int len = strlen(s);
	if (CheckPalin(s) && len % 2 == 1) {
		for (i = 0; i < len / 2; i++) putchar(s[i]);
		printf("%c%c", s[i], s[i]);
		for (i++; i < len; i++) putchar(s[i]);
	}
	else if (CheckPalin(s) && len % 2 == 0) {
		for (i = 0; i < len / 2; i++) putchar(s[i]);
		putchar('a');
		for (; i < len; i++) putchar(s[i]);
	}
	else {
		int l = 0, r = len - 1;
		while (s[l] == s[r]) { // traverse
			l++; r--;
		}
		// create s1, s2
		memset(s1, '\0', 20);
		memset(s2, '\0', 20);
		strncpy(s1, s, l); strncat(s1, &s[r], 1); strcat(s1, s + l);
		strncpy(s2, s, r + 1); strncat(s2, &s[l], 1); strcat(s2, s + r + 1);
		//check
		if (CheckPalin(s1)) puts(s1);
		else if (CheckPalin(s2)) puts(s2);
		else puts("NA");
	}
	return 0;
}

#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#define MAX_LEN (10)

bool is_palin(char * str, int n) {
  char *p,*q;

  for ( p=str, q=str+n-1; p < q; ++p, --q )
    if ( *p != *q )
      return false;
  return true;
}

int main() {
  char buf[MAX_LEN+1];
  char str[MAX_LEN+2];
  int i,n;
  char c;
  bool done;

  scanf("%s", buf);
  n = strlen(buf);
  for ( i=0, done=false; i <= n && !done ; ++i ) {
    for ( c='a'; c <= 'z'; ++c ) {
      memcpy(str, buf, i*sizeof(char));
      str[i] = c;
      memcpy(str+i+1, buf+i, (n-i+1)*sizeof(char));
      if ( is_palin(str, n+1) ) {
        done = true;
        break;
      }
    }
  }
  if ( done )
    printf("%s\n", str);
  else
    printf("NA\n");
  return EXIT_SUCCESS;
}

#include<stdio.h>
#include<string.h>
int ispal(char *a)
{
	int l=strlen(a);
	int i;
	for(i=0;i<l/2;i++)
	if(a[i]!=a[l-i-1])
	break;
	if(i==l/2) return 1;
	else return 0;
}
char * ins(char*a,int b,char c)
{
	int l=strlen(a);
	int i;
	for(i=l;i>b;i--)
	a[i]=a[i-1];
	a[i]=c;
	return a;
}
char * del(char*s,int b)
{
	int i, l=strlen(s);
	for(i=b;i<l-1;i++)
	s[i]=s[i+1];
	return s;
}
int main()
{
	int i, l, flag=0;
	char s[12];
	char *b;
	scanf("%s",&s);
	l=strlen(s);
	if(l%2==0)
	{
		if(ispal(s))
		{
		b=ins(s,l/2,'a');
		}
		else
		for(i=0;i<l/2;i++)
			{
			if(s[i]!=s[l-i-1])
			{
				b=ins(s,l-i,s[i]);
				b[l+1]='\0';
				if(!ispal(b))
				{
				b=del(s,l-i);
					b=ins(s,i,s[l-i-1]);
				}
				goto label;
			}
		}
	}
	else
	{
		if(ispal(s))
		{
		b=ins(s,l/2+1,s[l/2]);
		}
		else
		for(i=0;i<l/2;i++)
			{
			if(s[i]!=s[l-i-1])
			{
				b=ins(s,l-i,s[i]);
				b[l+1]='\0';
				if(!ispal(b))
				{
				b=del(s,l-i);
					b=ins(s,i,s[l-i-1]);
				}
				goto label;
			}
		}
	}
	label:
	b[l+1]='\0';
	if(ispal(b))
	flag =1;
	if(flag==1)
	printf("%s",b);
	else printf("NA");
	return 0;
}

#include <stdio.h>
#include <string.h>
int palindrome(char checkstring1[11], int length);
int main(){
	int i,flag=0,j,k,r,l;
	char string[11];
	char string1[12];
	scanf("%s", string);
	for (i = 0; i <= strlen(string); i++){
		for (j = 0; j <= 25; j++){
			string1[i] = 'a' + j;
			l = 0;
			for (k = 0; k < strlen(string)+1; k++){
				if (i != k){
					string1[k] = string[l];
					l++;
				}
			}
			flag = palindrome(string1, strlen(string));
			if (flag){
				break;
			}
			}
		if (flag){
			break;
		}
		}
	if (flag){
		for (r = 0; r < strlen(string) + 1; r++){
			printf("%c", string1[r]);
		}
	}
	else
	printf("NA");
	return 0;
}
int palindrome(char checkstring[12], int length){
	int count = 0, i;
	for (i = 0; i < (length+1) / 2; i++){
		if (checkstring[i] == checkstring[length - i])
			count++;
	}
	if (count == (length + 1) / 2)
		return 1;
	else
		return 0;
}

#include<stdio.h>
#include<string.h>
int check(char str[])
{
    int a, i;
    a=strlen(str);
    for(i=0;i<(a/2);i++){
        if(str[i]!=str[a-i-1]){
            return 0;
        }
    }
    return 1;
}

int main()
{
    int i, j, k, a, b, c;
    char st[11], temp[12], ch;
    scanf("%s", st);
    a=strlen(st);
    k=check(st);
    if(k==1){
        if(a%2==0){
            for(i=0;i<a/2;i++){
                printf("%c", st[i]);
            }
            printf("a");
            for(;st[i];i++){
                printf("%c", st[i]);
            }
        }
        else{
            for(i=0;i<(a/2);i++){
                printf("%c", st[i]);
            }
            printf("%c%c", st[i], st[i]);
            i++;
            for(;st[i];i++){
                printf("%c", st[i]);
            }
        }
    }
    else if(k==0){
        for(i=0;i<=a;i++){
            for(j=0;j<26;j++){
                temp[i]=j+'a';
                for(k=0,c=0;k<=a;k++){
                    if(k==i) continue;
                    else {
                        temp[k]=st[c];
                        c++;
                    }
                }
                temp[k]='\0';
                c=check(temp);
                if(c==1){
                    puts(temp);
                    return 0;
                }

            }
        }
        printf("NA");
    }

    return 0;
}

#include<stdio.h>
#include<string.h>
int main() {
            char a[20],s[20];
            scanf("%s",a);
            int len=strlen(a),i,j,k;
            for(i=0;i<=len;i++)
            {
                strcpy(s,a);
                s[len+1]='\0';
                for(j=len;j>i;j--)
                    s[j]=s[j-1];
                for(j=0;j<26;j++)
                {
                    s[i]=(char)(j+(int)'a');
                    for(k=0;k<(len+1)/2 && s[k]==s[len-k];k++);
                    if(k==(len+1)/2) {printf("%s",s);return 0;}
                }
            }
            printf("NA");

    return 0;
}

#include<stdio.h>
#include<string.h>
int i,j;
int palin(char str[])
{
    i=0,j;
    j=strlen(str)-1;
    while(j>i)
    {
        if(str[i]!=str[j])
        {
            return 0;
        }

            i++;
            j--;

    }
    return 1;
}
int main()
{
    char str[11],str1[50];
    scanf("%s",str);
    int l=strlen(str),k,k1,i1,j1;
    if(palin(str))
    {

            for(k=0;k<=l/2;k++)
            {
                printf("%c",str[k]);
            }
            printf("%c",str[l/2]);
            for(k=l/2+1;k<l;k++)
            {
                printf("%c",str[k]);
            }

    }
    else
    {
        k1=0;
        for(k=0;k<=j;k++)
        {
            str1[k1]=str[k];
            k1++;
        }
        str1[k1]=str[i];
        k1++;
        for(k=j+1;k<l;k++)
        {
            str1[k1]=str[k];
            k1++;
        }
        str1[k1]='\0';
        i1=i;
        j1=j;
        //printf("%s",str1);
        if(palin(str1))
        {
            printf("%s",str1);
            return 0;
        }

                k1=0;
            for(k=0;k<i1;k++)
            {
                str1[k1]=str[k];
                k1++;
            }
            str1[k1]=str[j1];
            k1++;
            for(k=i1;k<l;k++)
            {
                str1[k1]=str[k];
                k1++;
            }
            str1[k1]='\0';
                if(palin(str1))
        printf("%s",str1);
        else
         printf("NA");
   }

    return 0;
}

#include <stdio.h>
#include <string.h>
int main () {
    char a[100],b[100],temp[100];
    scanf("%s",a);
    strcpy(temp,a);
    int i,j,k;
    char test[27]="abcdefghijklmnopqrstuvwxyz";
    for (i=0;i<strlen(test);i++){
        //strcpy(a,temp);
        for (j=0;j<strlen(a)+1;j++){
            for (k=j+1;k<strlen(a)+2;k++){
                a[k]=temp[k-1];
            }

            a[j]=test[i];
            //check
            char rev[100];
            strcpy(rev,a);
            strrev(rev);

            if (strcmp(a,rev)==0){
                printf("%s",rev);

                return 0;
            }
            //reset if not found
            strcpy(a,temp);

        }

    }

    printf("NA");

    return 0;
}

#include <stdio.h>
#include <string.h>
int check(char A[]){
int a,i;
	a=strlen(A);
	for(i=0;i<a/2+1;i++){
		if(A[i]!=A[a-i-1]){
			return 1;
		}
	}
	return 2;
}
int main(){
	int i,j,k;
	char Arr[11];
	scanf("%s",Arr);
	//printf("%s",Arr);
	//printf("%d\n",check(Arr));
	if(check(Arr)==2){
	i=strlen(Arr);
	if(i==1){
		printf("%c%c\n",Arr[0],Arr[0]);
		return 0;
	}
	else if(i%2==0){
	for(j=0;j<i;j++){
		if(j==i/2){
			printf("a");
			printf("%c",Arr[j]);
		}
		else{
			printf("%c",Arr[j]);
		}
	}
		printf("\n");
		return 0;
	}
	}
	int l;
	l=strlen(Arr);
	char B[12];
	int bet;
	bet=0;
	k=0;
	for(bet=0;bet<=l;bet++){

	for(k=0;k<l;k++){
		for(i=0;i<=11;i++){
			B[i]='\0';
		}

		j=0;
		for(i=0;i<=l;i++){
	if(i==bet){
		B[bet]=Arr[k];
	}
	else
		B[i]=Arr[j++];
	}
	//printf("B = %s\n",B);
	if(check(B)==2){
		printf("%s\n",B);
		return 0;
	}
	}
	}
	printf("NA\n");

	return 0;
}

#include<stdio.h>
#include<string.h>
int main()
{
	int len,i,j,index1=-1,index2=-1,p,flag1=0,flag=0;
	char str[14];
	scanf("%s",str);
	len=strlen(str);
	i=0;
	j=len-1;
	while(i<j)
	{
		if(str[i]!=str[j])
		{
			index1=i;
			index2=j;
			break;
		}
		else
		{
			i++;
			j--;
		}
	}
	if(index1==-1 && index2==-1 && len%2==0)
	{
		p=len/2;
		for(i=0;i<=(len/2)-1;i++)
		{
			printf("%c",str[i]);
		}
		printf("a");
		for(i=len/2;i<len;i++)
		{
			printf("%c",str[i]);
		}
		printf("\n");
	}
	else if(index1==-1 && index2==-1 && len%2!=0)
	{
		p=len/2;
		for(i=0;i<len/2;i++)
		{
			printf("%c",str[i]);
		}
		printf("%c",str[p]);
		for(i=(len/2);i<len;i++)
		{
			printf("%c",str[i]);
		}
		printf("\n");
	}
	else
	{
		i=index1;
		j=index2-1;
		while(i<j)
		{
			if(str[i]!=str[j])
			{
				flag=1;
				break;
			}
			i++;
			j--;
		}
		if(flag!=1)
		{
			for(i=0;i<index1;i++)
			{
				printf("%c",str[i]);
			}
			printf("%c",str[index2]);
			for(i=index1;i<len;i++)
			{
				printf("%c",str[i]);
			}
			printf("\n");
		}
		else
		{
			i=index1+1;
			j=index2;
			while(i<j)
			{
				if(str[i]!=str[j])
				{
					flag1=1;
					break;
				}
				i++;
				j--;
			}
			if(flag1!=1)
			{
				for(i=0;i<=index2;i++)
				{
					printf("%c",str[i]);
				}
				printf("%c",str[index1]);
				for(i=(index2+1);i<len;i++)
				{
					printf("%c",str[i]);
				}
				printf("\n");
			}
			else
				printf("NA\n");
		}
	}

	return 0;
}

#include<stdio.h>
#include<string.h>
#include<limits.h>
#include<math.h>
#include<stdlib.h>
int compare (const void * a, const void * b)
{
  return ( *(int*)a - *(int*)b );
}
void in(char str[],char str2[],int pos,int ch,int len)
{
    int i;
    for(i=len-1;i>=pos;i--)
    str2[i+1]=str[i];
    for(i=0;i<pos;i++)
    str2[i]=str[i];
    str2[pos]=ch;
    str2[len+1]='\0';
}
int ispalin(char str[],int len)
{
    int s=0,flag=1;
    int e=len-1;
    while(s<e)
    {
        if(str[s]!=str[e])
        {
            return 0;
        }
        s++;
        e--;
    }
    return 1;
}
int main()
{
    int n,i,s,e,flag,len,j;
    char str[100],str2[100];
    scanf("%s",str);
    len=strlen(str);
    s=0;
    e=len-1;
    flag=0;
    for(i=0;i<=len;i++)
    {
        for(j='a';j<='z';j++)
        {
            in(str,str2,i,j,len);
            if(ispalin(str2,len+1))
            {
                printf("%s",str2);
                flag=1;
                break;
            }
        }
        if(flag)
        break;
    }
    //printf("%d ",flag);
    if(flag==0)
    printf("NA");
    return 0;
}

int isPalindrome(char x[20])
{

    int j = strlen(x);
    for(int i = 0; i <= j/2; i++)
        if(x[i] != x[j-i-1])
            return 0;
    return 1;
}

int main()
{
    char x[20],y[20];
    int c = 0;
    scanf("%s",x);

    int len = strlen(x);
    for(int i = 0; i<= 25 && c!=1; i++){
        memset(y, '\0', sizeof(y));
        for(int j = 0; j <= len; j++) {
            for (int k = 0,l = 0; k <= len; k++)
             {
                if (k == j)
                   {
                    y[k] = (char) (i + 97);
                }
                   else y[k] = x[l++];
            }
            y[len+1] = '\0';
            //printf("%s\n",y);
            c = isPalindrome(y);
            if (c)
                break;
        }
    }

  if(c)
        printf("%s\n",y);
    else
    {
      printf("NA\n");
    }

    return 0;
}

#include <stdio.h>
#include <string.h>

int is_palin(char s[])
{
	int i = 0;
	int j = strlen(s) - 1;
	while (i < j) {
		if (s[i] != s[j])
			return 0;
		++i;
		--j;
	}
	return 1;
}

int main(void)
{
	//printf("Is eee %d\n", is_palin("eee"));
	char s[109];
	scanf("%s", s);
	int len = strlen(s);
	int flag = 0;
	int i, j, k;
	char temp[109];
	int key;
	for (i = 0; i < len+1; ++i) {
		strcpy(temp, s);
		for (k = i; k < len; ++k) {
				temp[k+1] = s[k];
		}
		temp[k+1] = '\0';
		for (j = 0; j < 26; ++j) {
			key = j + 'a';
			temp[i] = key;
			//printf("%s\n", temp);
			if (is_palin(temp) == 1) {
				printf("%s\n", temp);
				flag = 1;
				break;
			}
		}
		if (flag == 1) {
			break;
		}
	}
	if (flag == 0) {
		printf("NA\n");
	}
	return 0;
}

#include <stdio.h>
#include <strings.h>

int main()
{
    int counter = 0 , no = 0 , index , index1 , flag = 0 , counter1 = 0 , l ,s = 0;
    char str[11];
    scanf("%s",str);
    if (strlen(str) %2 != 0)
    {
        l = strlen(str)/2 + 1;
    }
    else
    {
        l = strlen(str)/2;
    }

    while ( counter < l && flag == 0 && counter1 <l)
    {
        if (str[counter] != str[strlen(str) - counter1-1])
        {
            if (str[counter+1] == str[strlen(str) - counter1-1] && str[counter] == str[strlen(str) - counter1 -2] && strlen(str) > 2)
            {
                if (str[counter+1] == str[strlen(str) - counter1-3] && s ==0 )
                {
                    index1 = strlen(str) - counter1-1;
                    index = counter;
                    no++;
                    counter1++;
                    s = 1;
                }
                else if (str[counter+2] == str[strlen(str) - counter1 -2]&& s== 0)
                {
                    index1 = counter;
                    index = strlen(str) - counter1;
                    no++;
                    counter++;
                    s= 1;
                }
                else
                {
                    flag = 1;
                }
            }

            else  if (str[counter+1] == str[strlen(str) - counter1-1])
            {
                index = strlen(str) - counter1;
                index1 = counter;
                no++;
                counter++;
            }
            else if (str[counter] == str[strlen(str) - counter1 -2])
            {
                index = counter;
                index1 = strlen(str) - counter1-1;
                no++;
                counter1++;
            }
            else
            {
                flag = 1;
            }
        }
        else
        {
            counter++;
            counter1++;
        }
    }
    counter = 0;
    counter1 = 0;
    if (flag ==0 || no > 1)
    {
        while( counter <= strlen(str) && counter1 <= strlen(str))
        {
            if (no == 0)
            {
                if (counter1 == strlen(str)/2)
                {
                    printf("%c",str[counter1]);
                    counter1++;
                }
                else
                {
                    printf("%c",str[counter]);
                    counter++;
                    counter1++;
                }
            }
            else
            {
                if (counter1 == index)
                {
                    printf("%c",str[index1]);
                    counter1++;
                }
                else
                {
                    printf("%c",str[counter]);
                    counter1++;
                    counter++;
                }
            }
        }
    }
    else
    {
        printf("NA");
    }

    return 0;
}

#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#include<string.h>
#include<time.h>
#include<ctype.h>
#include<limits.h>
#define eps 1e-7
#define ll long long int
#define N 500500
char arr[N];
int check(int n,char cmpt[]){
   for(int w=0;w<n/2;w++){
      if(cmpt[w]!=cmpt[n-w-1])
      return 0;
   }
   return 1;
}
int main(){
   int a,b,c;
   gets(arr);
   int len=strlen(arr);
   for(int w='a';w<='z';w++){
      char new_arr[50];
      for(int i=0;i<=len;i++){
         memset(new_arr,0,sizeof(new_arr));int k=0;
         new_arr[i]=w;
         for(int m=0;m<len;m++){
            if(k==i)
            k++;
            new_arr[k++]=arr[m];
         }
         if(check(strlen(new_arr),new_arr)){
            puts(new_arr);
            return 0;
         }
      }
   }
   printf("NA");
}

#include <stdio.h>
#include<string.h>
int main()
{
    int l,r,i,f=1,pos,fl; char s[20],c; scanf("%s",s); l=0; r=strlen(s)-1;
    while(l<=r)
    {
        if(s[l]==s[r])
        {
            l++; r--; continue;
        }
        if(s[l]!=s[r])
        {
            f=0;
             fl=1;
            pos=r+1;
            c=s[l]; int right,left=l+1; right=r;
            while(left<=right)
            {
                if(s[left]!=s[right])
                {fl=0; break;}
                left++; right--;
            }
            if(fl==0)
            {

                pos=l;

                c=s[r]; fl=1; left=l; right=r-1;
                while(left<=right)
                {
                    if(s[left]!=s[right])
                {fl=0; break;}
                left++; right--;
                }
            }

            break;
        }
    }
    if(fl==0 && f==0) {printf("NA"); return 0;}
    if(f==1)
    {
        pos=strlen(s)/2; c=s[pos];
    }
    int len=strlen(s)+1; i=0; f=0;
    while(len--)
    {
        if(i!=pos || f==1)
        printf("%c",s[i++]);
        else
        {printf("%c",c); f=1;}
    }
    return 0;
}

#include<stdio.h>
#include<string.h>

char Check(char s[]);

int main ()
{
	char str[15]={0};
	char a=0,b=0,c=0,p=0,F=0,tmp=0;
	char length=0;
	str[0]=1;
	scanf("%s",str+1);
	length=strlen(str);

	for(p=0;p<length;p++)
	{
		for(a='a';a<='z';a++)
		{
			str[p]=a;
			F=Check(str);
			if(F==1)
			{
				puts(str);
				return 0;
			}
			else
				continue;
		}
		tmp=str[p];
		str[p]=str[p+1];
		str[p+1]=tmp;
	}
	printf("NA\n");
	return 0;

}

char Check(char s[])
{
	char len=0,flag=0,i=0,last=0;
	len=strlen(s);
	last=len/2;

	for(i=0;i<last;i++)
	{
		if(s[i]==s[len-1-i])
			continue;
		else
		{
//			printf("NO!\n");
			return 0;
		}
	}
//	printf("YES!\n");
	return 1;
}

#include<stdio.h>
#include<string.h>

int check(char arr[], int l, int h)
{

    while(l<=h)
    {
        if (arr[l]!=arr[h])
            return 0;
        l++;
        h--;
    }

    return 1;
}

void print(char arr[], int low, int high)
{
    int i=0;
    for(i=low;i<=high;i++)
        printf("%c",arr[i]);
    return;
}

int main()
{
    char s[12];
    scanf("%s",s);

    int len=strlen(s);

    if (len==1)
        printf("%s%s\n",s ,s);
    else if (len==2)
        printf("%s%c\n",s ,s[0]);
    else if (check(s,0,len-1))
    {
        if (len%2==0)
        {
            print(s,0,len/2-1);
            printf("u");
            print(s,len/2,len-1);
            printf("\n");
        }
        else
        {
            print(s,0,len/2);
            //printf("%c",s[len/2]);
            print(s,len/2,len-1);
            printf("\n");
        }
    }
    else
    {
        int i;
        for(i=0;i<len/2;i++)
        {
            if (s[i]!=s[len-1-i])
            {
                if (check(s,i,len-1-i-1))
                {
                    print(s,0,i-1);
                    printf("%c",s[len-1-i]);
                    print(s,i,len-1);
                    printf("\n");
                    break;
                }
                else if (check(s,i+1,len-1-i))
                {
                    print(s,0,len-1-i);
                    printf("%c",s[i]);
                    print(s,len-i,len-1);
                    printf("\n");
                    break;
                }
                else
                    i=len/2-1;
            }

        }
        if (i==(len/2))
            printf("NA\n");
    }

    return 0;
}

#include<stdio.h>
#include<string.h>
int main()
{
	long long int i,j,k,len,count=0,flag1=0,flag=0,flag21=0,p,q;
	char s[1000000],letter;
	scanf("%s", s);
	len=strlen(s);
	i=0;
	for(i=0;i<len/2;i++)
	{
		if(flag21==0)
		{
		p=len-i-1;
		q=i;
		}
		else if(flag21==1)
		{
			p=len-i-1;
			q=i+1;
		}
		else if(flag21==2)
		{
			p=len-i-2;
			q=i;
		}
//		printf("%lld %lld\n", q,p);
//		printf("%c %c %lld\n", s[q], s[p],i);
		if(s[q]!=s[p])
		{
			count++;
			flag=1;
		}
		if(flag==1)
		{
			if(s[i+1]==s[len-i-1])
			{
			//	printf("-1\n");
				j=len-i;
				flag=-1;
				letter=s[i];
				q=i+1;
				flag21=1;

			}
			else if(s[i]==s[len-i-2])
			{
			//	printf("-2\n");
				j=i;
				letter=s[len-i-1];
				flag=-2;
				p=p-1;
				flag21=2;
			}
			else
			{
				flag1=3;
				break;
			}
		}

	}
//	printf("%lld\n", count);
	if(count==1 && flag==-1)
	{
		for(k=0;k<j;k++)
		{
			printf("%c", s[k]);
		}
		printf("%c", letter);
		for(k=j;k<len;k++)
		{
			printf("%c", s[k]);
		}
		printf("\n");
	}
	else if(count==1 && flag==-2)
	{
		for(k=0;k<j;k++)
		{
			printf("%c", s[k]);
		}
		printf("%c", letter);
		for(k=j;k<len;k++)
		{
			printf("%c", s[k]);
		}
		printf("\n");
	}
	else if(count==0)
	{
		if(len%2!=0)
		{
			for(k=0;k<=len/2;k++)
			{
				printf("%c", s[k]);
			}
			printf("%c", s[len/2]);
			for(k=len/2+1;k<len;k++)
			{
				printf("%c", s[k]);
			}
			printf("\n");
		}
		else
		{
			for(k=0;k<len/2;k++)
			{
				printf("%c", s[k]);
			}
			printf("c");
			for(k=len/2;k<len;k++)
			{
				printf("%c", s[k]);
			}
			printf("\n");
		}
	}
	else if(flag1==3)
	{
		printf("NA\n");
	}
	else if(count>1)
	{
		printf("NA\n");
	}
	return 0;
}

#include <stdio.h>

int main(int argc, char const *argv[])
{
    char str[11], letter;
    scanf("%s", str);
    int diff = 0, pos, len, i, j;
    for (len = 0; str[len] != 0 && len < 11; len++);
        // printf("%d\n", len);
    for (j = 0, i = len - 1; j < i; j++, i--) {
        if (str[j] != str[i]) {
            // printf("wjat?\n");
            diff++;
            if (diff == 1) {
                pos = i + 1;
                letter = str[j];
            }
            i++;
        }

    }
    if (diff == 0) {
        letter = str[len / 2];
        pos = len / 2;
    }
    // printf("%c %d %d\n", letter, pos, diff);

    if (diff > 1) {
        // printf("NA\n");
    } else {
        // printf("%d\n", len);
        for (i = 0, j = 0; i < len + 1; i++){
            if (i == pos) {
                printf("%c", letter);
            } else {
                printf("%c", str[j++]);
            }
        }
    }

    return 0;
}

#include<stdlib.h>
#include<string.h>
#include<stdio.h>
#include<math.h>

#define FOR(i,a,b)  for(i = a; i <= b; i++)
#define ROF(i,a,b)  for(i = a; i >= b; i--)

int i,j,s,u,u2,sit,sit2,t,t2;
char str[10000], ans[10000];

int main()
{
    scanf("%s", str);
    u = strlen(str);
    if(u == 1)
        printf("%s%s",str, str);
    else {
        FOR(i,0,u/2-1){
            if(str[i] != str[u - 1 - i])
            {
                ROF(j,u,u-i+1){
                    str[j] = str[j - 1];
                }
                str[u - i] = str[i];
                sit = 1;
                break;
            }
        }
        strcpy(ans,str);
        u = strlen(ans);
        FOR(i,0,u/2-1)
        {
            if(ans[i] != ans[u - i - 1])
                sit2 = 1;
        }
        if(sit2 == 0 && sit == 1)
            printf("%s", ans);
        else if(sit2 == 0 && sit == 0)
        {
            FOR(j,0,u-1){
                if(j == u / 2 - 1)
                    printf("%c%c",ans[j],ans[j + 1]);
                else
                    printf("%c", ans[j]);
            }
        }
        else
            printf("NA");
    }
    return 0;
}

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main()
{
    char s[11], backup[11];
    gets(s);
    strcpy(backup,s);
    int len = strlen(s), i = 0, j = 0, chosen = 0;
    for(i = 0; i < len-1; i++)
    {
        for(j = i; j < len-1; j++)
            s[j] = s[j+1];
        s[len-1] = '\0';
        chosen = i;
        int found = 1, auxlen = strlen(s);
        for(j = 0; j < auxlen/2; j++)
            if(s[j] != s[auxlen-j-1])
            {
                found = 0;
                break;
            }
        strcpy( s,backup);
        if(found == 1)
        {
            for(j = 0; j < len-chosen; j++)
                printf("%c", s[j]);
            printf("%c", s[chosen]);
            for(j = len-chosen; j < len; j++)
                printf("%c", s[j]);
            exit(0);
        }
    }
    printf("NA");
}

#include <stdlib.h>
#include <stdio.h>
#include <string.h>

int isPalindrome(char* str)
{
    int i = 0, j = strlen(str) - 1;
    while(i<j)
    {
        if (str[i] != str[j])
            return 0;
        i++;
        j--;
    }
    return 1;
}

void addchar(char* str, char c, int pos)
{
    int i = strlen(str)+1;
    while (i > pos)
    {
        str[i] = str[i-1];
        i--;
    }
    str[pos] = c;
}

int bruteforce_solve(char* str)
{
    int i, j, len = strlen(str);
    char aux[12];
    for (i=0; i < len; i++)
    {
        for (j = 0; j < len; j++)
        {
            strcpy(aux, str);
            addchar(aux, str[i], j);
            if (isPalindrome(aux))
            {
                strcpy(str, aux);
                return 1;
            }
        }
    }
    return 0;
}

int main()
{
    char str[12];
    scanf("%s", str);
    if(bruteforce_solve(str))
        printf("%s\n", str);
    else
        printf("NA\n");
    return 0;
}

#include<stdio.h>
#include<stdio.h>
#include<string.h>
#include<ctype.h>

char *insere(char ch[10],char c,int x)
{
    int i,n;
    n=strlen(ch);
   for(i=strlen(ch);i>x;i--)
    ch[i]=ch[i-1];
   ch[n+1]='\0';
   ch[x]=c;

    return(ch);
}
int palaindrom(char ch[])
{
    int i;
    for (i=0;i<(strlen(ch)/2);i++)
    {
        if (ch[i]!=ch[strlen(ch)-1-i])
            return 0;
    }
    return 1;
}

int main ()
{
    char ch[11],ch2[11],ch3[11],ch4[11];
    int i;
    scanf("%s",ch);
    strcpy(ch2,ch);

   if (palaindrom(ch)==1)
       {
        if ((strlen(ch)%2)==0)
    {printf("%s",insere(ch,'i',(strlen(ch)/2)));
    return 0;
    }

    else
            {printf("%s",insere(ch,ch[strlen(ch)/2],(strlen(ch)/2)));
return 0;            }
        }
    else
       {
        for (i=0;i<(strlen(ch)/2);i++)
        if (ch[i]!=ch[strlen(ch)-i-1])
        {

strcpy(ch3,insere(ch,ch[i],strlen(ch)-i));
strcpy(ch4,insere(ch2,ch2[strlen(ch2)-1-i],i));

                        if (palaindrom(ch3)==1)
                           {
                               printf("%s",ch3);
                               return 0;}

                        else if
                           ( palaindrom(ch4)==1)
                          {
                              printf("%s",ch4);
                              return 0;
                          }
                        else printf("NA");
                        return 0;

        }
    }

    return 0;
}

#include <stdio.h>
#include <strings.h>

int main()
{
    int counter = 0 , no = 0 , index , index1 , flag = 0 , counter1 = 0;
    char str[11];
    scanf("%s",str);

        while ( counter < (strlen(str)/2) && flag == 0 && counter1 < strlen(str)/2)
        {
            if (str[counter] != str[strlen(str) - counter1-1])
            {

                if (str[counter+1] == str[strlen(str) - counter1-1])
                {
                    index = strlen(str) - counter1;
                    index1 = counter;
                    no++;
                    counter++;
                }
               else if (str[counter] == str[strlen(str) - counter1 -2])
                {
                    index = counter;
                    index1 = strlen(str) - counter1-1;
                    no++;
                    counter1++;
                }
                else
                {
                    flag = 1;
                }
            }
            else
            {
                counter++;
                counter1++;
            }
        }
        counter = 0;
        counter1 = 0;
        if (flag ==0 || no > 1)
        {
            while( counter <= strlen(str) && counter1 <= strlen(str))
            {
                if (no == 0)
                {
                    if (counter1 == strlen(str)/2)
                    {
                        printf("%c",str[counter1]);
                        counter1++;
                    }
                    else
                    {
                        printf("%c",str[counter]);
                        counter++;
                        counter1++;
                    }
                }
                else
                {
                    if (counter1 == index)
                    {
                        printf("%c",str[index1]);
                        counter1++;
                    }
                    else
                    {
                        printf("%c",str[counter]);
                        counter1++;
                        counter++;
                    }
                }
            }
        }
        else
        {
            printf("NA");
        }

    return 0;
}

#include<stdio.h>
#include<string.h>
int is_palindrome(char s[],int len)
{
        int i;
        for(i=0;i<len/2;i++)
                if(s[i]!=s[len-i-1])
                        return -1;
        return 1;
}
int main()
{
        char s[11],a[12];
        scanf("%s",s);
        int i,j;
        int len=strlen(s);
        //printf("%d\n",len);
        //printf("%d\n",is_palindrome(s,len));
        //printf("%s\n",s);
        int flag=0;
        for(i=0;i<len+1;i++)
        {
                for(j=0;j<i;j++)
                        a[j]=s[j];
                if(len-i-1>=0)

                {
                        if(len%2==0)
                        a[j]=s[len-i];
                        else
                                a[j]=s[len-1-i];
                }
                else
                        a[i]=s[0];
                for(j=j+1;j<len+1;j++)
                        a[j]=s[j-1];
                a[j]='\0';
                //printf("%s\n",a);
                if(is_palindrome(a,len+1)==1)
                {
                        flag=1;
                        printf("%s\n",a);
                        break;
                }
        }
        if(flag==0)
                printf("NA\n");
        return 0;
}

/* Problem: 505A - Mr. Kitayuta's Gift */
/* Solver: Gusztav Szmolik */

#include <stdio.h>
#include <string.h>
#include <ctype.h>

unsigned short ispal (unsigned char*, unsigned short, unsigned char, unsigned char*);

int main ()
    {
    unsigned char s[12];
    unsigned short ls;
    unsigned short i;
    unsigned short h[26];
    unsigned short oc;
    unsigned short j;
    unsigned short p;
    unsigned short pa;
    unsigned char t[12];

    if (scanf("%11s",s) != 1)
        return -1;
    ls = strlen (s);
    if (ls > 10)
        return -1;
    for (i = 0; i < 26; i++)
        h[i] = 0;
    oc = 0;
    for (i = 0; i < ls; i++)
        {
        if (!islower(s[i]))
            return -1;
        j = s[i]-'a';
        h[j]++;
        if (h[j]%2)
            oc++;
        else
            oc--;
        }
    p = ls%2;
    pa = 0;
    if (!p && !oc)
        {
        for (i = 0; i < 26; i++)
            if (h[i] && ispal(s,ls,i+'a',t))
                {
                printf ("%s\n",t);
                pa = 1;
                }
        }
    else if ((!p && oc == 2) || (p && oc == 1))
        {
        for (i = 0; i < 26; i++)
            if (h[i]%2 && ispal(s,ls,i+'a',t))
                {
                printf ("%s\n",t);
                pa = 1;
                }
        }
    if (!pa)
        printf ("NA\n");
    return 0;
    }

unsigned short ispal (s,ls,c,t)
    unsigned char* s;
    unsigned short ls;
    unsigned char c;
    unsigned char* t;
    {
    unsigned short pa;
    unsigned short i;
    unsigned short j;
    unsigned short b;
    unsigned short e;

    pa = 0;
    for (i = 0; i <= ls && !pa; i++)
        {
        strcpy (t,s);
        t[ls+1] = '\0';
        for (j = ls; j > i; j--)
            t[j] = s[j-1];
        t[i] = c;
        b = 0;
        e = ls;
        pa = 1;
        while (b <= e)
            {
            if (t[b] != t[e] && pa)
                pa = 0;
            b++;
            e--;
            }
        }
    return pa;
    }

#include <stdio.h>
#include<string.h>
int main(void) {
    int i,j,num,flag;
    char a, s[12];
    scanf("%s",&s);
    i=0;
    j=strlen(s)-1;
    flag=0;
    while(i<j)
    {
        if(s[i]==s[j])
        {
            i++;j--;
        }
        else if(s[i]==s[j-1]&&i<j-1&&s[i+1]==s[j-2])
        {
            if(flag==1)
             {
                flag==2;
                 break;
             }
            flag=1;
          num=i;

          a=s[j];
            j--;
        }
        else if(s[i+1]==s[j]&&i+1<j&&s[i+2]==s[j-1])
        {
            if(flag==1)
             {
                flag==2;
                 break;
             }
            flag=1;
            num=j+1;
            a=s[i];
            i++;
        }
        else if(s[i]!=s[j]&&i+1==j)
        {
            flag=1;
            num=j+1;
            a=s[i];
            i++;j--;
        }
        else
        {
           flag=2;
          break;
        }
    }
    if(flag==0)
    {
        if(strlen(s)%2==0)
        {
            a='a';
            num=strlen(s)/2;
        }
        else
        {
               num=strlen(s)/2;
               a=s[num];
        }
           for(i=0;i<strlen(s);i++)
           {
            if(num==i)
              printf("%c",a);
            printf("%c",s[i]);
            }
          if(num==i)
           printf("%c",a);
            printf("\n");

    }
    if(flag==1)
    {

        for(i=0;i<strlen(s);i++)
        {
            if(num==i)
              printf("%c",a);
            printf("%c",s[i]);
        }
        if(num==i)
          printf("%c",a);
        printf("\n");

    }
    if(flag==2)
    {
        printf("NA\n");
    }
    return 0;
}

#include<stdio.h>
#include<string.h>

char Check(char s[]);
int main ()
{
	char str[15]={0};
	char a=0,b=0,c=0,p=0,F=0,tmp=0;
	char length=0;
	str[0]=1;
	scanf("%s",str+1);
	length=strlen(str);

	for(p=0;p<length;p++)
	{
		for(a='a';a<'z';a++)
		{
			str[p]=a;
			F=Check(str);
			if(F==1)
			{
				puts(str);
				return 0;
			}
			else
				continue;
		}
		tmp=str[p];
		str[p]=str[p+1];
		str[p+1]=tmp;
	}
	printf("NA\n");
	return 0;

}

char Check(char s[])
{
	char len=0,flag=0,i=0,last=0;
	len=strlen(s);
	last=len/2;

	for(i=0;i<last;i++)
	{
		if(s[i]==s[len-1-i])
			continue;
		else
		{
//			printf("NO!\n");
			return 0;
		}
	}
//	printf("YES!\n");
	return 1;
}

#include <stdlib.h>
#include <stdio.h>
#include <string.h>

int isPalindrome(char* str)
{
    int i = 0, j = strlen(str) - 1;
    while(i<j)
    {
        if (str[i] != str[j])
            return 0;
        i++;
        j--;
    }
    return 1;
}

void addchar(char* str, char c, int pos)
{
    int i = strlen(str)+1;
    while (i > pos)
    {
        str[i] = str[i-1];
        i--;
    }
    str[pos] = c;
}

int main()
{
    int len;
    int i, j;
    char str[12];
    char aux[12];
    scanf("%s", str);
    len = strlen(str);

    if (isPalindrome(str) && len%2 == 0)
    {
        addchar(str, 'r', len/2);
        printf("%s\n", str);
        return 0;
    }
    if (isPalindrome(str))
    {
        printf("NA\n");
        return 0;
    }

    if (len & 1)
    {
        i = len/2;
        j = len/2 + 1;
    }
    else
    {
        i = j = len/2;
    }

    while (str[i] == str[j])
    {
        i--;
        j++;
    }
    strcpy(aux, str);
    addchar(str, str[i], j);
    if (isPalindrome(str))
        printf("%s\n", str);
    else
    {
        addchar(aux, aux[j], i);
        if(isPalindrome(aux))
            printf("%s\n", aux);
        else
            printf("NA\n");
    }
    return 0;
}

#include<stdio.h>
#include<string.h>
int tp(char s[],int n)
{
	int i,ans=0;
	for(i=0;i<n/2;i++)
	{
		if(s[i]!=s[n-i-1])
		{	ans=1;
			break;
		}
	}
	return ans;
}
int main()
{
	char s[11],s2[12];
	int i,j,k,l,state=1;
	scanf("%s",s);
	l=strlen(s);
	for(i=0;i<=l;i++)
	{
		for(k=0;k<=l;k++)
		{
			if(k<i)
				s2[k]=s[k];
			else if(k>i)
				s2[k]=s[k-1];
		}
		char c;
		for(j='a';j<='z';j++)
		{
			c=j;
			s2[i]=c;
			int ans;
			ans=tp(s2,l+1);
			if(ans==0)
			{	state=0;
				break;
			}
		}

		if(state==0)
			break;
	}
	if(state==0)
		printf("%s\n",s2);
	else
		printf("NA\n");
	return 0;
}

#include<stdio.h>
#include<string.h>
int is_pallindrome(char a[10000],int l)
{int i,j;
    for(i=0,j=l-1;i<l/2;++i,--j)
        if(a[i]==a[j])
            continue;
        else
            return 0;

    return 1;

}
int main()
{int try = -1;
    char a[100000];
    scanf("%s",a);
    int k;char b[100000];
    char c[100000];
    strcpy(b,a);
    strcpy(c,a);

    int l = strlen(a);
    int i,j;int flag1=-1,flag2=-1;
    for(i=l/2,j=l/2;i>=0;--i,++j)
    {if(a[i]==a[j])
        continue;
        else
        {flag1=i;flag2=j;
            if(a[i-1]==a[j])
            { for(k=l-1;k>=j;--k)
                c[k+1]=c[k];
                c[j]=c[i];
                if(is_pallindrome(c,l+1))
                {
                    printf("\n%s\n",c);
                  break;
                }
                else
                 try =0;

            }
            if(a[i]==a[j+1])
            {  for(k=l-1;k>=i;--k)
                b[k+1]=b[k];
                b[i-1]=b[j+1];

                if(is_pallindrome(b,l+1))
                {
                    printf("\n%s\n",b);
                 break;
                }
                else
                 {printf("\nNA\n");
                 break;}
            }//check shifting till i

        }

    }

    if(flag1==-1)
    {
        if(l%2==0)
        {printf("\n");
            {
            for(i=0;i<l/2;++i)
             printf("%c",a[i]);
         }
        printf("%c",a[l/2]);
        for(i;i<l;++i)
            printf("%c",a[i]);
        printf("\n");
        }
        if(l%2==1)
            printf("\nNA\n");
    }

    else
        printf("\nNA");

    return 0;
}

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main()
{
    char s[11];
    int l,i,j,test=1;
    scanf("%s",&s);
    l=strlen(s);
    i=0;
    char *s1=malloc((l)*sizeof(char));
    while((i<=(l/2))&& test)
    {
        if(s[i]!=s[l-i-1])
        {
            char *m=malloc((i+1)*sizeof(char));
            m[0]=s[i];
            memcpy(s1,s,l-i);
            for(j=l-i; j<l; j++)
            {
                m[j-(l-i)+1]=s[j];
            }
            strcat(s1,m);
            test=0;

        }
        i++;
    }
    if (test)
    {
        if(l%2==0)
        {
            memcpy(s1,s,l/2);
            char *k=malloc((l/2+1)*sizeof(char));
            k[0]=s[(l/2)-1];
            for(i=(l/2); i<l; i++)
            {
                k[i-((l/2))+1]=s[i];

            }
            strcat(s1,k);
        }
        else
        {
            memcpy(s1,s,l/2+1);
            char *k=malloc((l/2+1)*sizeof(char));
            k[0]=s[(l/2)];
            for(i=(l/2)+1; i<l; i++)
            {
                k[i-((l/2)+1)+1]=s[i];

            }
            strcat(s1,k);
        }

    }
    test=1;
    while((i<(l/2))&& test)
    {
        if(s1[i]!=s1[l-i]) test=0;
        i++;
    }

    if(test) printf("%s\n",s1);
    else printf("NA\n");

    return 0;
}

#include<stdio.h>
#include<string.h>
#include<limits.h>
#include<math.h>
#include<stdlib.h>
int compare (const void * a, const void * b)
{
  return ( *(int*)a - *(int*)b );
}
int main()
{
    int n,i,s,e,flag,len;
    char str[100];
    scanf("%s",str);
    len=strlen(str);
    s=0;
    e=len-1;
    flag=1;
    while(s<e)
    {
        if(str[s]!=str[e])
        {
            flag=0;
            break;
        }
        else
        {
            s++;
            e--;
        }
    }
    if(flag==0)
    {
        for(i=len-1;i>=e+1;i--)
        {
            str[i+1]==str[i];
        }
        str[len+1]='\0';
        str[e+1]=str[s];
        flag=1;
        s=0;
        e=len;
        while(s<e)
        {
            if(str[s]!=str[e])
            {
                flag=0;
            }
            s++;
            e--;
        }
        if(flag)
        printf("%s",str);
        else
        printf("NA");
    }
    else
    {
        for(i=0;i<=(len-1)/2;i++)
        printf("%c",str[i]);
        printf("%c",str[(len-1)/2]);
        for(i=(len-1)/2+1;i<len;i++)
        printf("%c",str[i]);
    }
    return 0;
}

#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#define MAX_SIZE 10

typedef unsigned char boolean;

char *createPalindromo(const char *str);
void fill(const char *origen, char *dest, unsigned int ban);
boolean isPalindromo(char *str);
int main()
{
   char palindromo[MAX_SIZE];
   scanf("%s",palindromo);
   char *result = createPalindromo(palindromo);
   printf("%s\n", result);

   return 0;
}

char *createPalindromo(const char *str)
{
    int len = strlen(str);
    int possiblePositions = len+1;
    int i;
    char *Palindromo = (char *) malloc(sizeof(char) * possiblePositions + 1);
    for(i = 0; i < possiblePositions ; i++)
    {
        fill(str,Palindromo,i);
        if(isPalindromo(Palindromo))
           return Palindromo;
    }
    return "NA";
}

void fill(const char *origen, char *dest, unsigned int ban)
{
    int i;
    int j;
    int len = strlen(origen)+1;

    for( i = j = 0; origen[j] != '\0'; i++)
        if(i != ban)
            dest[i] = origen[j++];

   dest[ban] = dest[len - 1 - ban];
   printf("%s \n",dest);
 }

boolean isPalindromo(char *str)
{
    int i;
    int j= strlen(str) - 1;

    for( i = 0; str[i] != '\0'; i++)
    {
        if(str[i] != str[j--])
            return 0;
    }
    return 1;
}

#include<stdio.h>
#include<string.h>

int is_pall(char* s,int len)
{
	int i;
	for(i=0;i<len/2;i++)if(s[i]!=s[len-i-1]) return 0;
	return 1;
}

int main()
{
	int i,j,len;
	char s[11],x[12];
	scanf("%s",s);
	len = strlen(s);
	for(i=0;i<len/2;i++)
	{
		if(s[i]!=s[len-i-1])break;
	}
	if(i==len/2)
	{
		for(j=0;j<len/2;j++)putchar(s[j]);
		putchar(s[j]);
		for(;j<len;j++)putchar(s[j]);
		return 0;
	}

	for(j=0;j<i;j++)x[j]=s[j];
	x[j]=s[len-i-1];
	for(;j<len;j++)x[j+1]=s[j];
	if(is_pall(x,len+1)){printf("%s",x);return 0;}

	for(j=0;j<=i;j++)x[j]=s[j];
	x[j]=s[len-i-1];
	for(;j<len;j++)x[j+1]=s[j];
	if(is_pall(x,len+1)){printf("%s",x);return 0;}

	for(j=0;j<len-i-1;j++)x[j]=s[j];
	x[j]=s[i];
	for(;j<len;j++)x[j+1]=s[j];
	if(is_pall(x,len+1)){printf("%s",x);return 0;}

	for(j=0;j<=len-i-1;j++)x[j]=s[j];
	x[j]=s[i];
	for(;j<len;j++)x[j+1]=s[j];
	if(is_pall(x,len+1)){printf("%s",x);return 0;}

	printf("NA");
	return 0;
}

#include<stdio.h>
int main()
{
  int i=0;
  char s[10];
  char c;
  while((c=getchar()) != '\n')
    {
      s[i]=c;
      i++;
    }
  //  printf("%s\n",s);
  int m;
  // printf("i is:%d\n",i);
  int j,k=i-1,counter=0,flag=0,breakingj,breakingk;
  for(j=0;j<=(i/2)-1;j++)
    {
    a:      if(s[j] == s[k])
	{
	  // printf("if loop %c %c %d %d\n",s[j],s[k],j,k);
	  counter++;
	  // printf("counter is:%d\n",counter);
	  k--;
	  continue;
	}
      else
	{
	  //  printf("else loop %c %c %d %d\n",s[j],s[k],j,k);
	  if(flag==0)
	    {
	      breakingj=j;
	      breakingk=k;
	    }
	  flag++;
	  break;
	}
    }
  if((counter <= (i/2)-1) && flag ==1)
    {
      // printf("came to first loop\n");
      k--;
      goto a;
    }
  else if((counter < (i/2)-1) && flag == 2)
    {
      // printf("came to second loop\n");
      k=breakingk;
      j=breakingj+1;
      goto a;
    }
  else if(counter == (i/2) && flag == 1)
    {
      // printf("came to third loop\n");
      for(j=0;j<breakingj;j++)
	printf("%c",s[j]);
      printf("%c",s[breakingk]);
      for(j=breakingj;j<i;j++)
	printf("%c",s[j]);
      printf("\n");
    }
  else if(counter == (i/2)-1 && flag == 2)
    {
      // printf("came to fourth loop\n");
      for(j=0;j<=breakingk;j++)
	printf("%c",s[j]);
      printf("%c",s[breakingj]);
       for(j=breakingk+1;j<i;j++)
	 printf("%c",s[j]);
      printf("\n");
    }
  else if(flag ==0 )
    {
      // printf("came to sixth loop\n");
      if (i%2 != 0)
	{
	  // printf("came to first part of sixth loop\n");
	  for(j=0;j<=i/2;j++)
	    printf("%c",s[j]);
	  printf("%c",s[j-1]);
	  for(j=(i/2)+1;j<i;j++)
	    printf("%c",s[j]);
	  printf("\n");
	}
      else
	{
	  //  printf("came to last loop\n");
	  for(j=0;j<i/2;j++)
	    printf("%c",s[j]);
	  printf("a");
	  for(j=i/2;j<i;j++)
	    printf("%c",s[j]);
	  printf("\n");
	}
    }
  if(flag >2)
    {
      printf("NA\n");
      return 0;
    }
  return 0;
}

#include<stdio.h>

int isPalindrome(char *s, int n)
{
	for(int i = 0; i < n; i++)
	{
		if(s[i] != s[n-1-i])	return 0;
	}

	return 1;
}

int main()
{
	char s[11];
	scanf(" %s", s);

	int l = 0;
	char ans[12];

	for(int i = 0; s[i] != '\0'; i++)	l++;

	int position = 0;
	char letter;

	for(int position = 0; position < l; position++)
	{
		letter = s[position];
		int k = 0;
		for(int i = 0; i < l-position; i++)	ans[k++] = s[i];
		ans[k++] = letter;
		for(int i = l-position; i < l; i++)	ans[k++] = s[i];
		ans[k] = '\0';

		if(isPalindrome(ans, l+1))
		{
			printf("%s\n", ans);
			return 0;
		}
	}

	printf("NA\n");
	return 0;
}

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main()
{
    char s[11];
    int l,i,j,test=1;
    scanf("%s",&s);
    l=strlen(s);
    i=0;
    char *s1=malloc((l)*sizeof(char));
    while((i<=(l/2))&& test)
    {
        if(s[i]!=s[l-i-1])
        {
            char *m=malloc((i+1)*sizeof(char));
            m[0]=s[i];
            memcpy(s1,s,l-i);
            for(j=l-i; j<l; j++)
            {
                m[j-(l-i)+1]=s[j];
            }
            strcat(s1,m);
            test=0;

        }
        i++;
    }
    if (test)
    {
        if(l%2==0)
        {
            memcpy(s1,s,l/2);
            char *k=malloc((l/2+1)*sizeof(char));
            k[0]=s[(l/2)-1];
            for(i=(l/2); i<l; i++)
            {
                k[i-((l/2))+1]=s[i];

            }
            strcat(s1,k);
        }
        else
        {
            memcpy(s1,s,l/2+1);
            char *k=malloc((l/2+1)*sizeof(char));
            k[0]=s[(l/2)];
            for(i=(l/2)+1; i<l; i++)
            {
                k[i-((l/2)+1)+1]=s[i];

            }
            strcat(s1,k);
        }

    }
    test=1;
    while((i<(l/2+1))&& test)
    {
        if(s1[i]!=s1[l-i]) test=0;
        i++;
    }

    if(test) printf("%s",s1);
    else printf("NA");

    return 0;
}

#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#define MAX_SIZE 10

typedef unsigned char boolean;

char *createPalindromo(const char *str);
void fill(const char *origen, char *dest, unsigned int ban);
boolean isPalindromo(char *str);
int main()
{
   char palindromo[MAX_SIZE];
   scanf("%s",palindromo);
   char *result = createPalindromo(palindromo);
   printf("%s\n", result);

   return 0;
}

char *createPalindromo(const char *str)
{
    int len = strlen(str);
    int possiblePositions = len+1;
    int i;
    char *Palindromo = (char *) malloc(sizeof(char) * possiblePositions + 1);
    for(i = 0; i < possiblePositions ; i++)
    {
        fill(str,Palindromo,i);
        if(isPalindromo(Palindromo))
           return Palindromo;
    }
    return str;

}

void fill(const char *origen, char *dest, unsigned int ban)
{
    int i;
    int j;
    int len = strlen(origen)+1;

    for( i = j = 0; origen[j] != '\0'; i++)
        if(i != ban)
            dest[i] = origen[j++];

   dest[ban] = dest[len - 1 - ban];
 }

boolean isPalindromo(char *str)
{
    int i;
    int j= strlen(str) - 1;

    for( i = 0; str[i] != '\0'; i++)
    {
        if(str[i] != str[j--])
            return 0;
    }
    return 1;
}

#include<stdio.h>
int main()
{
  int i=0;
  char s[10];
  char c;
  while((c=getchar()) != '\n')
    {
      s[i]=c;
      i++;
    }
  //printf("%s\n",s);
  int m;
  printf("i is:%d\n",i);
  int j,k=i-1,counter=0,flag=0,breakingj,breakingk;
  for(j=0;j<=(i/2)-1;j++)
    {
    a:      if(s[j] == s[k])
	{
	  // printf("if loop %c %c %d %d\n",s[j],s[k],j,k);
	  counter++;
	  // printf("counter is:%d\n",counter);
	  k--;
	  continue;
	}
      else
	{
	  // printf("else loop %c %c %d %d\n",s[j],s[k],j,k);
	  if(flag==0)
	    {
	      breakingj=j;
	      breakingk=k;
	    }
	  flag++;
	  break;
	}
    }
  if((counter <= (i/2)-1) && flag ==1)
    {
      //printf("came to first loop\n");
      k--;
      goto a;
    }
  else if((counter < (i/2)-1) && flag == 2)
    {
      //printf("came to second loop\n");
      k=breakingk;
      j=breakingj+1;
      goto a;
    }
  else if(counter == (i/2) && flag == 1)
    {
      // printf("came to third loop\n");
      for(j=0;j<breakingj;j++)
	printf("%c",s[j]);
      printf("%c",s[breakingk]);
      for(j=breakingj;j<i;j++)
	printf("%c",s[j]);
      printf("\n");
    }
  else if(counter == (i/2)-1 && flag == 2 && counter != 0)
    {
      //     printf("came to fourth loop\n");
      for(j=0;j<=breakingk;j++)
	printf("%c",s[j]);
      printf("%c",s[breakingj]);
       for(j=breakingk+1;j<i;j++)
	 printf("%c",s[j]);
      printf("\n");
    }
  else if(flag ==0 )
    {
      //printf("came to sixth loop\n");
      if (i%2 != 0)
	{
	  // printf("came to first part of sixth loop\n");
	  for(j=0;j<=i/2;j++)
	    printf("%c",s[j]);
	  printf("%c",s[j-1]);
	  for(j=(i/2)+1;j<i;j++)
	    printf("%c",s[j]);
	  printf("\n");
	}
      else
	{
	  //printf("came to last loop\n");
	  for(j=0;j<i/2;j++)
	    printf("%c",s[j]);
	  printf("a");
	  for(j=i/2;j<i;j++)
	    printf("%c",s[j]);
	  printf("\n");
	}
    }
  else if(flag >= 2)
    {
      printf("NA\n");
      return 0;
    }
  return 0;
}

#include<stdlib.h>
#include<string.h>
#include<stdio.h>
#include<math.h>

#define FOR(i,a,b)  for(i = a; i <= b; i++)
#define ROF(i,a,b)  for(i = a; i >= b; i--)

int i,j,s,u,u2,sit,sit2,t,t2;
char str[10000], ans[10000];

int main()
{
    scanf("%s", str);
    u = strlen(str);
    FOR(i,0,u/2-1){
        if(str[i] != str[u - 1 - i])
        {
            ROF(j,u,u-i+1){
                str[j] = str[j - 1];
            }
            str[u - i] = str[i];
            sit = 1;
            break;
        }
    }
    strcpy(ans,str);
    u = strlen(ans);
    FOR(i,0,u/2-1)
    {
        if(ans[i] != ans[u - i - 1])
            sit2 = 1;
    }
    if(sit2 == 0 && sit == 1)
        printf("%s", ans);
    else if(sit2 == 0 && sit == 0)
    {
        FOR(j,0,u-1){
            if(j == u / 2 - 1)
                printf("%c%c",ans[j],ans[j + 1]);
            else
                printf("%c", ans[j]);
        }
    }
    else
        printf("NA");
    return 0;
}

#include<stdio.h>
#include<string.h>
int is_pallindrome(char a[10000],int l)
{int i,j;
    for(i=0,j=l-1;i<l/2;++i,--j)
        if(a[i]==a[j])
            continue;
        else
            return 0;

    return 1;

}
int main()
{int try = -1;
    char a[100000];
    scanf("%s",a);
    int k;char b[100000];
    char c[100000];
    strcpy(b,a);
    strcpy(c,a);

    int l = strlen(a);
    int i,j;int flag1=-1,flag2=-1;
    for(i=l/2,j=l/2;i>=0;--i,++j)
    {if(a[i]==a[j])
        continue;
        else
        {flag1=i;flag2=j;
            if(a[i-1]==a[j])
            { for(k=l-1;k>=j;--k)
                c[k+1]=c[k];
                c[j]=c[i];
                if(is_pallindrome(c,l+1))
                {
                    printf("\n%s",c);
                    return 0;
                }
                else
                    try =0;

            }
            if(a[i]==a[j+1])
            {  for(k=l-1;k>=i;--k)
                b[k+1]=b[k];
                b[i-1]=b[j+1];

                if(is_pallindrome(b,l+1))
                {
                    printf("\n%s",b);
                    return 0;
                }
                else
                {printf("\nNA");
                    return 0;}
            }//check shifting till i

        }

    }

    if(flag1==-1)
    {
        if(l%2==0)
        {printf("\n");
            {
                for(i=0;i<l/2;++i)
                    printf("%c",a[i]);
            }
            printf("%c",a[l/2]);
            for(i;i<l;++i)
                printf("%c",a[i]);

            return 0;
        }
        else if(l%2==1)
        {printf("\n");
             {
                 for(i=0;i<l/2;++i)
                     printf("%c",a[i]);
             }
             printf("%c",a[l/2]);
             for(i;i<l;++i)
                 printf("%c",a[i]);

               return 0;
        }
    }

            printf("\nNA");

        return 0;
    }

#include <stdio.h>
#include <strings.h>

int main()
{
    int counter = 0 , no = 0 , index , index1 , flag = 0 , counter1 = 0;
    char str[11];
    scanf("%s",str);

    if (strlen(str) % 2 != 0)
    {
        printf("NA");
    }
    else
    {
        while ( counter < (strlen(str)/2) && flag == 0 && counter1 < strlen(str)/2)
        {
            if (str[counter] != str[strlen(str) - counter1-1])
            {
                if (str[counter] == str[strlen(str) - counter1 -2])
                {
                    index = counter;
                    index1 = strlen(str) - counter1-1;
                    no++;
                    counter1++;
                }
                else if (str[counter+1] == str[strlen(str) - counter1-1])
                {
                    index = strlen(str) - counter1;
                    index1 = counter;
                    no++;
                    counter++;
                }
                else
                {
                    flag = 1;
                }
            }
            else
            {
                counter++;
                counter1++;
            }
        }
        counter = 0;
        counter1 = 0;
        if (flag ==0 || no > 1)
        {
            while( counter <= strlen(str) && counter1 <= strlen(str))
            {
                if (no == 0)
                {
                    if (counter1 == strlen(str)/2)
                    {
                        printf("a");
                        counter1++;
                    }
                    else
                    {
                        printf("%c",str[counter]);
                        counter++;
                        counter1++;
                    }
                }
                else
                {
                    if (counter1 == index)
                    {
                        printf("%c",str[index1]);
                        counter1++;
                    }
                    else
                    {
                        printf("%c",str[counter]);
                        counter1++;
                        counter++;
                    }
                }
            }
        }
        else
        {
            printf("NA");
        }
    }
    return 0;
}

#include<stdlib.h>
#include<string.h>
#include<stdio.h>
#include<math.h>

#define FOR(i,a,b)  for(i = a; i <= b; i++)
#define ROF(i,a,b)  for(i = a; i >= b; i--)

int i,j,k,s,u,t=1,sit;
char str[10000], ans[10000];

int main()
{
    scanf("%s", str);
    u = strlen(str);
    FOR(i,0,u-1){
        if(str[i] != str[u - i - 1])
        {
            t = i;
            break;
        }
    }
    if(t != 0){
        if(t == 1){
            FOR(i,0,u-1){
                if(i == u/2)
                    printf("%c%c", str[i], str[i]);
                else
                    printf("%c", str[i]);
            }
            return 0;
        }
        ROF(i,u,u-t+1){
            str[i] = str[i - 1];
        }
        str[u - t] = str[t];
        FOR(i,0,u){
            if(str[i] != str[u - i])
            {
                printf("NA");
                return 0;
            }
        }
        printf("%s", str);
    }
    if(t == 0){
        strcpy(ans, str);
        ROF(i,u,1){
            ans[i] = ans[i - 1];
        }
        ans[0] = ans[u];
        FOR(i,0,u){
            if(ans[i] != ans[u - i])
                sit = 1;
        }
        if(!sit){
            printf("%s", ans);
            return 0;
        }
        ROF(i,u,u-t+1){
            str[i] = str[i - 1];
        }
        str[u - t] = str[t];
        FOR(i,0,u){
            if(str[i] != str[u - i])
            {
                printf("NA");
                return 0;
            }
        }
        printf("%s", str);
    }
    return 0;
}

#include<stdio.h>
#include<string.h>
int is_pallindrome(char a[10000],int l)
{int i,j;
    for(i=0,j=l-1;i<l/2;++i,--j)
        if(a[i]==a[j])
            continue;
        else
            return 0;

    return 1;

}
int main()
{int try = -1;
    char a[100000];
    scanf("%s",a);
    int k;char b[100000];
    char c[100000];
    strcpy(b,a);
    strcpy(c,a);

    int l = strlen(a);
    int i,j;int flag1=-1,flag2=-1;
    for(i=l/2,j=l/2;i>=0;--i,++j)
    {if(a[i]==a[j])
        continue;
        else
        {flag1=i;flag2=j;
            if(a[i-1]==a[j])
            { for(k=l-1;k>=j;--k)
                c[k+1]=c[k];
                c[j]=c[i];
                if(is_pallindrome(c,l+1))
                {
                    printf("\n%s\n",c);
                    return 0;
                }
                else
                    try =0;

            }
            if(a[i]==a[j+1])
            {  for(k=l-1;k>=i;--k)
                b[k+1]=b[k];
                b[i-1]=b[j+1];

                if(is_pallindrome(b,l+1))
                {
                    printf("\n%s\n",b);
                    return 0;
                }
                else
                {printf("\nNA\n");
                    return 0;}
            }//check shifting till i

        }

    }

    if(flag1==-1)
    {
        if(l%2==0)
        {printf("\n");
            {
                for(i=0;i<l/2;++i)
                    printf("%c",a[i]);
            }
            printf("%c",a[l/2]);
            for(i;i<l;++i)
                printf("%c",a[i]);
            printf("\n");
            return 0;
        }
        else if(l%2==1)
        {printf("\n");
             {
                 for(i=0;i<l/2;++i)
                     printf("%c",a[i]);
             }
             printf("%c",a[l/2]);
             for(i;i<l;++i)
                 printf("%c",a[i]);
             printf("\n");

               return 0;
        }
    }

            printf("\nNA\n");

        return 0;
    }

#include <stdio.h>
#include <string.h>
int main(){
	char a[15];
	scanf("%s",&a);
	int n=strlen(a)-1;
	int f=0,flag,fzy=0;
	char b;
	if(n==1){
		printf("%c%c%c",a[0],a[1],a[0]);
		return 0;
	}
	else if(strlen(a)%2!=0){
		int y=0;
	for(int i=0;i<strlen(a)/2;i++){
		if(f>strlen(a))
		break;
		if(a[i]!=a[n-y]){
			f++;
			if(a[i]==a[n-y-1]){
	        b=a[n-y];
			flag=i;
			i--;

			printf("%");
			}
			else if(a[i+1]==a[n-y]){
				b=a[i];
				flag=n-y;
				i++;

				fzy=1;
			}
		}
		y++;
	}
}
	else if(strlen(a)%2==0){
		int y=0;
	for(int i=0;i<strlen(a)/2;i++){
	        if(f>=strlen(a))
		    break;
			if(a[i]!=a[n-y]){
				f++;
			if(a[i]==a[n-y-1]){
			b=a[n-y];
			flag=i;
			i--;

			}
			else if(a[i+1]==a[n-y]){
				b=a[i];
				flag=n-y;
				i++;
				fzy=1;
			}
		}
		y++;
	}

}
if(f==1){
	if(strlen(a)==3){
		if(a[0]!=a[1]&&a[1]!=a[2]){
			printf("NA");
			return 0;
		}
	}
for(int i=0;i<strlen(a);i++){
	if(i==flag&&fzy==0){
		printf("%c",b);
	}
	printf("%c",a[i]);

	if(i==flag&&fzy==1){
		printf("%c",b);
	}
}

}
else if(f==0){
	for(int i=0;i<strlen(a);i++){
		if(i==n/2){
			printf("%c",a[n/2]);
		}
		printf("%c",a[i]);
}
}
else{
	printf("NA");
}

}

#include<stdio.h>
#include<string.h>
int fun(char a[],int n)
{
    int i,j,k;
    for(i=0;i<n/2;i++)
    {
        if(a[i]!=a[n-1-i])
        return  0;
    }
    return 1;
}
int main()
{
    int i,j,k,n,t,pos;
    char a[120];
    while(scanf("%s",a)!=EOF)
    {
        n=strlen(a);
        if(fun(a,n)==1)
        {
                for(i=0;i<n;i++)
                {
                    if(i==n/2)
                    printf("%c",a[i]);
                    printf("%c",a[i]);
                }
                printf("\n");
                continue;
        }
        else
        {
                t=n/2;
                for(i=t-1;i>=0;i--)
                {
                    if(a[i]!=a[t+(t-i)])
                    break;
                }
                if(i==0)
                {
                    printf("%s%c\n",a,a[0]);
                    continue;
                }
                pos=i;
                i--;
                for(j=i;j>=0;j--)
                {
                    if(a[j]!=a[t+(t-j-1)])
                    break;
                }
                if(j==-1)
                {
                    for(k=0;k<n;k++)
                    {
                        if(k==t+(t-pos))
                        printf("%c",a[pos]);
                        printf("%c",a[k]);
                    }
                    printf("\n");
                    continue;
                }
            if(n%2==0)
            {
                t=n/2-1;
                for(i=t+1;i<n;i++)
                {
                    if(a[i]!=a[t-(i-t)])
                    break;
                }
                //printf("i=%d ",i);
                if(i==n-1)
                {
                    printf("%c",a[n-1]);
                    printf("%s\n",a);
                    continue;
                }
                pos=i;
                i++;
                for(j=i;j<n;j++)
                {
                    if(a[j]!=a[t-(j-t)+1])
                    break;
                }
                if(j==n)
                {
                    for(k=0;k<n;k++)
                    {
                        if(k==t-(pos-t))
                        printf("%c",a[pos]);
                        printf("%c",a[k]);
                    }
                    printf("\n");
                    continue;
                }
            }
            printf("NA\n");
        }
    }
}

#include<stdio.h>
#include<string.h>
int is_pallindrome(char a[10000],int l)
{int i,j;
    for(i=0,j=l-1;i<l/2;++i,--j)
        if(a[i]==a[j])
            continue;
        else
            return 0;

    return 1;

}
int main()
{int try = -1;
    char a[100000];
    scanf("%s",a);
    int k;char b[100000];
    char c[100000];
    strcpy(b,a);
    strcpy(c,a);

    int l = strlen(a);
    int i,j;int flag1=-1,flag2=-1;
    for(i=l/2,j=l/2;i>=0;--i,++j)
    {if(a[i]==a[j])
        continue;
        else
        {flag1=i;flag2=j;
            if(a[i-1]==a[j])
            { for(k=l-1;k>=j;--k)
                c[k+1]=c[k];
                c[j]=c[i];
                if(is_pallindrome(c,l+1))
                {
                    printf("\n%s",c);
                  break;
                }
                else
                 try =0;

            }
            if(a[i]==a[j+1])
            {  for(k=l-1;k>=i;--k)
                b[k+1]=b[k];
                b[i-1]=b[j+1];

                if(is_pallindrome(b,l+1))
                {
                    printf("\n%s",b);
                 break;
                }
                else
                 {printf("\nNA");
                 break;}
            }//check shifting till i

        }

    }

    if(flag1==-1)
    {
        if(l%2==0)
        {{for(i=0;i<l/2;++i)
             printf("%c",a[i]);
         }
        printf("%c",a[l/2]);
        for(i;i<l;++i)
            printf("%c",a[i]);
        }
        if(l%2==1)
            printf("\nNA");
    }

    return 0;
}

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main()
{
    char s[11];
    int l,i,j,test1=1,test2=1;
    scanf("%s",&s);
    l=strlen(s);
    i=0;
    char *s1=malloc((l+2)*sizeof(char));
    char *s2=malloc((l+2)*sizeof(char));
    while((i<=(l/2))&& test1)
    {
        if(s[i]!=s[l-i-1])
        {
            char *m=malloc((i+1)*sizeof(char));
            m[0]=s[i];
            memcpy(s1,s,l-i);
            for(j=l-i; j<l; j++)
            {
                m[j-(l-i)+1]=s[j];
            }
            strcat(s1,m);
            test1=0;

        }
        i++;
    }
    i=0;
    while((i<=(l/2))&& test2)
    {
        if(s[i]!=s[l-i-1])
        {
            char *m1=malloc((i+1)*sizeof(char));
            m1[0]=s[l-i-1];
            if(i!=0) memcpy(s2,s,i-1);
            for(j=i; j<l; j++)
            {
                m1[j-i+1]=s[j];
            }
            strcat(s2,m1);
            test2=0;

        }
        i++;
    }

    if (test1&&test2)
    {
        if(l%2==0)
        {
            memcpy(s1,s,l/2);
            char *k=malloc((l/2+1)*sizeof(char));
            k[0]=s[(l/2)-1];
            for(i=(l/2); i<l; i++)
            {
                k[i-((l/2))+1]=s[i];

            }
            strcat(s1,k);
        }
        else
        {
            memcpy(s1,s,l/2+1);
            char *k=malloc((l/2+1)*sizeof(char));
            k[0]=s[(l/2)];
            for(i=(l/2)+1; i<l; i++)
            {
                k[i-((l/2)+1)+1]=s[i];

            }
            strcat(s1,k);
        }

    }
    test1=1;
    test2=1;
    while((i<(l/2+1))&& test1 &&test2)
    {
        if(s1[i]!=s1[l-i]) test1=0;
        if(s2[i]!=s2[l-i]) test2=0;
        i++;
    }

    if(test1) printf("%s",s1);
    else if(test2) printf("%s",s2);
    else printf("NA");

    return 0;
}

#include<stdlib.h>
#include<string.h>
#include<stdio.h>
#include<math.h>

#define FOR(i,a,b)  for(i = a; i <= b; i++)
#define ROF(i,a,b)  for(i = a; i >= b; i--)
#define MAX 100000

int N;
int i,j,s,u,u2,sit,sit2,t;
char str[10000], ans[10000];

int main()
{
    scanf("%s", str);
    u = strlen(str);
    FOR(i,0,u/2-1){
        if(str[i] != str[u - 1 - i])
        {
            FOR(j,u-i-1,u+1){
                if(j != u-1-i)
                    t = str[j+1];
                if(j == u-1-i)
                    str[j + 1] = str[i];
                else
                    str[j + 1] = t;
            }
            sit = 1;
            break;
        }
    }
    strcpy(ans,str);
    u = strlen(ans);
    FOR(i,0,u/2-1)
    {
        if(ans[i] != ans[u - i - 1])
            sit2 = 1;
    }
    if(sit2 == 0 && sit == 1)
        printf("%s", ans);
    else if(sit2 == 0 && sit == 0)
    {
        FOR(j,0,u-1){
            if(j == u / 2 - 1)
                printf("%c%c",ans[j],ans[j + 1]);
            else
                printf("%c", ans[j]);
        }
    }
    else
        printf("NA");
    return 0;
}

#include<stdio.h>
#include<string.h>
int checkpalin(char *str,int l,int h)
{
if(l==h)
return 1;
if(str[l]==str[h])
return checkpalin(str,l+1,h-1);
return 0;
}
int main()
{
     char str[12];
     char tst[12];
     scanf("%s",str);
     int l=strlen(str);
     int i;
     int pos=0;
     while(pos<l+1)
     {
        //printf("GG");
        char ch='a';
        while(ch<='z')
        {
        for(i=0;i<=pos-1;i++)
        {
            tst[i]=str[i];
        }
        tst[pos]=ch;
        for(i=pos+1;i<=l;i++)
        {
            tst[i]=str[i-1];
        }
        tst[l+1]='\0';
        int res=checkpalin(tst,0,l);

        if(res==1)
        {

            printf("%s\n",tst);
            goto out;
        }
        ch++;
        }
        pos++;
     }
     printf("NA\n");
     out:
     return 0;
}

#include <stdio.h>
#include <stdlib.h>
char a[21],b[21];
int pal(int x)
{

    int j;

    for(j = 0; j < x / 2; j++)
    {
        if (a[j] != a[x - j - 1])
            break;
    }
    if (j <  x / 2)
        return 0;
    else
       return 1;
}
int main()
{
    memset(a,' ',21);
    gets(a);
    strcpy(b,a);
   if (pal(strlen(a))){
    a[strlen(a)] = ' ';
    printf("%s",a);
    return 0;
    }
   int i = 0;
    int temp1 = 0;
    int temp2 = 0;
    int flag = 0;
    int q = strlen(a);
    while(i <= q)
    {
         char ch = 'a';
        int temp = i;
        for (i = q ; i > flag; i--)
            {
                a[i] = 'c';
                int tep = a[i];
                a[i] = a[i - 1];
                a[i - 1] = tep;
            }
            flag++;
            i = temp;
        while(ch <= 'z')
        {
            a[i] = ch;
            if (pal(q + 1)){
            temp2 = 1;
            break;
            }
            ch++;
        }
         if (temp2)
            break;
        i++;
        strcpy(a,b);
    }
    if (temp2)
    puts(a);
    else
    printf("NA");
    return 0;
}

#include<stdio.h>
#include<string.h>
int checkpalin(char *str,int l,int h)
{
if(l==h)
return 1;
if(str[l]==str[h])
return checkpalin(str,l+1,h-1);
return 0;
}
int main()
{
     char str[12];
     char tst[12];
     scanf("%s",str);
     int l=strlen(str);
     int i;
     int pos=0;
     char ch;
     while(pos<l+1)
     {
        //printf("GG");
         ch='a';
        while(ch<='z')
        {
        for(i=0;i<=pos-1;i++)
        {
            tst[i]=str[i];
        }
        tst[pos]=ch;
        for(i=pos+1;i<=l;i++)
        {
            tst[i]=str[i-1];
        }
        tst[l+1]='\0';
        int res=checkpalin(tst,0,l);

        if(res==1)
        {

            printf("%s\n",tst);
            goto out;
        }
        ch++;
        }
        pos++;
     }
     printf("NA\n");
     out:
     return 0;
}

#include<stdio.h>
#include<string.h>
int main()
{
	char s[12],c;
	int length;
	int left,right,i,mark;
	scanf("%s",s);
	getchar();
	length=strlen(s);
	left=0,right=length-1;
	for(i=0;i<length/2;i++)
	{
		if(s[left]==s[right]&&(left+1)!=length/2)
		{
			left++;
			right--;
		}
		else
			break;
	}
	if((left+1)!=length/2)//û�й�������
	{
		if(s[left]==s[right-1])//����߼��ַ�
		{
			c=s[right];
			mark=left;
			//�����ж�
			for(i=left+1;i<(length+1)/2;i++)
			{
				left=left+1;
				right=right-2;
				if(s[left]==s[right])
				{
					left++;
					right++;
				}
				else
				{
					printf("NA");
					return 0;
				}

			}
			for(i=0;i<=mark-1;i++)
			{
				printf("%c",s[i]);
			}
			printf("%d",c);
			for(i=mark;i<length;i++)
				printf("%c",s[i]);
			return 0;

		}

		else if(s[left+1]=s[right])//���ұ߼��ַ�
		{
			c=s[left];
			mark=right;
			//�ж������ַ���Ƿ�Ϊ����
			for(i=mark-1;i>length/2;i--)
			{
				left=left+2;
				right=right-1;
				if(s[left]==s[right])
				{
					left++;
					right--;
				}
				else
				{
					printf("NA");
					return 0;
				}
			}
			for(i=0;i<=mark;i++)
					printf("%c",s[i]);
			printf("%c",c);
			for(i=mark+1;i<=length-1;i++)
					printf("%c",s[i]);
			return 0;

		}
		else
		{
			printf("NA");
			return 0;
		}

	}

	else//�Ѿ��Գƣ���printf
	{
		for(i=0;i<=left;i++)
		{
			printf("%c",s[i]);
		}
		if(length%2)//����c��left+1���

		{
			printf("%c",s[left+1]);
			printf("%c",s[left+1]);
		}

		else
			printf("%c",s[left+1]);

		for(i=right;i<length;i++)
		{
			printf("%c",s[i]);

		}
	}

	return 0;
}

#include<stdio.h>
#include<string.h>
int main()
{
	char s[12],c;
	int length;
	int left,right,i,mark;
	scanf("%s",s);
	getchar();
	length=strlen(s);
	left=0,right=length-1;
	for(i=0;i<length/2;i++)
	{
		if(s[left]==s[right])
		{
			left++;
			right--;
		}
		else
			break;
	}
	if((left+1)!=length/2)
	{
		if(s[left]==s[right-1])//����߼��ַ�
		{
			c=s[right];
			mark=left;
			//�����ж�
			for(i=left+1;i<(length+1)/2;i++)
			{
				left=left+1;
				right=right-2;
				if(s[left]==s[right])
				{
					left++;
					right++;
				}
				else
				{
					printf("NA");
					return 0;
				}

			}
			for(i=0;i<=mark-1;i++)
			{
				printf("%c",s[i]);
			}
			printf("%d",c);
			for(i=mark;i<length;i++)
				printf("%c",s[i]);
			return 0;

		}

		else if(s[left+1]=s[right])//���ұ߼��ַ�
		{
			c=s[left];
			mark=right;
			//panduan
			for(i=left+2;i<=mark;i++)
			{
				left=left+2;
				right=right-1;
				if(s[left]==s[right])
				{
					left++;
					right++;
				}
				else
				{
					printf("NA");
					return 0;
				}
			}
			for(i=0;i<=mark;i++)
					printf("%c",s[i]);
			printf("%d",c);
			for(i=mark+1;i<=length-1;i++)
					printf("%c",s[i]);
			return 0;

		}
		else
		{
			printf("NA");
			return 0;
		}

	}

	else//�Ѿ��Գ£���printf
	{
		for(i=0;i<=left;i++)
		{
			printf("%c",s[i]);
		}
		if(length%2)//����c��left+1���

		{
			printf("%c",s[left+1]);
			printf("%c",s[left+1]);
		}

		else
			printf("%c",s[left+1]);

		for(i=right;i<length;i++)
		{
			printf("%c",s[i]);

		}
	}

	return 0;
}

#include<stdio.h>
#include<string.h>
int is_pallindrome(char a[10000],int l)
{int i,j;
    for(i=0,j=l-1;i<l/2;++i,--j)
        if(a[i]==a[j])
            continue;
        else
            return 0;

    return 1;

}
int main()
{int try = -1;
    char a[100000];
    scanf("%s",a);
    int k;char b[100000];
    char c[100000];
    int l = strlen(a);
    a[l]=b[l]=c[l]='\0';
    strcpy(b,a);
    strcpy(c,a);

    int i,j;int flag1=-1,flag2=-1;
    for(i=l/2,j=l/2;i>=0;--i,++j)
    {if(a[i]==a[j])
        continue;
        else
        {flag1=i;flag2=j;
            if(a[i-1]==a[j])
            { for(k=l-1;k>=j;--k)
                c[k+1]=c[k];
                c[j]=c[i];
                if(is_pallindrome(c,l+1))
                {
                    printf("%s\n",c);
                    return 0;
                }
                else
                    try =0;

            }
            if(a[i]==a[j+1])
            {  for(k=l-1;k>=i;--k)
                b[k+1]=b[k];
                b[i-1]=b[j+1];

                if(is_pallindrome(b,l+1))
                {
                    printf("%s\n",b);
                    return 0;
                }
                else
                {printf("NA\n");
                    return 0;}
            }//check shifting till i

        }

    }

    if(flag1==-1)
    {
        if(l%2==0)
        {
            {
                for(i=0;i<l/2;++i)
                    printf("%c",a[i]);
            }
            printf("%c",a[l/2]);
            for(i;i<l;++i)
                printf("%c",a[i]);
            printf("\n");
            return 0;
        }
        else if(l%2==1)
        {
             {
                 for(i=0;i<l/2;++i)
                     printf("%c",a[i]);
             }
             printf("%c",a[l/2]);
             for(i;i<l;++i)
                 printf("%c",a[i]);
            printf("\n");
               return 0;
        }
    }

            printf("NA\n");

        return 0;
    }

//http://codeforces.com/contest/505/problem/A

#include<stdio.h>
#include<string.h>

int checkpalin(char *str, int s, int e)
{
    while(s <= e)
    {
        if(str[s] == str[e])
        {
            s++, e--;
        }
        else
            return 0;
    }
    return 1;
}

void findstring(char *str, int len)
{
    char temp[len+1];

    int s=0, e=len-1;
    int ts=0, te=len;

    while(s <= e)
    {
        if(str[s] == str[e])
        {
            temp[ts] = temp[te] = str[s];
            ts++, te--;
            s++, e--;
            if(ts == te)
                temp[ts] = 'a';

        }
        else if(checkpalin(str,s+1,e))
        {
            temp[te] = temp[ts] = str[s];
            te--, ts++, s++;

        }
        else if(checkpalin(str,s,e-1))
        {
            temp[ts] = temp[te] = str[e];
            ts++, te--, e--;

        }
        else
        {
            break;
        }
    }
    if(s > e)
        printf("%s\n", temp);
    else
        printf("NA\n");

}

int main()
{
    char str[11];
    scanf("%s", str);

    int len = strlen(str);
    findstring(str,len);
    //printf("%d", checkpalin(str,0, len-1));
    return 0;
}

#include<stdio.h>

int isPalindrome(char *s, int n)
{
	for(int i = 0; i < n; i++)
	{
		if(s[i] != s[n-1-i])	return 0;
	}

	return 1;
}

int main()
{
	char s[11];
	scanf(" %s", s);

	int l = 0;
	char ans[12];

	for(int i = 0; s[i] != '\0'; i++)	l++;

	int position = 0;
	char letter;

	for(position = 0; position < l-1; position++)
	{
		letter = s[position];
		int k = 0;
		for(int i = 0; i < l-position; i++)	ans[k++] = s[i];
		ans[k++] = letter;
		for(int i = l-position; i < l; i++)	ans[k++] = s[i];
		ans[k] = '\0';
		if(isPalindrome(ans, l+1))
		{
			printf("%s\n", ans);
			return 0;
		}
	}

	letter = s[l-1];
	ans[0] = letter;
	for(int i = 0; i < l; i++)	ans[i+1] = s[i];
	ans[l+1] = '\0';

	if(isPalindrome(ans, l+1))
	{
		printf("%s\n", ans);
		return 0;
	}

	printf("NA\n");
	return 0;
}

//bug:iq,dog,babccba(�����޸ĵĻ�������Ҫ��������߼ӣ���Ҫ�������ұ߼�)
#include<stdio.h>
#include<string.h>
int main()
{
	char s[12],c;
	int length;
	int left,right,i,mark,leftbefore,rightbefore,ans=0;
	scanf("%s",s);
	getchar();
	length=strlen(s);
	left=0,right=length-1;
	for(i=0;i<length/2;i++)
	{
		if(s[left]==s[right])//���������ȣ�Ӧ����leftָ��ȥ����ֹleftֹͣ���м�ʱ����֪���м���Ƿ����
		{
			left++;
			right--;
		}
		else
			break;
	}
	//��¼�µ�ǰָ��λ�ã�������before��
	leftbefore=left;
	rightbefore=right;
	//�ж�left��λ���Ƿ��־���ַ�Գ����
	if(left<right)//������ַ�left=right��ż����ַ�left>right����ʾ�����Ѿ�ȫ���Գ�
	{
		if(s[left]==s[right-1])//����߼��ַ��ڴ��ڼ�û�ҵ��𰸲��˳�����ans��¼û���ҵ���
		{
			c=s[right];
			mark=left-1;
			//�����ж�
			left=left+1;
			right=right-2;
			for(i=0;i<(right-left+1)/2;i++)//i<(right-left+1)/2
			{

				if(s[left]==s[right])
				{
					left++;
					right--;
				}
				else
				{
					ans=1;//ans==1��ʾ�ڵ�һ�γ���ʧ��
					break;
				}
			}
			//��һ��forѭ�������ʾ���ɻ��Ĵ�����������
			if(ans!=1)
			{
				for(i=0;i<=mark;i++)
				{
					printf("%c",s[i]);
				}
				printf("%c",c);
				for(i=mark+1;i<length;i++)
					printf("%c",s[i]);
				return 0;
			}
		}

		left=leftbefore;
		right=rightbefore;
		if(s[left+1]==s[right])//���ұ߼��ַ�
		{
			c=s[left];
			mark=right;
			//�ж�
			for(i=0;i<(right-left+1)/2;i++)//i<(right-left+1)/2
			{
				left=left+2;
				right=right-1;
				if(s[left]==s[right])
				{
					left++;
					right--;
				}
				else
				{
					printf("NA");
					return 0;
				}
			}
			for(i=0;i<=mark;i++)
				printf("%c",s[i]);
			printf("%c",c);
			for(i=mark+1;i<length;i++)
				printf("%c",s[i]);
			return 0;
		}
		else
		{
			printf("NA");
			return 0;
		}
	}

	else//�Ѿ��Գƣ�printf
	{
		left--;
		right++;
		for(i=0;i<=left;i++)
		{
			printf("%c",s[i]);
		}
		if(length%2)//����c��left+1���

		{
			printf("%c",s[left+1]);
			printf("%c",s[left+1]);
		}

		else
			printf("%c",s[left+1]);

		for(i=right;i<length;i++)

			printf("%c",s[i]);

		return 0;
	}

}

#include <stdio.h>
#include<string.h>
int main(void) {
    int i,j,num,flag;
    char a, s[12];
    scanf("%s",&s);
    i=0;
    j=strlen(s)-1;
    flag=0;
    while(i<j)
    {
    	if(s[i]==s[j])
    	{
    		i++;j--;
    	}
    	else if(s[i]==s[j-1]&&i<j-1)
    	{
    		if(flag==1)
    	     {
    	     	flag==2;
    	         break;
    	     }
    		flag=1;
          if(i!=0)
    		num=i-1;
          else
            num=0;
          a=s[j];
    		j--;
    	}
    	else if(s[i+1]==s[j]&&i+1<j)
    	{
    		if(flag==1)
    	     {
    	     	flag==2;
    	         break;
    	     }
    		flag=1;
    		num=j+1;
    		a=s[i];
    		i++;
    	}
    	else if(s[i]!=s[j]&&i+1==j)
    	{
    		flag=1;
    		num=j+1;
    		a=s[i];
    		i++;j--;
    	}
    	else
    	{
    	   flag=2;
    	  break;
    	}
    }
    if(flag==0)
    {
    	if(strlen(s)%2==0)
    	{
    		a='a';
    		num=strlen(s)/2;
    	}
    	else
    	{
    		   num=strlen(s)/2;
    	       a=s[num];
    	}
    	   for(i=0;i<strlen(s);i++)
    	   {
    		if(num==i)
    		  printf("%c",a);
    	    printf("%c",s[i]);
         	}
    	  if(num==i)
    	   printf("%c",a);
        	printf("\n");

    }
    if(flag==1)
    {

    	for(i=0;i<strlen(s);i++)
    	{
    		if(num==i)
    		  printf("%c",a);
    	    printf("%c",s[i]);
    	}
    	if(num==i)
    	  printf("%c",a);
    	printf("\n");

    }
    if(flag==2)
    {
    	printf("NA\n");
    }
	return 0;
}

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main()
{
    char s[11], backup[11];
    gets(s);
    strcpy(backup,s);
    int len = strlen(s), i = 0, j = 0, chosen = 0;
    if(len == 1)
    {
        printf("%s%s",s,s);
        exit(0);
    }
    for(i = 0; i < len-1; i++)
    {
        for(j = i; j < len-1; j++)
            s[j] = s[j+1];
        s[len-1] = '\0';
        chosen = i;
        int found = 1, auxlen = strlen(s);
        for(j = 0; j < auxlen/2; j++)
            if(s[j] != s[auxlen-j-1])
            {
                found = 0;
                break;
            }
        strcpy( s,backup);
        if(found == 1)
        {
            for(j = 0; j < len-chosen; j++)
                printf("%c", s[j]);
            printf("%c", s[chosen]);
            for(j = len-chosen; j < len; j++)
                printf("%c", s[j]);
            exit(0);
        }
    }
    printf("NA");
}

#include<stdio.h>
#include<stdio.h>
#include<string.h>
#include<ctype.h>

char *insere(char ch[10],char c,int x)
{
    int i,n;
    n=strlen(ch);
   for(i=strlen(ch);i>x;i--)
    ch[i]=ch[i-1];
   ch[n+1]='\0';
   ch[x]=c;

    return(ch);
}

int palaindrom(char ch[])
{
    int i;
    for (i=0;i<(strlen(ch)/2);i++)
    {
        if (ch[i]!=ch[strlen(ch)-1-i])
            return 0;
    }
    return 1;
}

int main ()
{
    char ch[11],ch2[11],ch3[11];
    int i;
    scanf("%s",ch);

   if (palaindrom(ch)==1)
       {
        if ((strlen(ch)%2)==0)
    {printf("%s",insere(ch,'i',(strlen(ch)/2)));
    return 0;
    }

    else
            {printf("%s",insere(ch,ch[strlen(ch)/2],(strlen(ch)/2)));
return 0;            }
        }
    else
       {
        for (i=0;i<(strlen(ch)/2);i++)
        if (ch[i]!=ch[strlen(ch)-i-1])
        {
            strcpy(ch3,insere(ch,ch[i],strlen(ch)-i));
                        strcpy(ch2,insere(ch,ch[strlen(ch)-i-1],i));

                        if (palaindrom(ch3)==1)
                            printf("%s",ch3);

                        else if
                           ( palaindrom(ch2)==1)
                           printf("%s",ch2);
                        else printf("NA");
                        return 0;

        }
    }

printf("%s",insere(ch,ch[1],(strlen(ch)/2)));

    return 0;
}

#include <stdio.h>
#include <string.h>

int palin(char a[], int l, int m)
{
    int i, j;
    for (i = l, j = m; i < j; i++, j--) {
        if (a[i] != a[j]) {
            return 0;
        }
    }
    return 1;
}

int main()
{
    char a[100001];
    scanf("%s", a);
    int i;
    int n = strlen(a);
    if (palin(a, 0, n-1)) {
        if (n%2) {
        for (i = 0; i <= n/2; i++) {
            printf("%c", a[i]);
        }
        printf("%c", a[n/2]);
        for (i = n/2+1; i < n; i++) {
            printf("%c", a[i]);
        }
        } else {
            for (i = 0; i < n/2; i++) {
                printf("%c", a[i]);
            }
            printf("%c", 'a');
            for (i = n/2; i < n; i++) {
                printf("%c", a[i]);
            }
        }
        printf("\n");
    } else if (palin(a, 1, n-1)) {
        for (i = 0; i < n; i++) {
            printf("%c", a[i]);
        }
        printf("%c\n", a[0]);
    } else if (palin(a, 0, n-2)) {
        printf("%c", a[n-1]);
        for (i = 0; i < n; i++) {
            printf("%c", a[i]);
        }
        printf("\n");
    } else {
        printf("NA\n");
    }

    return 0;
}

#include <stdio.h>
#include <string.h>

int lel(const char* first, const char* second, int len1)
{
	char third[11];
	int len2;
	int i,j;
	int flag = 0;
	for (i = 0; i < len1 / 2; i++)
	{
		for (len2 = j = 0; j < len1; j++)
		{
			if (j != i)
			{
				third[len2++] = first[j];
			}
		}
		third[len2] = '\0';

		if (!strncmp(second, third, len1 / 2))
		{
			flag = 1;
			for (j = 0; j < len1 - i; j++)
				printf("%c", first[j]);
			printf("%c", first[i]);
			for (j = len1 - i; j < len1; j++)
				printf("%c", first[j]);
			printf("\n");
		}
	}
	return flag;
}

int main(void)
{
	char first[11];
	char second[11];
	int len1, len2;
	int flag = 0;
	int i,j;

	fgets(first, 10, stdin);
	len1 = strlen(first);
	if (first[len1 - 1] = '\n') first[--len1] = '\0';
	for (i = 0, j = len1 - 1; j >= 0; i++, j--)
		second[i] = first[j];
	second[i] = '\0';

	if (!lel(first, second, len1) && !lel(second, first, len1))
		printf("NA\n");

	return 0;
}

#include<stdlib.h>
#include<string.h>
#include<stdio.h>
#include<math.h>

#define FOR(i,a,b)  for(i = a; i <= b; i++)
#define ROF(i,a,b)  for(i = a; i >= b; i--)

int i,j,s,u,u2,sit,sit2,t,t2;
char str[10000], ans[10000];

int main()
{
    scanf("%s", str);
    u = strlen(str);
    if(u == 1)
        printf("%s%s",str, str);
    else {
        FOR(i,0,u/2-1){
            if(str[i] != str[u - 1 - i])
            {
                ROF(j,u,u-i+1){
                    str[j] = str[j - 1];
                }
                str[u - i] = str[i];
                sit = 1;
                break;
            }
        }
        strcpy(ans,str);
        u = strlen(ans);
        FOR(i,0,u/2-1)
        {
            if(ans[i] != ans[u - i - 1])
                sit2 = 1;
        }
        if(sit2 == 0 && sit == 1)
            printf("%s", ans);
        else if(sit2 == 0 && sit == 0)
        {
            FOR(j,0,u-1){
                if(j == u / 2 - 1)
                    printf("%c%c",ans[j],ans[j + 1]);
                else
                    printf("%c", ans[j]);
            }
        }
        else
            printf("NA");
    }
    return 0;
}

#include <stdio.h>
#include <string.h>
int palindrome(char checkstring1[11], int length);
int main(){
	int i,flag=0,j,k,r,l;
	char string[11];
	char string1[12];
	scanf("%s", string);
	for (i = 0; i <= strlen(string); i++){
		for (j = 0; j <= 25; j++){
			string1[i] = 'a' + j;
			l = 0;
			for (k = 0; k < strlen(string)+1; k++){
				if (i != k){
					string1[k] = string[l];
					l++;
				}
			}
			flag = palindrome(string1, strlen(string));
			if (flag){
				break;
			}
			}
		if (flag){
			break;
		}
		}
	if (flag){
		for (r = 0; r < strlen(string) + 1; r++){
			printf("%c", string1[r]);
		}
	}
	return 0;
}
int palindrome(char checkstring[12], int length){
	int count = 0, i;
	for (i = 0; i < (length+1) / 2; i++){
		if (checkstring[i] == checkstring[length - i])
			count++;
	}
	if (count == (length + 1) / 2)
		return 1;
	else
		return 0;
}

#include <stdio.h>
#include<string.h>
int main()
{
    int l,r,i,f=1,pos,fl; char s[20],c; scanf("%s",s); l=0; r=strlen(s)-1;
    while(l<=r)
    {
        if(s[l]==s[r])
        {
            l++; r--; continue;
        }
        if(s[l]!=s[r])
        {
            f=0;
             fl=1;
            pos=r+1;
            c=s[l]; int right,left=l+1; right=r;
            while(left<=right)
            {
                if(s[left]!=s[right])
                {fl=0; break;}
                left++; right--;
            }
            if(fl==0)
            {

                pos=l;

                c=s[r]; fl=1; left=l; right=r-1;
                while(left!=right)
                {
                    if(s[left]!=s[right])
                {fl=0; break;}
                left++; right--;
                }
            }

            break;
        }
    }
    if(fl==0 && f==0) {printf("NA"); return 0;}
    if(f==1)
    {
        pos=strlen(s)/2; c=s[pos];
    }
    int len=strlen(s)+1; i=0; f=0;
    while(len--)
    {
        if(i!=pos || f==1)
        printf("%c",s[i++]);
        else
        {printf("%c",c); f=1;}
    }
    return 0;
}

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main()
{
    char s[11], letter;
    gets(s);
    int i = 0, len = strlen(s), forward = 0, backward = len-1, once = 0, f = -1, pos = 0;
    for(i = 0; i < len/2; i++)
    {
        if(s[forward] != s[backward])
        {
            if(once == 1)
            {
                printf("NA");
                exit(0);
            }
            once = 1;
            if(s[forward+1] == s[backward])
            {
                f = 0;
                letter = s[forward];
                pos = backward;
                backward++;
            }
            else if(s[forward] == s[backward-1])
            {
                letter = s[backward];
                f = 1;
                pos = forward;
                forward--;
            }
            else
            {
                printf("NA");
                exit(0);
            }
        }
        forward++; backward--;
    }
    if(f == 0)
    {
        for(i = 0; i <= pos; i++)
            printf("%c", s[i]);
        printf("%c", letter);
        for(i = pos+1; i < len; i++)
            printf("%c", s[i]);
    }
    else if(f == 1)
    {
        for(i = 0; i < pos; i++)
            printf("%c", s[i]);
        printf("%c", letter);
        for(i = pos; i < len; i++)
            printf("%c", s[i]);
    }
    else
    {
        if(len % 2 == 0)
        {
            for(i = 0; i < len/2; i++)
                printf("%c", s[i]);
            printf("%c", 'a');
            for(i = len/2; i < len; i++)
                printf("%c", s[i]);
        }
        else
        {
            for(i = 0; i <= len/2; i++)
                printf("%c", s[i]);
            for(i = len/2; i < len; i++)
                printf("%c", s[i]);
        }
    }
}

//bug:iq,dog
#include<stdio.h>
#include<string.h>
int main()
{
	char s[12],c;
	int length;
	int left,right,i,mark;
	scanf("%s",s);
	getchar();
	length=strlen(s);
	left=0,right=length-1;
	for(i=0;i<length/2;i++)
	{
		if(s[left]==s[right])//���������ȣ�Ӧ����leftָ��ȥ����ֹleftֹͣ���м�ʱ����֪���м���Ƿ����
		{
			left++;
			right--;
		}
		else
			break;
	}
	//�ж�left��λ���Ƿ��־���ַ�Գ����

	if(left<right)//������ַ�left=right��ż����ַ�left>right����ʾ�����Ѿ�ȫ���Գ�
	{
		if(s[left]==s[right-1])//����߼��ַ�
		{
			c=s[right];
			mark=left-1;
			//�����ж�
			left=left+1;
			right=right-2;
			for(i=0;i<(right-left+1)/2;i++)//δ��֤i<(right-left+1)/2
			{

				if(s[left]==s[right])
				{
					left++;
					right--;
				}
				else
				{
					printf("NA");
					return 0;
				}
			}
			//��һ��forѭ�������ʾ���ɻ��Ĵ�����������
			for(i=0;i<=mark;i++)
			{
				printf("%c",s[i]);
			}
			printf("%c",c);
			for(i=mark+1;i<length;i++)
				printf("%c",s[i]);
			return 0;
		}

		else if(s[left+1]==s[right])//���ұ߼��ַ�
		{
			c=s[left];
			mark=right;
			//�ж�
			for(i=0;i<(right-left+1)/2;i++)//δ��֤i<(right-left+1)/2
			{
				left=left+2;
				right=right-1;
				if(s[left]==s[right])
				{
					left++;
					right--;
				}
				else
				{
					printf("NA");
					return 0;
				}
			}
			for(i=0;i<=mark;i++)
				printf("%c",s[i]);
			printf("%c",c);
			for(i=mark+1;i<length;i++)
				printf("%c",s[i]);
			return 0;
		}
		else
		{
			printf("NA");
			return 0;
		}
	}

	else//�Ѿ��Գƣ�printf
	{
		left--;
		right++;
		for(i=0;i<=left;i++)
		{
			printf("%c",s[i]);
		}
		if(length%2)//����c��left+1���

		{
			printf("%c",s[left+1]);
			printf("%c",s[left+1]);
		}

		else
			printf("%c",s[left+1]);

		for(i=right;i<length;i++)

			printf("%c",s[i]);

		return 0;
	}

}

#include<stdio.h>
#include<string.h>
int fun(char a[],int n)
{
	int i,j,k;
	for(i=0;i<n/2;i++)
	{
		if(a[i]!=a[n-1-i])
		return  0;
	}
	return 1;
}
int main()
{
	char a[100];
	char b[100];
	int i,j,k;
	char t;
	while(scanf("%s",a)!=EOF)
	{
		int L=strlen(a);
		for(i=0;i<L;i++)
		{
			strcpy(b,a);
			t=b[L-i-1];
			for(j=L-1;j>=i;j--)
			b[j+1]=b[j];
			b[j+1]=t;
			b[L+1]='\0';
		//	printf("%s\n",b);
			if(fun(b,L+1)==1)
			{
				printf("%s\n",b);
				break;
			}
		}
		if(i!=L)
		continue;
		a[i]=a[0];
		a[L+1]='\0';
		//printf("%s\n",a);
		if(fun(a,L+1)==1)
		{
			printf("%s\n",a);
			continue;
		}

		printf("NA\n");
	}
}

#include <stdio.h>
#include <stdlib.h>
char a[21],b[21];
int pal(int x)
{

    int j;

    for(j = 0; j < x / 2; j++)
    {
        if (a[j] != a[x - j - 1])
            break;
    }
    if (j <  x / 2)
        return 0;
    else
       return 1;
}
int main()
{
    memset(a,' ',21);
    gets(a);
    strcpy(b,a);
   if (pal(strlen(a))){
    a[strlen(a)] = ' ';
    printf("%s",a);
    return 0;
    }
   int i = 0;
    int temp1 = 0;
    int temp2 = 0;
    int flag = 0;
    int q = strlen(a);
    while(i <= q)
    {
         char ch = 'a';
        int temp = i;
        for (i = q ; i > flag; i--)
            {
                a[i] = 'c';
                int tep = a[i];
                a[i] = a[i - 1];
                a[i - 1] = tep;
            }
            flag++;
            i = temp;
        while(ch <= 'z')
        {
            a[i] = ch;
            if (pal(q + 1)){
            temp2 = 1;
            break;
            }
            ch++;
        }
         if (temp2)
            break;
        i++;
        strcpy(a,b);
    }
    if (temp2)
    puts(a);
    else
    printf("NA");
    return 0;
}

#include<stdio.h>

int isPalindrome(char *s, int n)
{
	for(int i = 0; i < n; i++)
	{
		if(s[i] != s[n-1-i])	return 0;
	}

	return 1;
}

int main()
{
	char s[11];
	scanf(" %s", s);

	int l = 0;
	char ans[12];

	for(int i = 0; s[i] != '\0'; i++)	l++;

	int position = 0;
	char letter;

	for(int position = 0; position < l; position++)
	{
		letter = s[position];
		int k = 0;
		for(int i = 0; i < l-position; i++)	ans[k++] = s[i];
		ans[k++] = letter;
		for(int i = l-position; i < l; i++)	ans[k++] = s[i];
		ans[k] = '\0';

		if(isPalindrome(ans, l+1))
		{
			printf("%s\n", ans);
			return 0;
		}
	}

	printf("NA\n");
	return 0;
}

#include <stdio.h>
#include <string.h>
int main(){
	char a[15];
	scanf("%s",&a);
	int n=strlen(a)-1;
	int f=0,flag,fzy=0,yn=0;
	char b;
	if(n==1){
		printf("%c%c%c",a[0],a[1],a[0]);
		return 0;
	}
	else if(strlen(a)%2!=0){
		int y=0;
	for(int i=0;i<strlen(a)/2;i++){
		if(f>strlen(a))
		break;
		if(a[i]!=a[n-y]){
			f++;
			if(a[i]==a[n-y-1]){
	        b=a[n-y];
			flag=i;
			i--;
			yn=1;

			}
			else if(a[i+1]==a[n-y]){
				b=a[i];
				flag=n-y;
				i++;
				yn=1;
				fzy=1;
			}
		}
		y++;
	}
}
	else if(strlen(a)%2==0){
		int y=0;
	for(int i=0;i<strlen(a)/2;i++){
	        if(f>=strlen(a))
		    break;
			if(a[i]!=a[n-y]){
				f++;
			if(a[i]==a[n-y-1]){
			b=a[n-y];
			flag=i;
			i--;
			yn=1;
			}
			else if(a[i+1]==a[n-y]){
				b=a[i];
				flag=n-y;
				i++;
				fzy=1;
				yn=1;
			}
		}
		y++;
	}

}
if(f==1&&yn==1){
	if(strlen(a)==3){
		if(a[0]!=a[1]&&a[1]!=a[2]){
			printf("NA");
			return 0;
		}
	}
for(int i=0;i<strlen(a);i++){
	if(i==flag&&fzy==0){
		printf("%c",b);
	}
	printf("%c",a[i]);

	if(i==flag&&fzy==1){
		printf("%c",b);
	}
}

}
else if(f==0){
	for(int i=0;i<strlen(a);i++){
		if(i==n/2){
			printf("%c",a[n/2]);
		}
		printf("%c",a[i]);
}
}
else{
	printf("NA");
}

}