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 = 405;
const int mo = 10007;
char s[N];
int n;
int f[N][N][N];
long long len;
int k;
long long add(long long x, long long y) {
  return x + y >= mo ? x + y - mo : x + y;
}
int trs[N][N];
int ans[N];
int tv[N][N];
void twice() {
  for (int i = 1; i <= k; i++)
    for (int j = 1; j <= k; j++) {
      long long sum = 0;
      for (int x = 1; x <= k; x++) sum = sum + trs[i][x] * trs[x][j];
      tv[i][j] = sum % mo;
    }
  for (int i = 1; i <= k; i++)
    for (int j = 1; j <= k; j++) trs[i][j] = tv[i][j];
}
int tmp[N];
int main() {
  scanf("%s", s + 1);
  n = strlen(s + 1);
  scanf("%I64d", &len);
  len = len + n;
  f[1][n][0] = 1;
  for (int i = 1; i <= n; i++)
    for (int j = n; j >= i; j--)
      for (int k = 0; k <= min(i - 1, n - j); k++)
        if (f[i][j][k]) {
          if (s[i] == s[j])
            f[i + 1][j - 1][k + 1] = add(f[i + 1][j - 1][k + 1], f[i][j][k]);
          else {
            f[i + 1][j][k] = add(f[i + 1][j][k], f[i][j][k]);
            f[i][j - 1][k] = add(f[i][j - 1][k], f[i][j][k]);
          }
        }
  k = n * 2 + 2;
  for (int i = 1; i <= k; i++) ans[i] = 0;
  for (int i = 1; i <= k; i++)
    for (int j = 1; j <= k; j++) trs[i][j] = 0;
  for (int i = 1; i <= n; i++) trs[i][i] = 24;
  for (int i = 1; i <= n - 1; i++) trs[i][i + 1] = 1;
  for (int i = n + 1; i <= n * 2; i++) trs[i][i] = 25;
  for (int i = n + 1; i <= n * 2 - 1; i++) trs[i + 1][i] = 1;
  trs[n * 2 + 1][1] = 1;
  trs[n + 1][n * 2 + 2] = 1;
  trs[n * 2 + 2][n * 2 + 2] = 26;
  ans[n * 2 + 1] = 1;
  for (int i = 1; i <= n + 1; i++)
    for (int j = 0; j <= i - 1; j++)
      for (int k = 0; k <= min(i - 1, n - j); k++)
        if (f[i][j][k]) {
          int A = k, B = i - 1 + n - j - k * 2;
          int s = B == 0 ? n * 2 + 1 : B, t = A == 0 ? n * 2 + 2 : n + A;
          trs[s][t] = add(trs[s][t], f[i][j][k]);
        }
  long long tim = len / 2 + 1;
  for (; tim; tim /= 2, twice())
    if (tim & 1) {
      for (int i = 1; i <= k; i++) {
        long long sum = 0;
        for (int j = 1; j <= k; j++) sum = sum + 1ll * ans[j] * trs[j][i];
        tmp[i] = sum % mo;
      }
      for (int i = 1; i <= k; i++) ans[i] = tmp[i];
    }
  if (len % 2 == 0)
    printf("%d\n", ans[n * 2 + 2]);
  else {
    long long sum = ans[n * 2 + 2] * 26 % mo;
    for (int i = 1; i <= k; i++) ans[i] = 0;
    for (int i = 1; i <= k; i++)
      for (int j = 1; j <= k; j++) trs[i][j] = 0;
    for (int i = 1; i <= n; i++) trs[i][i] = 24;
    for (int i = 1; i <= n - 1; i++) trs[i][i + 1] = 1;
    for (int i = n + 1; i <= n * 2; i++) trs[i][i] = 25;
    for (int i = n + 1; i <= n * 2 - 1; i++) trs[i + 1][i] = 1;
    trs[n * 2 + 1][1] = 1;
    trs[n + 1][n * 2 + 2] = 1;
    trs[n * 2 + 2][n * 2 + 2] = 25;
    ans[n * 2 + 1] = 1;
    for (int i = 1; i <= n; i++) {
      for (int k = 0; k <= min(i - 1, n - i); k++)
        if (f[i][i][k]) {
          int A = k, B = i - 1 + n - i - k * 2;
          int s = B == 0 ? n * 2 + 1 : B, t = A == 0 ? n * 2 + 2 : n + A;
          trs[s][t] = add(trs[s][t], f[i][i][k]);
        }
    }
    long long tim = len / 2 + 1;
    for (; tim; tim /= 2, twice())
      if (tim & 1) {
        for (int i = 1; i <= k; i++) {
          long long sum = 0;
          for (int j = 1; j <= k; j++) sum = sum + 1ll * ans[j] * trs[j][i];
          tmp[i] = sum % mo;
        }
        for (int i = 1; i <= k; i++) ans[i] = tmp[i];
      }
    sum = (sum + ans[n * 2 + 2]) % mo;
    cout << sum << endl;
  }
  return 0;
}