func_code_string: #include <bits/stdc++.h>   using namespace std;   template <class C>   void mini(C& a4, C b4) {     a4 = min(a4, b4);   }   template <class C>   void maxi(C& a4, C b4) {     a4 = max(a4, b4);   }   template <class T1, class T2>   ostream& operator<<(ostream& rout, pair<T1, T2> pair) {     return rout <<  (  << pair.first <<  ,   << pair.second <<  ) ;   }   const int P = 10007;   const int MN = 201;   vector<int> T[MN][MN];   vector<int> pw;   int rev[P];   const int S = 26;   int pot(int x, int n) {     int res = 1;     while (n) {       if (n & 1) res = (res * x) % P;       x = (x * x) % P;       n >>= 1;     }     return res;   }   int gauss(vector<vector<int> >& a, vector<int>& res) {     int n = a.size(), m = a[0].size() - 1;     res.resize(m);     for (__typeof((res).begin()) i = ((res).begin()); i != (res).end(); ++i)       *i = 0;     vector<int> wyb(n, -1);     for (int j = 0; j < (m); ++j) {       for (int i = 0; i < (n); ++i)         if (a[i][j] != 0 && wyb[i] == -1) {           wyb[i] = j;           if (a[i][j] < 0) a[i][j] += P;           int odw = rev[a[i][j]];           for (int jj = 0; jj < (m + 1); ++jj) a[i][jj] = (a[i][jj] * odw) % P;           for (int ii = 0; ii < (n); ++ii)             if (i != ii && a[ii][j] != 0) {               int wsp = a[ii][j];               for (int jj = 0; jj < (m + 1); ++jj)                 a[ii][jj] = (a[ii][jj] - wsp * a[i][jj]) % P;             }           break;         }     }     int dim = m - n;     for (int i = 0; i < (n); ++i)       if (wyb[i] == -1) {         dim++;         if (a[i][m] != 0) return -1;       } else         res[wyb[i]] = a[i][m];     for (__typeof((res).begin()) i = ((res).begin()); i != (res).end(); ++i)       if (*i < 0) *i += P;     return dim;   }   vector<int> solve(vector<int> vals, int n) {     int M = 2 * n + 1;     vector<vector<int> > A(M, vector<int>(M + 1, 0));     for (int j = 0; j < (3); ++j) {       A[0][j] = 1;       for (int _ = 0; _ < (n); ++_) A[0][j] = (A[0][j] * (S - j)) % P;     }     for (int i = (1); i <= (M - 1); ++i)       for (int j = 0; j < (3); ++j) A[i][j] = (A[i - 1][j] * (S - j)) % P;     for (int i = 0; i < (M); ++i) {       for (int j = (3); j <= (M - 1); ++j) A[i][j] = (A[i][j - 2] * (n + i)) % P;     }     for (int i = 0; i < (M); ++i) A[i][M] = vals[i + n];     vector<int> res(M);     int dim = gauss(A, res);     assert(dim != -1);     return res;   }   int main() {     ios_base::sync_with_stdio(false);     cout << fixed << setprecision(10);     for (int i = 0; i < (P); ++i) rev[i] = pot(i, P - 2);     string s;     int L;     cin >> s >> L;     int n = s.length();     L += n;     bool odd = (L % 2 == 1);     L = (L + 1) / 2;     int mx = 3 * n + 1;     pw = vector<int>(mx);     pw[0] = 1;     for (int j = (1); j <= (mx - 1); ++j) pw[j] = (pw[j - 1] * S) % P;     for (int j = 0; j < (n + 1); ++j)       for (int i = (j); i >= (0); --i) {         T[i][j] = vector<int>(mx);         for (int k = 0; k < (mx); ++k) {           if (j == i)             T[i][j][k] = pw[k];           else if (j == i + 1) {             if (k > 0) T[i][j][k] = (T[i][j][k - 1] * (S - 1) + pw[k - 1]) % P;           } else if (j == i + 2 && s[i] == s[j - 1] && k == 1 && odd)             T[i][j][k] = 0;           else if (k > 0) {             if (s[i] == s[j - 1])               T[i][j][k] =                   (T[i][j][k - 1] * (S - 1) + T[i + 1][j - 1][k - 1]) % P;             else               T[i][j][k] = (T[i][j][k - 1] * (S - 2) + T[i + 1][j][k - 1] +                             T[i][j - 1][k - 1]) %                            P;           }         }       }     if (L < n) {       cout << T[0][n][L] << endl;       return 0;     }     vector<int> coef = solve(T[0][n], n);     int M = 2 * n + 1;     vector<int> val(M);     for (int i = 0; i < (3); ++i) val[i] = pot(S - i, L);     for (int i = (3); i <= (M - 1); ++i) val[i] = ((long long)val[i - 2] * L) % P;     long long res = 0;     for (int i = 0; i < (M); ++i) res = (res + coef[i] * val[i]) % P;     cout << res << endl;     return 0;   }   