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, P = 10007, M = N * N;
char s[N];
int n, m, tmp[N << 1][N << 1], lim, tp[M];
inline void add(int &a, int b) { a = (a + b) % P; }
inline void mul(int &a, int b) { a = a * b % P; }
struct Graph {
  int head[M], v[M * 2], nxt[M * 2], ptr, dp[N][M];
  bool vis[N][M];
  inline void add_edge(int uu, int vv) {
    v[ptr] = vv;
    nxt[ptr] = head[uu];
    head[uu] = ptr++;
  }
  int dfs(int cnt, int pos) {
    if (cnt < 0) return 0;
    if (vis[cnt][pos]) return dp[cnt][pos];
    for (int i = head[pos]; i != -1; i = nxt[i])
      add(dp[cnt][pos], dfs(cnt - tp[pos], v[i]));
    vis[cnt][pos] = 1;
    return dp[cnt][pos];
  }
  Graph() {
    memset(head, -1, sizeof(head));
    memset(nxt, -1, sizeof(nxt));
  }
} g;
struct Matrix {
  int a[N << 1][N << 1];
  inline int *operator[](const size_t &x) { return a[x]; }
  inline const int *operator[](const size_t &x) const { return a[x]; }
  Matrix operator*=(const Matrix &b) {
    for (int i = 1; i <= lim; i++)
      for (int j = 1; j <= lim; j++) tmp[i][j] = 0;
    for (int i = 1; i <= lim; i++)
      for (int j = i; j <= lim; j++)
        for (int k = j; k <= lim; k++) add(tmp[i][k], a[i][j] * b[j][k]);
    for (int i = 1; i <= lim; i++)
      for (int j = 1; j <= lim; j++) a[i][j] = tmp[i][j];
    return *this;
  }
} ts, ret;
int id[N][N], idx, f[N], gg[N];
int main() {
  ios::sync_with_stdio(false);
  cin >> (s + 1) >> m;
  n = strlen(s + 1);
  for (int i = 1; i <= n; i++)
    for (int j = i; j <= n; j++) id[i][j] = ++idx;
  ++idx;
  for (int i = 1; i <= n; i++)
    for (int j = i; j <= n; j++)
      if (s[i] == s[j]) {
        if (j - i <= 1)
          g.add_edge(idx, id[i][j]);
        else
          g.add_edge(id[i + 1][j - 1], id[i][j]);
      } else {
        tp[id[i][j]] = 1;
        g.add_edge(id[i + 1][j], id[i][j]);
        g.add_edge(id[i][j - 1], id[i][j]);
      }
  for (int i = 0; i < n; i++) g.vis[i][id[1][n]] = 1;
  g.dp[tp[id[1][n]]][id[1][n]] = 1;
  for (int i = 0; i < n; i++) g.dfs(i, idx);
  for (int i = 1; i < n; i++) ts[i][i] = 24;
  int t = (n + 1) / 2;
  for (int i = 0; i < t; i++) ts[n + i][n + i] = 25;
  for (int i = 0; i < t; i++) ts[n + t + i][n + t + i] = 26;
  for (int i = 1; i < n + t - 1; i++) ++ts[i][i + 1];
  for (int i = 0; i < t; i++) ++ts[n + i][n + t + i];
  lim = n + t * 2 - 1;
  for (int i = 1; i <= lim; i++) ret[i][i] = 1;
  for (int p = (n + m) / 2; p > 0; p >>= 1, ts *= ts)
    if (p & 1) ret *= ts;
  for (int i = 0, v; i < n; i++)
    v = (n - i + 1) / 2, f[i] = ret[n - i][n + t + v - 1],
    gg[i] = ret[n - i][n + v - 1];
  int ans = 0;
  if ((n + m) & 1) {
    for (int i = 0; i < n; i++) add(ans, f[i] * g.dp[i][idx]);
    mul(ans, 26);
    for (int i = 1; i <= 26; i++)
      for (int j = 1; j <= n; j++)
        if (s[j] == 'a' + i - 1)
          for (int k = 0; k < n; k++) add(ans, gg[k] * g.dp[k][id[j][j]]);
  } else
    for (int i = 0; i < n; i++) add(ans, f[i] * g.dp[i][idx]);
  cout << ans << endl;
  return 0;
}