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 = 205, M = 305, mod = 10007;
int n, m, sz, ans, st, f[N][N][N];
char s[N];
struct mat {
  int v[M][M];
  void clear() { memset(v, 0, sizeof(v)); }
  mat() { clear(); }
  mat operator*(const mat& x) const {
    mat res;
    for (int i = 1; i <= sz; i++)
      for (int k = 1; k <= i; k++)
        for (int j = 1; j <= k; j++)
          (res.v[i][j] += v[i][k] * x.v[k][j]) %= mod;
    return res;
  }
} p, lst;
int dp(int x, int l, int r) {
  if (x < 0) return 0;
  int& d = f[x][l][r];
  if (~d) return d;
  if (l == 1 && r == m) return d = (!x);
  d = 0;
  if (l != 1 && s[l - 1] != s[r]) (d += dp(x - 1, l - 1, r)) %= mod;
  if (r != m && s[l] != s[r + 1]) (d += dp(x - 1, l, r + 1)) %= mod;
  if (l != 1 && r != m && s[l - 1] == s[r + 1])
    (d += dp(x, l - 1, r + 1)) %= mod;
  return d;
}
signed main() {
  scanf("%s%d", s + 1, &n);
  m = strlen(s + 1);
  sz = m + (m + 1) / 2;
  memset(f, -1, sizeof(f));
  for (int i = 0; i < m; i++) {
    int cnt = 0;
    for (int j = 1; j <= m; j++) (cnt += dp(i, j, j)) %= mod;
    for (int j = 1; j < m; j++)
      if (s[j] == s[j + 1]) (cnt += dp(i, j, j + 1)) %= mod;
    if (i)
      p.v[sz - (m - i + 1) / 2][i] = cnt;
    else
      st = cnt;
  }
  for (int i = 2; i < m; i++) p.v[i][i - 1] = 1;
  for (int i = m; i < sz; i++) p.v[i + 1][i] = 1;
  for (int i = 1; i < m; i++) p.v[i][i] = 24;
  for (int i = m; i < sz; i++) p.v[i][i] = 25;
  p.v[sz][sz] = 26;
  for (int i = 1; i <= sz; i++) lst.v[i][i] = 1;
  for (int i = (n + m + 1) / 2; i; i >>= 1, p = p * p)
    if (i & 1) lst = lst * p;
  if (m > 1) ans = lst.v[sz][1];
  (ans += st * lst.v[sz][m]) %= mod;
  if ((n + m) % 2 == 0) return printf("%d\n", ans), 0;
  lst.clear();
  p.clear();
  for (int i = 0; i < m; i++) {
    int cnt = 0;
    for (int j = 1; j < m; j++)
      if (s[j] == s[j + 1]) (cnt += dp(i, j, j + 1)) %= mod;
    if (i)
      p.v[sz - (m - i + 1) / 2][i] = cnt;
    else
      st = cnt;
  }
  for (int i = 2; i < m; i++) p.v[i][i - 1] = 1;
  for (int i = m; i < sz; i++) p.v[i + 1][i] = 1;
  for (int i = 1; i < m; i++) p.v[i][i] = 24;
  for (int i = m; i < sz; i++) p.v[i][i] = 25;
  for (int i = 1; i <= sz; i++) lst.v[i][i] = 1;
  for (int i = (n + m + 1) / 2; i; i >>= 1, p = p * p)
    if (i & 1) lst = lst * p;
  if (m > 1) ans -= lst.v[sz][1];
  (ans -= st * lst.v[sz][m]) %= mod;
  printf("%d\n", (ans + mod) % mod);
  return 0;
}