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 g[311], dp[100011][311], vist[100011][311], No[311][311], black[100011],
    white[100011], indexx[100011], tot, cnt, ans, T, type[100011], m, n;
char s[311];
struct squ {
  int s[311][311];
  friend squ operator*(squ &u, squ &v) {
    squ ret;
    for (int i = 0; i <= cnt; i++) {
      for (int j = i; j <= cnt; j++) {
        ret.s[i][j] = 0;
        for (int k = i; k <= j; k++) {
          ret.s[i][j] =
              (ret.s[i][j] + 1ll * u.s[i][k] * v.s[k][j] % 10007) % 10007;
        }
      }
    }
    return ret;
  }
} A, B;
struct apple {
  int v, nxt;
} edge[100011 * 4];
void addedge(int x, int y) {
  edge[++tot].v = y;
  edge[tot].nxt = indexx[x];
  indexx[x] = tot;
}
int dfs(int u, int k) {
  if (k < 0) return 0;
  if (u == T) return (k == 0);
  if (vist[u][k]) return dp[u][k];
  vist[u][k] = 1;
  int t = indexx[u], vv;
  while (t) {
    vv = edge[t].v;
    dp[u][k] = (dp[u][k] + dfs(vv, k - type[u])) % 10007;
    t = edge[t].nxt;
  }
  return dp[u][k];
}
void ksm(int y) {
  while (y) {
    if (y & 1) B = B * A;
    A = A * A;
    y >>= 1;
  }
}
int main() {
  scanf("%s%d", s + 1, &m);
  n = strlen(s + 1);
  for (int i = 1; i <= n; i++) {
    for (int j = i; j <= n; j++) {
      No[i][j] = ++cnt;
      if (s[i] == s[j])
        type[cnt] = 0;
      else
        type[cnt] = 1;
    }
  }
  T = ++cnt;
  for (int i = 1; i <= n; i++) {
    for (int j = i; j <= n; j++) {
      if (s[i] == s[j]) {
        if (j - i <= 1)
          addedge(No[i][j], T);
        else
          addedge(No[i][j], No[i + 1][j - 1]);
      } else {
        addedge(No[i][j], No[i][j - 1]);
        addedge(No[i][j], No[i + 1][j]);
      }
    }
  }
  for (int i = 0; i < n; i++) {
    g[i] = dfs(No[1][n], i);
  }
  cnt = -1;
  for (int i = 0; i < n; i++) black[i] = ++cnt;
  for (int i = (n + 1) / 2; i >= 1; i--) white[i] = ++cnt;
  cnt++;
  A.s[cnt][cnt] = 26;
  for (int i = (n + 1) / 2; i >= 1; i--) {
    A.s[white[i]][white[i]] = 25;
    if (white[i + 1]) A.s[white[i + 1]][white[i]] = 1;
    if (i == 1) A.s[white[i]][cnt] = 1;
  }
  for (int i = 0; i < n; i++) {
    if (i) A.s[black[i]][black[i]] = 24;
    A.s[black[i]][white[(n - i + 1) / 2]] = g[i];
    if (i < n - 1) A.s[black[i]][black[i + 1]] = 1;
  }
  B.s[0][0] = 1;
  ksm((n + m + 1) / 2 + 1);
  ans = B.s[0][cnt];
  if ((n + m) % 2 == 0) {
    printf("%d", ans);
  } else {
    memset(indexx, 0, sizeof(indexx));
    tot = 0;
    memset(vist, 0, sizeof(vist));
    memset(dp, 0, sizeof(dp));
    memset(g, 0, sizeof(g));
    memset(&A, 0, sizeof(A));
    memset(&B, 0, sizeof(B));
    for (int i = 1; i <= n; i++) {
      for (int j = i; j <= n; j++) {
        if (s[i] == s[j]) {
          if (j - i == 0)
            continue;
          else if (j - i <= 1)
            addedge(No[i][j], T);
          else
            addedge(No[i][j], No[i + 1][j - 1]);
        } else {
          addedge(No[i][j], No[i][j - 1]);
          addedge(No[i][j], No[i + 1][j]);
        }
      }
    }
    for (int i = 0; i < n; i++) {
      g[i] = dfs(No[1][n], i);
    }
    for (int i = (n + 1) / 2; i >= 1; i--) {
      A.s[white[i]][white[i]] = 25;
      if (white[i + 1]) A.s[white[i + 1]][white[i]] = 1;
      if (i == 1) A.s[white[i]][cnt] = 1;
    }
    for (int i = 0; i < n; i++) {
      if (i) A.s[black[i]][black[i]] = 24;
      A.s[black[i]][white[(n - i + 1) / 2]] = g[i];
      if (i < n) A.s[black[i]][black[i + 1]] = 1;
    }
    B.s[0][0] = 1;
    ksm((n + m + 1) / 2 + 1);
    ans = (ans - B.s[0][cnt] + 10007) % 10007;
    printf("%d", ans);
  }
  return 0;
}