/*
                             UM.
                            J@B@1                                                                    iO@1
                           Y@@@B@BB.                                                              7B@B@B@
                          :@B@i,B@B@O                                                          ,Z@B@B@B@Br
                          @B@q   i@B@BS                                                      7@B@@@O5vMB@q
                         8@@B      LB@B@i                                                  FB@@@BNjYjLE@B@
                        ,B@B:        0@@@Z                                               P@B@BM1JJ125JPB@B
                        B@BB          :@B@B                                            XB@B@Z2LuU52F2u2@B@.
                       :@B@             @@@B:                                        v@B@B8uJj51F1525uUB@B7
                       @B@O              0@@B.               ..::ir7vvYUuU777r::.   B@B@OULU2F2F151F11Y@B@S
                       B@B,               8B@B  :ruXMB@B@B@B@B@B@B@B@B@B@@@B@B@B@B@B@B@5Jj1211F1F1F2FUJO@BB
                      U@B@                 @B@B@B@B@B@@@B@B@B@MMqPS5JuYL7rq@B@OBB@B@B8Yu211F1515251515YGB@@
                      @B@u                 v@@@@MSur:.                    LB@MvvjJuU5YU252F1F1F25251F2uX@@@
                      @@@.                                                N@BML2U2UUU12F15252525251515Jk@@B
                     r@B@                                                 YB@Bju52121252515252F15251F2u5@B@
                     PB@B                                                  @@@PYUF151F25151F152F2F1F15jF@@B
                     @@BS                                                  N@@@UJ2F25252F251525151F1F1u5@B@
                     @@@7                                                   B@B@5Yj12F152F1F1F25252515jFB@B
                     B@Bi                                                    M@B@O2Luu52525212F151121UY1@B@7
                    O@B@:                                                     v@B@BMSuYJJuuUu2u2uujjYJJXB@B@M
                  7B@B@,                                                        1B@@@B@GPF1uujuu21PNMB@B@B@B@@
                 qB@B2                                                            i8B@B@B@B@B@@@@@B@B@B@q: @@@B
                MB@B:                                                                 7SBB@B@B@B@B@Zu:      @B@B
               ZB@B.                                              ,v.                                        @B@L
              LB@B,                         Y7                    @B@Bu                                      7@B@
   :B@B@@B2:  @@B7                         @B@Z                   r@B@B@BP:                                   B@BE
    BB@@@B@B@B@BE                        r@B@B                       7@B@B@B@Ou:                              iB@B
         :uM@@B@@2.           :7::::ivk@B@B@0                           :5B@B@B@B@B@B@G.                       @B@i
            BB@@@B@@         :@B@B@@@B@B@@1                                 .i5M@B@B@@@5                       M@@2
            B@B ,@B1          L0EZZG0F7:                                            .:,                        uB@MrP@M7
           2@B@                                                                                               ,O@B@B@B@B
           @B@1                                                     :@B@@@r                                :@@@@B@BL:,,
           B@Bi                         :2ZS;                      :@B@B@B@r                               L@B@B@BU
           @B@.                        @@@B@B@                     vB@B@B@B5                                   @B@i
           B@B                        7B@B@B@BM                     OB@B@B@                                   ,B@B
           @B@                         @B@B@@@i                       rL7.                                    B@BM
           B@B7.:                       NB@@M.                                                               .@B@.
  .;JEB@@@B@B@B@B@.                                                                                       .  @B@u
@@@B@B@B@B@@@B@18U                                                                                      :B@B@B@BU,
7@BOui.    ,@@B                                                                                          SP@B@B@B@B@Or
            @@@U                                                                                           B@BJ.YO@B@B@i
            r@B@                                                                                         :B@Bk     .k@B@
             B@B@                                                                                       LB@@k         2i
              B@BM                                      .7jXEGqF7:                                     OB@@L
              .B@BM                                   .B@B@B@B@B@B@.                                 :@B@B:
               .B@B@                                   @@MYr::ivG@B                                .M@B@G
                 B@@@S                                                                           ,MB@B@,
                  v@@@BF                                                                      .1B@B@Br
                    2@@B@BL                                                                ,FB@@@B8,
                      r@B@B@BF,                                                        :YBB@B@B@B
                         L@B@B@B@P7,                                           .ivXB@B@B@B@B@M@B@
                            ,1B@B@B@B@@@BOP2L7i:,.              ..,:i7LSNB@@B@B@@@B@B@B@Z5v;.LB@@
                              @B@OEB@B@@@B@B@B@B@B@B@B@B@@@B@B@B@B@B@@@B@B@B@B@BM0SJ7i::::i:,u@B@
                              B@Bu ::i;7vu2XNGOMB@B@BMB@B@B@B@B@B@@@B1UFuj77ii:::::::iir;r;i.YB@B
                              @B@L.:i:i:i::::::::::..Y@B@BMYi:i;SB@B@N:.::i:iirir;r;rii::::ivO@B@
                              B@@X::,::::iirir;riri:E@B@1         ,@B@Br:;;r;rii:i::::i7JEB@@@@@B
                              @@@B@BBq5v7ii:::::::.2@@@i  ..,..     @B@@,,:::::irv2XMB@B@B@B@2@B@:
                             .B@BBB@@@B@B@B@BMNP5u7@B@1 .,,:,,  :.   @B@P50MB@B@B@B@B@@@BS:   @@B1
                             E@B@   ijGB@B@B@B@B@B@B@Bi .,:,,..@@B@7 B@B@B@B@B@B@BM57.        kB@B
                            .@B@:          .,ivu5Nq@B@u  ..,.. SB@B@@@B@PL7i,                 ,@B@
                            @@@8                   i@B@:    .     :B@B@@                       B@@2
                          i@@@@                     0@B@u          B@@B.                       vB@B
                         ,@B@G                       L@B@BOv:.:iFB@B@M                          @B@Bi
                          vNi                          S@@B@B@B@B@BM:                            MB@N
                                                          758BMqJ,
										I       am        too        slow!!!!!!!!!!!!!
                 .  YO.               vq                            :G       Z:
        SqOMBB@B@Br @@r rBE           @B     B@@@@@B@ONX8k    i::::.OB1.:::.u@O.::::i           @B@B@U:@@B@@BPEBu
        B@@NB@k.    5@i  uB@E.        BM     1U2uUJvirB@@Z   r@@B@B@@@B@B@B@B@B@@@B@Bi   LB@B@1 BX :@k uLLLvr@BJ:
            iB      iBi    7@     .@M8@BGMZZ         @@F            ,B       Pi          v@  Bq @i v@        B@
       vuL7r8@S7vJL7N@Z7LLri;72.   F7@Bvvv@@       @BX         @@@B@B@@@@@B@@@B@B@B      7@  @F Bi @q  @B@Bu @B
       N@B@G@@@8@BBOMB@G@BMNXG@,     B@   @@      .Bk          .:u;    i@:      Zv       7@  Bk @,;@  ,BY @B B@
            r@       @G     5.      ,@v   BZ :::,.r@E .::i,      @B     B@    .@BL       7@  @F B:i@. .@  @M @B
            7B: ,vO, @@   iB@:      @B   7@:MB@B@B@@@B@B@BM       @@.    B:  2@q         7@  BS @i 0@  B. @O B@
       ,r2EBB@B@B@Bi G@  @BB        B@   @B        @S              :    r@   ..          7B  @F @7  B7 @  @B @B
       E@B@UOBr       @B@Bi          L@0PB        .BZ        .@B@B@B@B@B@B@B@B@B@B@B@,   r@  BF @i  @G B@B@B B@
            7@,      kB@U    ;r        @@@.       .@Z                GBuL@iBBi           vB@B@q BP:5@7 @u,.  @B
            LBi   YB@BrB@    @@       @B:L@Br      BM             .M@B  rB  rB@J         v@. Pi @XZ8r  .     B@
        .   G@i B@BM.  ,B@,  @B    iB@B    N, 7r..q@k         ,LB@B8    J@,   i@B@B1r           Br           @@
        MB@B@B  ,i       B@B@B,    B@:        @B@B@F         .@BB:      P@i      :OBZ          .@U       B@B@B:
                          .ll                                           rB.                     :
*/
//--------------------------------Informations-----------------------------------------
//Introduction: Written by vegetable_bird,e.g.,me.
//Hate things: DP(very much,(especially Tree_DP))
//Like things: brute force
//Submission OJ: codeforces
//Problem:
//Date:
//Status: Unknown
//--------------------------------Informations-----------------------------------------
#pragma comment(linker, "/stack:20000000")
#pragma warning(disable:4146)
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define _CRT_SECURE_NO_WARNINGS
//#define __NOT_WANT_TO_DEBUG__
#include <cassert>
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdalign>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <string>
#include <typeinfo>
#include <valarray>
#include <vector>
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <unordered_map>
#include <unordered_set>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef ull hash_type;
#define rep(i,n) for (int i=0;i<(n);i++)
#define Rep(i,a,b) for (int i=(a);i<=(b);i++)
#define repit(it,a) for (__typeof(a.begin()) it=a.begin();it!=a.end();++it)
#define eprintf(...) fprintf(stderr, __VA_ARGS__),fflush(stderr)
#define RET(p,x) return p<<x<<endl,0
#define all(a) (a).begin(),(a).end()
#define reunique(v) v.erase(unique(all(v)),v.end())
#define sz(a) (int)a.size()
#define pb push_back
#define eb emplace_back
#define X first
#define Y second
#define sqr(x) ((x)*(x))
#define assert(...) if (!__VA_ARGS__) throw 0
#if !defined(__NOT_WANT_TO_DEBUG__)
#define Debug(...) __debug_assistant(#__VA_ARGS__,__VA_ARGS__)
template<typename T>void __debug_assistant(const char* name,T&& t){cerr<<name<<" = "<<t<<endl;}
template<typename T1,typename... T>void __debug_assistant(const char* names,T1&& t1,T&&... t){const char* comma=strchr(names+1,',');cerr.write(names,comma-names)<<" = "<<t1<<", ";__debug_assistant(comma+1,t...);}
#else
#define Debug(...)
#endif
void print(){}
void print(int x){__builtin_printf("%d",x);}
void print(long long x){__builtin_printf("%lld",x);}
void print(char x){putchar(x);}
void print(const char *x){__builtin_printf("%s",x);}
void print(unsigned x){__builtin_printf("%u",x);}
void print(unsigned long long x){__builtin_printf("%llu",x);}
void print(float x){__builtin_printf("%.15f",x);}
void print(double x){__builtin_printf("%.15lf",x);}
void print(long double x){__builtin_printf("%.15lf",x);}
void print(const string &x){__builtin_printf("%s",x.c_str());}
template<typename Y,typename ...T>void print(Y t1,T ...t){print(t1);print(' ');print(t...);}
template<typename T>void print_arr(T a,T b){for(print(*a++);a!=b;++a){print(' ');print(*a);}}
#define println(...) print(__VA_ARGS__),__builtin_putchar('\n')
void input(){}
void input(int &x){__builtin_scanf("%d",&x);}
void input(long long &x){__builtin_scanf("%lld",&x);}
void input(char &x){__builtin_scanf("%c ",&x);}
void input(char *x){__builtin_scanf("%s",x);}
void input(unsigned &x){__builtin_scanf("%u",&x);}
void input(unsigned long long &x){__builtin_scanf("%llu",&x);}
void input(float &x){__builtin_scanf("%f",&x);}
void input(double &x){__builtin_scanf("%lf",&x);}
void input(long double &x){__builtin_scanf("%lf",&x);}
void input(string &x){char s[1000005];__builtin_scanf("%s",s);x=s;}
template<typename Y,typename ...T>void input(Y &t1,T &...t){input(t1);input(t...);}
template<typename T>void input_arr(T a,T b){for(;a!=b;++a){input(*a);}}
void inputline(string &x,char cc='\n'){for(char c=getchar();c!=cc;c=getchar())x+=cc;}
void inputline(char *x,char cc='\n'){string xx="";inputline(xx,cc);__builtin_memcpy(x,xx.c_str(),sizeof(x));}
vector<string> splitstring(const string&s,const string&c){vector<string> v;string::size_type pos1,pos2;pos2=s.find(c);pos1=0;while(string::npos!=pos2){v.push_back(s.substr(pos1,pos2-pos1));pos1=pos2+c.size();pos2=s.find(c,pos1);}if(pos1!=s.length())v.push_back(s.substr(pos1));}
ll gcd(ll a,ll b){while(b)b^=a^=b^=a%=b,Debug(a);return a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
inline ll fastpow(ll a,ll b,ll mod){ll c=1;while(b){if(b&1)c=c*a%mod;a=a*a%mod;b>>=1;}return c;}
inline ll fastpow(ll a,ll b){ll c=1;while(b){if(b&1)c*=a;a*=a;b>>=1;}return c;}
inline bool isprime(const ll &x){if(x<=4||x%2==0||x%3==0){return x==2||x==3;}for(int i=5;i*i<=x;i+=6){if(x%i==0||x%(i+2)==0){return false;}}return true;}
inline int reverse_bits(int x){x=((x>>1)&0x55555555)|((x<<1)&0xaaaaaaaa);x=((x>>2)&0x33333333)|((x<<2)&0xcccccccc);x=((x>>4)&0x0f0f0f0f)|((x<<4)&0xf0f0f0f0);x=((x>>8)&0x00ff00ff)|((x<<8)&0xff00ff00);x=((x>>16)&0x0000ffff)|((x<<16)&0xffff0000);return x;}
inline ll reverse_bits(ll x){x=((x>>1)&0x5555555555555555ll)|((x<<1)&0xaaaaaaaaaaaaaaaall);x=((x>>2)&0x3333333333333333ll)|((x<<2)&0xccccccccccccccccll);x=((x>>4)&0x0f0f0f0f0f0f0f0fll)|((x<<4)&0xf0f0f0f0f0f0f0f0ll);x=((x>>8)&0x00ff00ff00ff00ffll)|((x<<8)&0xff00ff00ff00ff00ll);x=((x>>16)&0x0000ffff0000ffffll)|((x<<16)&0xffff0000ffff0000ll);x=((x>>32)&0x00000000ffffffffll)|((x<<32)&0xffffffff00000000ll);return x;}
template<class T>inline bool odd(T x){return x&1;}template<class T>inline bool even(T x){return !odd(x);}
template<class T>inline T lowbit(T x){return x&-x;}template<class T>inline T highbit(T x){T p=lowbit(x);while(p!=x)x-=p,p=lowbit(x);return p;}
template<class T>inline T coverbit(T x){T p=1;while(p<x)p<<=1;return p;}
template<class T>inline int coveridx(T x){int p=0;while((1<<p)<x)++p;return p;}
inline int clz(int x){return __builtin_clz(x);}
inline int clz(ll x){return __builtin_clzll(x);}
inline int ctz(int x){return __builtin_ctz(x);}
inline int ctz(ll x){return __builtin_ctzll(x);}
inline int lg2(int x){return !x?-1:31-clz(x);}
inline int lg2(ll x){return !x?-1:63-clz(x);}
inline int lowidx(int x){return !x?-1:ctz(x);}
inline int lowidx(ll x){return !x?-1:ctz(x);}
inline int highidx(int x){return lg2(x);}
inline int highidx(ll x){return lg2(x);}
inline int parity(int x){return __builtin_parity(x);}
inline int parity(ll x){return __builtin_parityll(x);}
inline int count_bits(int x){return __builtin_popcount(x);}
inline int count_bits(ll x){return __builtin_popcountll(x);}
const short single_test=1;
const int inf=1e9;
const long long lnf=1e18;
const long long h1=239017,h2=731604233;
const long long mod=1000000007,mod2=1000000009;
const long double pi=3.141592653589793238462643383279;
const long double EPS=1e-9;
const int Maxn=3e2+3;
string s,t;
int k,ans;
int dp[Maxn][Maxn];
int dp2[Maxn][Maxn];
bool solve(const int &test)
{
	input(s,k);
	t=s;
	reverse(t.begin(),t.end());
	int n=sz(s);
	Rep(i,1,n)
	{
		Rep(j,1,n)
		{
			if (s[i-1]==t[j-1]) dp[i][j]=dp[i-1][j-1]+1;
			else dp[i][j]=max(dp[i-1][j],dp[i][j-1]);
		}
	}
	Rep(i,1,k)
	{
		memset(dp2,0,sizeof(dp2));
		Rep(i,1,n)
		{
			Rep(j,1,n)
			{
				if (s[i-1]==t[j-1]) dp2[i][j]=dp2[i-1][j-1]+1;
				else dp2[i][j]=max({dp2[i-1][j],dp2[i][j-1],dp[i-1][j-1]+1});
			}
		}
		memcpy(dp,dp2,sizeof(dp));
	}
	Rep(i,1,n-1) ans=max(ans,2*dp[i][n-i]);
	rep(i,n) ans=max(ans,2*dp[i][n-1-i]+1);
	println(ans);
}
void main_init()
{
}
signed main()
{
	main_init();
	int tests=single_test;
	if (!tests) __builtin_scanf("%d",&tests);
	else if (tests<0) tests=100000000;
	for (int test=1;test<=tests;++test)
		if (solve(test))
			break;
	return 0;
}

Measured memory_bytes: 1024