func_code_string: #include <bits/stdc++.h>   using namespace std;   const int N = 305, MOD = 1e4 + 7;   char s[N];   int n, m, ndc, f[N][N][N];   int getf(int cnt, int l, int r) {     if (cnt < 0) return 0;     if (~f[cnt][l][r]) return f[cnt][l][r];     if (l == 1 && r == m) return f[cnt][l][r] = !cnt;     int ret = 0;     if (l > 1 && r < m && s[l - 1] == s[r + 1])       ret = (ret + getf(cnt, l - 1, r + 1)) % MOD;     if (l > 1 && s[l - 1] != s[r]) ret = (ret + getf(cnt - 1, l - 1, r)) % MOD;     if (r < m && s[l] != s[r + 1]) ret = (ret + getf(cnt - 1, l, r + 1)) % MOD;     return f[cnt][l][r] = ret;   }   struct matrix {     int sq[N][N];     matrix() { memset(sq, 0, sizeof(sq)); }     matrix operator*(const matrix &a) const {       matrix ret;       for (int i = 1; i <= ndc; i++)         for (int j = i; j <= ndc; j++)           for (int k = i; k <= j; k++)             ret.sq[i][j] = (ret.sq[i][j] + 1ll * sq[i][k] * a.sq[k][j]) % MOD;       return ret;     }   } trs, one;   inline matrix qpow(matrix x, int y) {     matrix ret = one;     while (y) {       if (y & 1) ret = ret * x;       x = x * x;       y >>= 1;     }     return ret;   }   int idr[N], idg[N], cntc[N];   int main() {     int i, j, k, ans = 0;     scanf( %s%d , s + 1, &n);     m = strlen(s + 1);     idr[0] = ++ndc;     for (i = 1; i < m; i++) {       int rem = (m - i + 1) / 2;       if ((m - i + 1) / 2 != (m - i) / 2 + 1) idg[(m - i) / 2 + 1] = ++ndc;       idr[i] = ++ndc;     }     if (!idg[1]) idg[1] = ++ndc;     idg[0] = ++ndc;     for (i = 0; i < m; i++) {       if (i) trs.sq[idr[i]][idr[i]] = 24;       if (i < m - 1) trs.sq[idr[i]][idr[i + 1]] = 1;     }     for (i = (m + 1) / 2; i > 0; i--) {       trs.sq[idg[i]][idg[i]] = 25;       trs.sq[idg[i]][idg[i - 1]] = 1;     }     for (i = 1; i <= ndc; i++) one.sq[i][i] = 1;     memset(f, -1, sizeof(f));     for (i = 0; i < m; i++) {       for (j = 1; j <= m; j++) {         cntc[i] = (cntc[i] + getf(i, j, j)) % MOD;         if (j < m && s[j] == s[j + 1])           cntc[i] = (cntc[i] + getf(i, j, j + 1)) % MOD;       }     }     for (i = 0; i < m; i++) trs.sq[idr[i]][idg[(m - i + 1) / 2]] = cntc[i];     trs.sq[ndc][ndc] = 26;     ans = (qpow(trs, (n + m + 1) / 2 + 1)).sq[1][ndc];     if (!((n + m) & 1)) {       printf( %d , ans);       return 0;     }     memset(f, -1, sizeof(f));     memset(cntc, 0, sizeof(cntc));     for (i = 0; i < m; i++)       for (j = 1; j < m; j++)         if (s[j] == s[j + 1]) cntc[i] = (cntc[i] + getf(i, j, j + 1)) % MOD;     for (i = 0; i < m; i++) trs.sq[idr[i]][idg[(m - i + 1) / 2]] = cntc[i];     trs.sq[ndc][ndc] = 0;     ans = (ans - (qpow(trs, (n + m + 1) / 2 + 1)).sq[1][ndc] + MOD) % MOD;     printf( %d , ans);     return 0;   }   