Problem: Mr. Kitayuta has kindly given you a string s consisting of lowercase English letters. You are asked to insert exactly n lowercase English letters 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 n lowercase English letters, and insert each of them to any position of s, possibly to the beginning or the end of s. You have to insert exactly n letters even if it is possible to turn s into a palindrome by inserting less than n letters.

Find the number of the palindromes that can be obtained in this way, modulo 10007.

Input

The first line contains a string s (1 ≤ |s| ≤ 200). Each character in s is a lowercase English letter.

The second line contains an integer n (1 ≤ n ≤ 109).

Output

Print the number of the palindromes that can be obtained, modulo 10007.

Examples

Input

revive
1


Output

1


Input

add
2


Output

28

Note

For the first sample, you can obtain the palindrome "reviver" by inserting 'r' to the end of "revive".

For the second sample, the following 28 palindromes can be obtained: "adada", "adbda", ..., "adzda", "dadad" and "ddadd".

Solution (in CPP):

Solution:
#include <bits/stdc++.h>
using namespace std;
int n, m, tot, S, T, an;
char c[405];
int s[405];
int g[205][205][205], flag[205][205], si[205];
int id1[205], id2[205];
struct mxr {
  int a, b;
  int t[405][405];
} mb, ans;
int adt(int a, int b) {
  if (a + b >= 10007) return a + b - 10007;
  return a + b;
}
mxr operator*(mxr A, mxr B) {
  mxr C;
  memset(C.t, 0, sizeof C.t);
  C.a = A.a;
  C.b = B.b;
  if (C.a != C.b) {
    for (int i = 1; i <= C.a; i++)
      for (int j = 1; j <= C.b; j++)
        for (int k = 1; k <= A.b; k++)
          C.t[i][j] = adt(C.t[i][j], (long long)A.t[i][k] * B.t[k][j] % 10007);
  } else {
    for (int i = 1; i <= C.a; i++)
      for (int j = i; j <= C.b; j++)
        for (int k = i; k <= j; k++)
          C.t[i][j] = adt(C.t[i][j], (long long)A.t[i][k] * B.t[k][j] % 10007);
  }
  return C;
}
void work(int x, int y, int v) {
  memset(mb.t, 0, sizeof mb.t);
  memset(ans.t, 0, sizeof ans.t);
  int mx1 = 0, mx2 = 0;
  tot = 0;
  S = ++tot;
  for (int i = 0; i <= n; i++)
    if (si[i] != 0) mx1 = max(mx1, i), mx2 = max(mx2, (n - i + 1) / 2);
  for (int i = 1; i <= mx1; i++) id1[i] = ++tot;
  for (int i = mx2; i >= 1; i--) id2[i] = ++tot;
  T = ++tot;
  mb.a = mb.b = tot;
  for (int i = 1; i < mx1; i++) mb.t[id1[i]][id1[i + 1]] = 1;
  for (int i = mx2; i > 1; i--) mb.t[id2[i]][id2[i - 1]] = 1;
  if (mx1 != 0) mb.t[S][id1[1]] = 1;
  if (mx2 != 0) mb.t[id2[1]][T] = 1;
  for (int i = 1; i <= mx1; i++) mb.t[id1[i]][id1[i]] = 24;
  for (int i = 1; i <= mx2; i++) mb.t[id2[i]][id2[i]] = 25;
  id1[0] = S;
  id2[0] = T;
  for (int i = 0; i <= n; i++) {
    if (si[i] == 0) continue;
    mb.t[id1[i]][id2[(n - i + 1) / 2]] = si[i];
  }
  mb.t[T][T] = 26;
  if (v == -1) mb.t[T][T] = 0;
  ans.a = 1;
  ans.b = tot;
  for (int i = 1; i <= tot; i++) ans.t[1][i] = 0;
  ans.t[1][S] = 1;
  while (y != 0) {
    if (y & 1) ans = ans * mb;
    mb = mb * mb;
    y = (y >> 1);
  }
  an = (an + (long long)v * ans.t[1][T] % 10007 + 10007) % 10007;
}
int main() {
  scanf("%s", c + 1);
  n = strlen(c + 1);
  scanf("%d", &m);
  for (int i = 1; i <= n; i++) s[i] = c[i] - 'a' + 1;
  for (int i = 1; i <= n; i++)
    for (int j = i; j <= n; j++) {
      if (s[i] == s[j])
        flag[i][j] = 0;
      else
        flag[i][j] = 1;
    }
  g[1][n][flag[1][n]] = 1;
  for (int len = n; len >= 1; len--)
    for (int i = 1; i <= n; i++) {
      int j = i + len - 1;
      if (j > n) break;
      for (int k = 0; k <= n; k++) {
        if (flag[i][j] == 0) {
          g[i + 1][j - 1][k + flag[i + 1][j - 1]] =
              adt(g[i + 1][j - 1][k + flag[i + 1][j - 1]], g[i][j][k]);
        } else {
          g[i + 1][j][k + flag[i + 1][j]] =
              adt(g[i + 1][j][k + flag[i + 1][j]], g[i][j][k]);
          g[i][j - 1][k + flag[i][j - 1]] =
              adt(g[i][j - 1][k + flag[i][j - 1]], g[i][j][k]);
        }
      }
    }
  memset(si, 0, sizeof si);
  for (int i = 1; i <= n; i++) {
    if (flag[i][i] == 0) {
      for (int j = 0; j <= n; j++) si[j] = (si[j] + g[i][i][j]) % 10007;
    }
    if (i != n && flag[i][i + 1] == 0) {
      for (int j = 0; j <= n; j++) si[j] = (si[j] + g[i][i + 1][j]) % 10007;
    }
  }
  work(0, (n + m + 1) / 2 + 1, 1);
  if ((n + m) % 2 == 1 && n != 1) {
    memset(si, 0, sizeof si);
    for (int i = 1; i < n; i++) {
      if (flag[i][i + 1] == 0) {
        for (int j = 0; j <= n; j++) si[j] = (si[j] + g[i][i + 1][j]) % 10007;
      }
    }
    work(-1, (n + m + 1) / 2 + 1, -1);
  }
  printf("%d\n", an);
  return 0;
}