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;
int cnt;
char st[210];
int m, num, n, anss;
int dp[210][210][210];
inline int mo(int x) {
  if (x >= MOD) return x - MOD;
  return x;
}
struct matrix {
  int num[305][305];
  inline matrix() { memset(num, 0, sizeof(num)); }
  void clear() { memset(num, 0, sizeof(num)); }
  inline friend matrix operator+(const matrix &a, const matrix &b) {
    matrix c;
    for (int i = 0; i <= cnt; i++)
      for (int j = i; j <= cnt; j++)
        c.num[i][j] = mo(a.num[i][j] + b.num[i][j]);
    return c;
  }
  inline friend matrix operator-(const matrix &a, const matrix &b) {
    matrix c;
    for (int i = 0; i <= cnt; i++)
      for (int j = i; j <= cnt; j++)
        c.num[i][j] = mo(a.num[i][j] - b.num[i][j] + MOD);
    return c;
  }
  inline friend matrix operator*(const matrix &a, const matrix &b) {
    matrix c;
    for (int i = 0; i <= cnt; i++)
      for (int j = i; j <= cnt; j++)
        for (int k = i; k <= j; k++)
          c.num[i][j] = mo(c.num[i][j] + 1ll * a.num[i][k] * b.num[k][j] % MOD);
    return c;
  }
};
int main() {
  int t;
  scanf("%s", st + 1);
  scanf("%d", &m);
  n = strlen(st + 1);
  num = (n + 1 + m) / 2;
  if (st[1] == st[n])
    dp[0][1][n] = 1;
  else
    dp[1][1][n] = 1;
  for (int i = n - 1; i >= 0; i--)
    for (int j = 1; j + i <= n; j++)
      for (int k = 0; k < n; k++)
        if (dp[k][j][j + i]) {
          int tot = dp[k][j][j + i], c;
          if (st[j] == st[j + i]) {
            if (i <= 1)
              dp[k][0][0] = mo(dp[k][0][0] + tot);
            else
              c = (st[j + 1] != st[j + i - 1]),
              dp[k + c][j + 1][j + i - 1] =
                  mo(dp[k + c][j + 1][j + i - 1] + tot);
          } else {
            c = st[j + 1] != st[j + i];
            dp[k + c][j + 1][j + i] = mo(dp[k + c][j + 1][j + i] + tot);
            c = st[j] != st[j + i - 1];
            dp[k + c][j][j + i - 1] = mo(dp[k + c][j][j + i - 1] + tot);
          }
        }
  cnt = n - 1 + (n + 1) / 2 + 1;
  matrix f;
  for (int i = 1; i <= n - 1; i++) f.num[i][i] = 24;
  for (int i = 0; i < n - 1; i++) f.num[i][i + 1] = 1;
  for (int i = n; i < cnt; i++) f.num[i][i] = 25;
  f.num[cnt][cnt] = 26;
  for (int i = n; i < cnt; i++) f.num[i][i + 1] = 1;
  for (int i = 0; i <= n - 1; i++)
    f.num[i][cnt - (n - i + 1) / 2] = dp[i][0][0];
  matrix ans;
  num++;
  ans.num[0][0] = 1, t = num;
  while (t) {
    if (t & 1) ans = ans * f;
    f = f * f;
    t /= 2;
  }
  anss = ans.num[0][cnt];
  if ((n + m) & 1) {
    memset(dp, 0, sizeof(dp));
    f.clear();
    ans.clear();
    if (st[1] == st[n])
      dp[0][1][n] = 1;
    else
      dp[1][1][n] = 1;
    for (int i = n - 1; i; i--)
      for (int j = 1; j + i <= n; j++)
        for (int k = 0; k < n; k++)
          if (dp[k][j][j + i]) {
            int tot = dp[k][j][j + i], c;
            if (st[j] == st[j + i]) {
              if (i <= 1)
                dp[k][0][0] = mo(dp[k][0][0] + tot);
              else
                c = (st[j + 1] != st[j + i - 1]),
                dp[k + c][j + 1][j + i - 1] =
                    mo(dp[k + c][j + 1][j + i - 1] + tot);
            } else {
              c = st[j + 1] != st[j + i];
              dp[k + c][j + 1][j + i] = mo(dp[k + c][j + 1][j + i] + tot);
              c = st[j] != st[j + i - 1];
              dp[k + c][j][j + i - 1] = mo(dp[k + c][j][j + i - 1] + tot);
            }
          }
    cnt = n - 1 + (n + 1) / 2 + 1;
    for (int i = 1; i <= n - 1; i++) f.num[i][i] = 24;
    for (int i = 0; i < n - 1; i++) f.num[i][i + 1] = 1;
    for (int i = n - 1 + 1; i < cnt; i++) f.num[i][i] = 25;
    for (int i = n - 1 + 1; i < cnt; i++) f.num[i][i + 1] = 1;
    for (int i = 0; i <= n - 1; i++)
      f.num[i][cnt - (n - i + 1) / 2] = dp[i][0][0];
    ans.num[0][0] = 1, t = num;
    while (t) {
      if (t & 1) ans = ans * f;
      f = f * f;
      t /= 2;
    }
    anss = mo(anss - ans.num[0][cnt] + MOD);
  }
  printf("%d\n", anss);
}