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 = 305, MOD = 1e4 + 7;
char s[N];
int n, m, ndc, f[N][N][N];
int getf(int cnt, int l, int r) {
  if (cnt < 0) return 0;
  if (~f[cnt][l][r]) return f[cnt][l][r];
  if (l == 1 && r == m) return f[cnt][l][r] = !cnt;
  int ret = 0;
  if (l > 1 && r < m && s[l - 1] == s[r + 1])
    ret = (ret + getf(cnt, l - 1, r + 1)) % MOD;
  if (l > 1 && s[l - 1] != s[r]) ret = (ret + getf(cnt - 1, l - 1, r)) % MOD;
  if (r < m && s[l] != s[r + 1]) ret = (ret + getf(cnt - 1, l, r + 1)) % MOD;
  return f[cnt][l][r] = ret;
}
struct matrix {
  int sq[N][N];
  matrix() { memset(sq, 0, sizeof(sq)); }
  matrix operator*(const matrix &a) const {
    matrix ret;
    for (int i = 1; i <= ndc; i++)
      for (int j = i; j <= ndc; j++)
        for (int k = i; k <= j; k++)
          ret.sq[i][j] = (ret.sq[i][j] + 1ll * sq[i][k] * a.sq[k][j]) % MOD;
    return ret;
  }
} trs, one;
inline matrix qpow(matrix x, int y) {
  matrix ret = one;
  while (y) {
    if (y & 1) ret = ret * x;
    x = x * x;
    y >>= 1;
  }
  return ret;
}
int idr[N], idg[N], cntc[N];
int main() {
  int i, j, k, ans = 0;
  scanf("%s%d", s + 1, &n);
  m = strlen(s + 1);
  idr[0] = ++ndc;
  for (i = 1; i < m; i++) {
    int rem = (m - i + 1) / 2;
    if ((m - i + 1) / 2 != (m - i) / 2 + 1) idg[(m - i) / 2 + 1] = ++ndc;
    idr[i] = ++ndc;
  }
  if (!idg[1]) idg[1] = ++ndc;
  idg[0] = ++ndc;
  for (i = 0; i < m; i++) {
    if (i) trs.sq[idr[i]][idr[i]] = 24;
    if (i < m - 1) trs.sq[idr[i]][idr[i + 1]] = 1;
  }
  for (i = (m + 1) / 2; i > 0; i--) {
    trs.sq[idg[i]][idg[i]] = 25;
    trs.sq[idg[i]][idg[i - 1]] = 1;
  }
  for (i = 1; i <= ndc; i++) one.sq[i][i] = 1;
  memset(f, -1, sizeof(f));
  for (i = 0; i < m; i++) {
    for (j = 1; j <= m; j++) {
      cntc[i] = (cntc[i] + getf(i, j, j)) % MOD;
      if (j < m && s[j] == s[j + 1])
        cntc[i] = (cntc[i] + getf(i, j, j + 1)) % MOD;
    }
  }
  for (i = 0; i < m; i++) trs.sq[idr[i]][idg[(m - i + 1) / 2]] = cntc[i];
  trs.sq[ndc][ndc] = 26;
  ans = (qpow(trs, (n + m + 1) / 2 + 1)).sq[1][ndc];
  if (!((n + m) & 1)) {
    printf("%d", ans);
    return 0;
  }
  memset(f, -1, sizeof(f));
  memset(cntc, 0, sizeof(cntc));
  for (i = 0; i < m; i++)
    for (j = 1; j < m; j++)
      if (s[j] == s[j + 1]) cntc[i] = (cntc[i] + getf(i, j, j + 1)) % MOD;
  for (i = 0; i < m; i++) trs.sq[idr[i]][idg[(m - i + 1) / 2]] = cntc[i];
  trs.sq[ndc][ndc] = 0;
  ans = (ans - (qpow(trs, (n + m + 1) / 2 + 1)).sq[1][ndc] + MOD) % MOD;
  printf("%d", ans);
  return 0;
}