#include <bits/stdc++.h>
#define f(i,a,b) for(int i=a;i<=b;++i)
using namespace std;int M=998244353,N,K,a,s[303],d[303][303][303]={1};main(){string S;cin>>S>>K;K=min((int)S.size(),K);for(auto c:S)c=='0'?++N:++s[N];f(i,0,N)f(j,0,K)f(k,0,j)f(l,-min(k,s[i]),K-j)(d[i+1][j+max(l,0)][k+l]+=d[i][j][k])%=M;f(i,0,K)(a+=d[N+1][i][0])%=M;cout<<a;}
#include <bits/stdc++.h>
int m;
using namespace std;
const int N = 302;
string s;
int f[N][N][N];
int a[N];
int main() {
    ios_base::sync_with_stdio(0);
    cin >> s;
    cin >> m;
    for (int i = 0; i < s.size(); i++) a[i + 1] = s[i] - 'a';
    int n = s.size(); a[0] = -1; a[n + 1] = -1;
    f[1][n][0] = 0;
    for (int i = 1; i <= n; i++) {
        for (int j = n; j >= i; j--) {
            for (int k = 0; k <= m; k++) {
                f[i + 1][j][k] = max(f[i + 1][j][k], f[i][j][k]);
                f[i][j - 1][k] = max(f[i][j - 1][k], f[i][j][k]);
                if (a[i] != a[j]) {
                    f[i + 1][j - 1][k + 1] = max(f[i + 1][j - 1][k + 1], f[i][j][k] + 2 - (i == j));
                }
                else {
                    f[i + 1][j - 1][k] = max(f[i + 1][j - 1][k], f[i][j][k] + 2 - (i == j));
                }
            }
        }
    }
    int mx = 0;
    for (int i = 0; i <= n + 1; i++) {
        for (int j = 0; j <= n; j++) {
            for (int k = 0; k <= m; k++) {
                mx = max(mx, f[i][j][k]);
            }
        }
    }
    cout << mx << "\n";
    return 0;
}
