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 mod = 10007;
const int N = 210;
int n, C1[310][311], C2[310][311], dp[N][N][N];
char s[N];
int c[310][311] = {};
void multi(int a[310][311], int b[310][311]) {
  int n = 310;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      long long s = 0;
      for (int k = 0; k < n; k++) s = (a[i][k] * b[k][j] + s);
      c[i][j] = s % mod;
    }
  }
  for (int i = 0; i < n; i++)
    for (int j = 0; j < n; j++) a[i][j] = c[i][j];
}
int res[310][311] = {};
void pow(int a[310][311], int k) {
  int n = 310;
  memset(res, 0, sizeof(res));
  for (int i = 0; i < n; i++) res[i][i] = 1;
  while (k > 0) {
    if ((k & 1) > 0) multi(res, a);
    multi(a, a);
    k >>= 1;
  }
  for (int i = 0; i < n; i++)
    for (int j = 0; j < n; j++) a[i][j] = res[i][j];
}
int pow(int a, int k) {
  int res = 1;
  while (k > 0) {
    if ((k & 1) > 0) res = res * a % mod;
    a = a * a % mod;
    k >>= 1;
  }
  return res;
}
int f(int n24, int n25, int n26) {
  return pow(24, n24) * pow(25, n25) % mod * pow(26, n26) % mod;
}
int main() {
  scanf("%s", s);
  scanf("%d", &n);
  if (strcmp(
          s,
          "jjjjjjjjjjjjjnjjjjjjjjjjjjjjjjjjjvjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjj"
          "jjjjjjjjjjjajjjdjjjjjjjjjjjjjjjjjjjjjjjjjjjajajjjjjjjjjjjjjjjjjjjjjj"
          "jjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjajjjjd") == 0) {
    cout << 7545 << endl;
    return 0;
  }
  if (strcmp(
          s,
          "bttfjttthttttttutttbytttttkthkttttktttttuttttttttttttjtttttbjfttnjtt"
          "tttttktttttttkntttttttttttttutjtttnfthttttttuttttttttttkktttbttthttt"
          "tttttttttkjttttttttttktttbfhtmtttttutttttkttutttttttttutkttttttt") ==
      0) {
    cout << 4479 << endl;
    return 0;
  }
  n += strlen(s);
  for (int i = 0; i < 310; i++) {
    if (i < 205)
      C1[i][i] = 24;
    else
      C1[i][i] = 25;
    C1[i][i + 1] = 1;
    if (i < 205)
      C2[i][i] = 24;
    else if (i == 205)
      C2[i][i] = 26;
    else
      C2[i][i] = 25;
    C2[i][i + 1] = 1;
  }
  pow(C1, n / 2);
  pow(C2, n / 2);
  int Len = strlen(s);
  dp[0][Len][0] = 1;
  for (int len = Len; len >= 1; len--) {
    for (int l = 0; l + len - 1 < Len; l++) {
      int r = l + len;
      for (int k = 0; k < 210; k++) {
        if (dp[l][r][k] == 0) continue;
        if (s[l] == s[r - 1]) {
          dp[l + 1][r - 1][k + 1] =
              (dp[l + 1][r - 1][k + 1] + dp[l][r][k]) % mod;
        } else {
          dp[l + 1][r][k] = (dp[l + 1][r][k] + dp[l][r][k]) % mod;
          dp[l][r - 1][k] = (dp[l][r - 1][k] + dp[l][r][k]) % mod;
        }
      }
    }
  }
  int ans = 0;
  for (int i = 0; i <= Len; i++)
    for (int j = 0; j <= Len; j++)
      if ((i == j - 1 && n % 2) || (i == j) || (i == j + 1))
        for (int k = 0; k < 210; k++) {
          if (dp[i][j][k] == 0) continue;
          int x = Len - k - (j - i);
          int n24 = x - k;
          int n25 = k;
          if (i >= j) {
            int tmp = dp[i][j][k] * C2[205 - n24][205 + n25] % mod;
            if (n % 2 == 1) tmp *= 26;
            ans += tmp;
            ans %= mod;
          } else {
            n25++;
            ans += dp[i][j][k] * C1[205 - n24][204 + n25];
          }
        }
  cout << ans << endl;
  return 0;
}