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;
const int N = 3e2 + 10;
const int Mo = 10007;
char s[N];
int a[N], n, m, len, Ans;
int f[N][N][N], w[N], c[N][N], C[N][N], g[N], g_[N];
void Doit(int fu) {
  int step = (n + m + 1 >> 1) + 1;
  memset(g, 0, sizeof g), g[0] = 1;
  for (int x = step; x; x >>= 1) {
    if (x & 1) {
      memset(g_, 0, sizeof g_);
      for (int x = 0; x <= len; x++)
        for (int y = x; y <= len; y++)
          ((g_[y]) = (g_[y] + g[x] * c[x][y]) % Mo);
      memcpy(g, g_, sizeof g);
    }
    memset(C, 0, sizeof C);
    for (int x = 0; x <= len; x++)
      for (int y = x; y <= len; y++)
        for (int z = y; z <= len; z++)
          ((C[x][z]) = (C[x][z] + 1ll * c[x][y] * c[y][z]) % Mo);
    memcpy(c, C, sizeof c);
  }
  ((Ans) = (Ans + fu * g[len]) % Mo);
}
int main() {
  scanf("%s", s + 1), m = strlen(s + 1);
  for (int i = 1; i <= m; i++) a[i] = s[i] - 'a' + 1;
  scanf("%d", &n);
  f[0][m + 1][0] = 1;
  for (int l = m + 2; l >= 3; l--)
    for (int i = 0; i <= m - l + 2; i++) {
      int j = i + l - 1;
      for (int k = 0; k <= m; k++)
        if (f[i][j][k]) {
          if (a[i + 1] == a[j - 1])
            ((f[i + 1][j - 1][k]) = (f[i + 1][j - 1][k] + f[i][j][k]) % Mo);
          else {
            ((f[i + 1][j][k + 1]) = (f[i + 1][j][k + 1] + f[i][j][k]) % Mo);
            ((f[i][j - 1][k + 1]) = (f[i][j - 1][k + 1] + f[i][j][k]) % Mo);
          }
        }
    }
  for (int k = 0; k <= m; k++)
    for (int i = 0; i <= m; i++)
      ((w[k]) = (w[k] + f[i][i][k] + f[i][i + 1][k]) % Mo);
  int L = m + 1 >> 1;
  len = m + L;
  c[0][1] = 1, c[0][m] = w[0];
  for (int i = 1; i <= m - 1; i++) {
    c[i][i + 1] = i < (m - 1), c[i][i] = 24;
    c[i][len - (m - i + 1 >> 1)] = w[i];
  }
  for (int i = m; i <= len - 1; i++) {
    c[i][i] = 25;
    c[i][i + 1] = 1;
  }
  c[len][len] = 26;
  Doit(1);
  if (n + m & 1) {
    memset(w, 0, sizeof w);
    for (int k = 0; k <= m; k++)
      for (int i = 0; i <= m; i++)
        if (a[i] == a[i + 1]) ((w[k]) = (w[k] + f[i][i + 1][k]) % Mo);
    memset(c, 0, sizeof c), c[0][1] = 1;
    c[0][m] = w[0];
    for (int i = 1; i <= m - 1; i++) {
      c[i][i + 1] = i < (m - 1), c[i][i] = 24;
      c[i][len - (m - i + 1 >> 1)] = w[i];
    }
    for (int i = m; i <= len - 1; i++) {
      c[i][i] = 25;
      c[i][i + 1] = 1;
    }
    c[len][len] = 0;
    Doit(-1);
  }
  printf("%d\n", (Ans + Mo) % Mo);
}