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;
long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); }
const int MOD = 10007;
char s[201];
int slen;
int want;
int ways[101][201][201];
int cnt[101][201][2];
int n;
int A[401][401];
int B[401][401];
int C[401][401];
void mmult(int A[401][401], int B[401][401]) {
  for (int i = (0); i < (n); ++i)
    for (int j = (i); j < (n); ++j) {
      int c = 0;
      for (int k = (i); k <= (j); ++k) {
        c += A[i][k] * B[k][j];
        if (c > INT_MAX - MOD * MOD) c %= MOD;
      }
      C[i][j] = c % MOD;
    }
  for (int i = (0); i < (n); ++i)
    for (int j = (0); j < (n); ++j) A[i][j] = C[i][j];
}
void mpow(int k) {
  for (int i = (0); i < (n); ++i)
    for (int j = (0); j < (n); ++j) B[i][j] = A[i][j];
  for (int i = (0); i < (n); ++i)
    for (int j = (0); j < (n); ++j) A[i][j] = i == j ? 1 : 0;
  while (k > 0) {
    if (k & 1) mmult(A, B);
    k /= 2;
    if (k == 0)
      break;
    else
      mmult(B, B);
  }
}
void run() {
  scanf("%s%d", s, &want);
  slen = strlen(s);
  want += slen;
  memset(ways, 0, sizeof(ways));
  memset(cnt, 0, sizeof(cnt));
  ways[0][0][0] = 1;
  for (int a = (0); a <= (slen / 2); ++a)
    for (int b = (0); b <= (slen); ++b)
      for (int c = (0); c <= (slen); ++c)
        if (ways[a][b][c] > 0) {
          int p = a + b, q = slen - a - c;
          if (p >= q) {
            for (int i = (0); i < (want % 2 == 0 ? 1 : 26); ++i)
              if ((cnt[a][b + c][1] += ways[a][b][c]) >= MOD)
                cnt[a][b + c][1] -= MOD;
            ;
          } else if (p == q - 1) {
            if (want % 2 == 1)
              if ((cnt[a + 1][b + c][0] += ways[a][b][c]) >= MOD)
                cnt[a + 1][b + c][0] -= MOD;
            ;
            for (int i = (0); i < (want % 2 == 0 ? 1 : 26); ++i)
              if ((cnt[a + 1][b + c][1] += ways[a][b][c]) >= MOD)
                cnt[a + 1][b + c][1] -= MOD;
            ;
          } else if (s[p] == s[q - 1]) {
            if ((ways[a + 1][b][c] += ways[a][b][c]) >= MOD)
              ways[a + 1][b][c] -= MOD;
            ;
          } else {
            if ((ways[a][b + 1][c] += ways[a][b][c]) >= MOD)
              ways[a][b + 1][c] -= MOD;
            ;
            if ((ways[a][b][c + 1] += ways[a][b][c]) >= MOD)
              ways[a][b][c + 1] -= MOD;
            ;
          }
        }
  int maxC = slen, maxB = (slen + 1) / 2;
  n = maxC + maxB + maxB + 1;
  for (int i = (0); i < (n); ++i)
    for (int j = (0); j < (n); ++j) A[i][j] = 0;
  for (int i = (0); i < (maxC); ++i) A[i][i] = 24, A[i][i + 1] = 1;
  A[maxC - 1][maxC + maxB] = 1;
  for (int i = (maxC); i < (maxC + maxB); ++i)
    A[i][i] = 25, A[i][i + maxB + 1] = 1;
  for (int i = (maxC); i < (maxC + maxB - 1); ++i) A[i][i + 1] = 1;
  for (int i = (maxC + maxB); i < (maxC + maxB + maxB + 1); ++i) A[i][i] = 26;
  mpow(want / 2);
  int ret = 0;
  for (int b = (0); b <= ((slen + 1) / 2); ++b)
    for (int c = (0); c <= (slen); ++c)
      for (int d = (0); d < (2); ++d)
        if (cnt[b][c][d] > 0) {
          n = b + c + d;
          int i = c != 0   ? maxC - c
                  : b != 0 ? maxC
                           : maxC + maxB,
              j = d != 0   ? maxC + maxB + b
                  : b != 0 ? maxC + b - 1
                           : maxC - 1,
              cur = A[i][j];
          ret += cnt[b][c][d] * cur;
          if (ret > INT_MAX - MOD * MOD) ret %= MOD;
        }
  ret %= MOD;
  printf("%d\n", ret);
}
int main() {
  clock_t tStart = clock();
  run();
  fprintf(stderr, "Time taken: %.2fs\n",
          (double)(clock() - tStart) / CLOCKS_PER_SEC);
  return 0;
}