func_code_string: #include <bits/stdc++.h>   using namespace std;   const int N = 205;   const int mod = 10007;   void add(int &x, int y) {     x += y;     if (x >= mod) x -= mod;   }   int mul(int x, int y) { return x * y % mod; }   int pw(int x, int y) {     int ret = 1;     while (y) {       if (y & 1) ret = mul(ret, x);       x = mul(x, x);       y >>= 1;     }     return ret;   }   namespace berlekamp_massey {   vector<int> bm(vector<int> x) {     vector<int> rel, cur;     int lf, ld;     for (int i = 0; i < x.size(); ++i) {       int sum = 0;       for (int j = 0; j < cur.size(); ++j) add(sum, mul(x[i - j - 1], cur[j]));       if (sum == x[i]) continue;       if (!cur.size()) {         cur.resize(i + 1);         lf = i;         ld = sum - x[i];         add(ld, mod);         continue;       }       int coef = mul(sum - x[i] + mod, pw(ld, mod - 2));       vector<int> new_cur(i - lf - 1);       new_cur.push_back(coef);       for (int j = 0; j < rel.size(); ++j) {         new_cur.push_back(mul(mod - rel[j], coef));       }       if (new_cur.size() < cur.size()) new_cur.resize(cur.size());       for (int j = 0; j < cur.size(); ++j) add(new_cur[j], cur[j]);       if (i - lf + rel.size() >= cur.size()) {         rel = cur, lf = i, ld = sum - x[i];         add(ld, mod);       }       cur = new_cur;     }     return cur;   }   int sz;   int a[5005], rel[5005], tmp[5005];   int ff[5005], gg[5005];   void mulmod(int *p, int *q) {     for (int i = 0; i < sz + sz; ++i) tmp[i] = 0;     for (int i = 0; i < sz; ++i)       if (p[i]) {         for (int j = 0; j < sz; ++j) {           add(tmp[i + j], mul(p[i], q[j]));         }       }     for (int i = sz + sz - 1; i >= sz; --i)       if (tmp[i]) {         for (int j = sz - 1; j >= 0; --j) {           add(tmp[i - j - 1], mul(tmp[i], rel[j]));         }       }     for (int i = 0; i < sz; ++i) p[i] = tmp[i];   }   int solve(vector<int> x, int n) {     if (n < x.size()) return x[n];     vector<int> cur = bm(x);     sz = cur.size();     for (int i = 0; i < sz; ++i) rel[i] = cur[i], a[i] = x[i];     for (int i = 0; i < sz; ++i) ff[i] = gg[i] = 0;     ff[0] = 1;     if (sz > 1)       gg[1] = 1;     else       gg[0] = rel[0];     while (n) {       if (n & 1) mulmod(ff, gg);       mulmod(gg, gg);       n >>= 1;     }     int ret = 0;     for (int i = 0; i < sz; ++i) add(ret, mul(ff[i], a[i]));     return ret;   }   }  // namespace berlekamp_massey   using namespace berlekamp_massey;   int n, m;   string s;   int f[805][N][N], ans[1405];   vector<int> g;   int main() {     ios_base::sync_with_stdio(false);     cin >> s >> n;     m = s.size();     s =  ~  + s;     f[0][0][0] = 1;     int len = m + 1400 >> 1;     for (int i = 1; i <= len; ++i) {       for (int j = 0; j <= m; ++j) {         for (int k = 0; k <= m; ++k) {           if (f[i - 1][j][k] == 0) continue;           if (j == m && k == m)             add(f[i][j][k], mul(26, f[i - 1][j][k]));           else if (j == m) {             add(f[i][j][k], mul(25, f[i - 1][j][k]));             add(f[i][j][k + 1], f[i - 1][j][k]);           } else if (k == m) {             add(f[i][j][k], mul(25, f[i - 1][j][k]));             add(f[i][j + 1][k], f[i - 1][j][k]);           } else {             if (s[j + 1] == s[m + 1 - k - 1]) {               add(f[i][j + 1][k + 1], f[i - 1][j][k]);               add(f[i][j][k], mul(25, f[i - 1][j][k]));             } else {               add(f[i][j + 1][k], f[i - 1][j][k]);               add(f[i][j][k + 1], f[i - 1][j][k]);               add(f[i][j][k], mul(24, f[i - 1][j][k]));             }           }         }       }     }     for (int i = 0; i < 1400; ++i) {       int l = m + i >> 1;       for (int j = 0; j <= m; ++j) {         for (int k = 0; k <= m; ++k) {           if (j + k >= m) {             if (m + i & 1)               add(ans[i], mul(26, f[l][j][k]));             else               add(ans[i], f[l][j][k]);           }           if (j + k == m - 1) {             if (m + i & 1) add(ans[i], f[l][j][k]);           }         }       }     }     for (int i = 0; i < 1400; ++i) g.push_back(ans[i]);     cout << solve(g, n) <<   n ;     return 0;   }   