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 S = 205;
const long long K = 26, mod = 10007ll;
long long qpow(long long a, long long k) {
  long long res = 1ll;
  while (k) {
    if (k & 1) res = res * a % mod;
    a = a * a % mod, k >>= 1;
  }
  return res;
}
long long get_inv(long long x) {
  if (x == 1ll) return 1ll;
  return qpow(x, mod - 2);
}
struct poly {
  int deg;
  vector<long long> coef;
  poly() {
    deg = 0;
    coef.push_back(0ll);
  }
  poly(long long c) {
    deg = 0;
    coef.push_back(c);
  }
  long long get_coef(int k) const { return k <= deg ? coef[k] : 0ll; }
  poly& operator=(poly rhs) {
    deg = rhs.deg, coef = rhs.coef;
    return *this;
  }
  poly operator+(poly rhs) const {
    poly res;
    res.deg = max(deg, rhs.deg), res.coef.resize(res.deg + 1);
    for (int i = 0; i <= res.deg; i++)
      res.coef[i] = (get_coef(i) + rhs.get_coef(i)) % mod;
    while (res.coef.size() > 1 && !res.coef.back())
      res.deg--, res.coef.pop_back();
    return res;
  }
  poly operator-(poly rhs) const {
    poly res;
    res.deg = max(deg, rhs.deg), res.coef.resize(res.deg + 1);
    for (int i = 0; i <= res.deg; i++)
      res.coef[i] = (get_coef(i) + mod - rhs.get_coef(i)) % mod;
    while (res.coef.size() > 1 && !res.coef.back())
      res.deg--, res.coef.pop_back();
    return res;
  }
  poly operator+=(poly rhs) { return *this = *this + rhs; }
  poly operator-=(poly rhs) { return *this = *this - rhs; }
  poly operator*(poly rhs) const {
    poly res;
    res.deg = deg + rhs.deg, res.coef.resize(res.deg + 1);
    for (int i = 0; i <= deg; i++) {
      for (int j = 0; j <= rhs.deg; j++)
        res.coef[i + j] = (res.coef[i + j] + coef[i] * rhs.coef[j]) % mod;
    }
    return res;
  }
  poly operator%(poly rhs) const {
    poly res = *this;
    for (int i = deg; i >= rhs.deg; i--) {
      long long k = res.coef[i] * get_inv(rhs.coef[rhs.deg]) % mod;
      for (int j = 0; j <= rhs.deg; j++) {
        res.coef[i - rhs.deg + j] =
            (res.coef[i - rhs.deg + j] + mod * mod - rhs.coef[j] * k) % mod;
      }
    }
    while (res.coef.size() > 1 && !res.coef.back())
      res.deg--, res.coef.pop_back();
    return res;
  }
} f0, f1, f2, F, G, pw[S << 1], pw1[S << 1], pw2[S << 1], id;
int s, n;
char str[S];
long long f[S][S][S], tmp0[S], tmp1[S], tmp2[S];
long long calc(poly f, poly g, int k) {
  vector<long long> vec(g.deg);
  for (int i = 0; i < g.deg; i++) {
    vec[i] = f.get_coef(i);
    for (int j = 1; j <= i; j++)
      vec[i] = (vec[i] + mod * mod - g.coef[j] * vec[i - j]) % mod;
  }
  poly res(1ll), a = id, g_;
  g_.deg = g.deg, g_.coef.resize(g.deg + 1);
  for (int i = 0; i <= g.deg; i++) g_.coef[i] = g.coef[g.deg - i];
  while (k) {
    if (k & 1) res = res * a % g_;
    a = a * a % g_, k >>= 1;
  }
  long long ans = 0ll;
  for (int i = 0; i < g.deg; i++) ans = (ans + vec[i] * res.get_coef(i)) % mod;
  return ans;
}
int main() {
  scanf("%s", str + 1), s = strlen(str + 1);
  scanf("%d", &n);
  for (int i = 0; i <= s + 1; i++) {
    for (int j = 0; j <= s + 1; j++) {
      for (int k = 0; k <= s; k++) f[i][j][k] = 0ll;
    }
  }
  for (int i = 1; i <= s; i++) {
    for (int j = s; j >= i; j--) {
      for (int k = 0; k <= s; k++) {
        if (i == 1 && j == s && k == 0) f[i][j][k] = 1ll;
        if (str[i] == str[j])
          f[i + 1][j - 1][k + 1] = (f[i + 1][j - 1][k + 1] + f[i][j][k]) % mod;
        else {
          f[i + 1][j][k] = (f[i + 1][j][k] + f[i][j][k]) % mod;
          f[i][j - 1][k] = (f[i][j - 1][k] + f[i][j][k]) % mod;
        }
      }
    }
  }
  for (int i = 0; i <= s; i++) tmp0[i] = 0ll, tmp1[i] = tmp2[i] = 0ll;
  for (int i = 0; i <= s + 1; i++) {
    for (int j = 0; j <= s + 1; j++) {
      for (int k = 0; k <= s; k++) {
        if (i < j || !f[i][j][k]) continue;
        if (i - j == 1) tmp1[k] = (tmp1[k] + f[i][j][k]) % mod;
        if (i - j == 2) tmp2[k] = (tmp2[k] + f[i][j][k]) % mod;
        if (i == j && (n + s & 1)) tmp0[k] = (tmp0[k] + f[i][j][k]) % mod;
      }
    }
  }
  id.deg = 1, id.coef.resize(2);
  id.coef[1] = 1ll;
  f0.deg = f1.deg = f2.deg = 1;
  f0.coef.resize(2), f1.coef.resize(2), f2.coef.resize(2);
  f0.coef[0] = f1.coef[0] = f2.coef[0] = 1ll;
  f0.coef[1] = (mod - K) % mod, f1.coef[1] = (mod - K + 1) % mod,
  f2.coef[1] = (mod - K + 2) % mod;
  pw[0] = pw1[0] = pw2[0] = poly(1ll);
  for (int i = 1; i <= 2 * s; i++) {
    pw[i] = pw[i - 1] * id % mod;
    pw1[i] = pw1[i - 1] * f1 % mod;
    pw2[i] = pw2[i - 1] * f2 % mod;
  }
  G = f0 * pw1[s] * pw2[s + 1];
  for (int i = 0; i <= s; i++) {
    if (i < s)
      F +=
          poly(tmp0[i]) * pw[s - 1 - i] * f0 * pw1[s - 1 - i] * pw2[i + 1 << 1];
    if (n + s & 1)
      F += poly(tmp1[i] * K % mod) * pw[s - i] * pw1[s - i] * pw2[i << 1 | 1];
    else
      F += poly(tmp1[i]) * pw[s - i] * pw1[s - i] * pw2[i << 1 | 1];
    if (n + s & 1)
      F += poly(tmp2[i] * K % mod) * pw[s + 1 - i] * pw1[s - i] * pw2[i << 1];
    else
      F += poly(tmp2[i]) * pw[s + 1 - i] * pw1[s - i] * pw2[i << 1];
  }
  printf("%lld\n", calc(F, G, n + s >> 1));
  return 0;
}