#include <cstdio>
#include <cstring>

using namespace std;

const int mod = 998244353;
char s[301];
int a[300];
int dp[301][301][301][4];

int main() {
    int n, k, i, j, l, r;
    long long ans = 0;
    
    scanf("%s %d", s, &k);
    
    n = strlen(s);
    
    for (i = 0; i < n; i++) a[i] = s[i] - '0';
    
    dp[0][0][0][0] = 1;
    for (i = 0; i < n; i++) {
        for (j = 0; j < n; j++) {
            for (l = 0; l < n && l <= k; l++) {
                for (r = 0; r < 4; r++) {
                    if (dp[i][j][l][r] == 0) continue;
                    
                    if (a[i] == 0) {
                        dp[i + 1][j][l][0] += dp[i][j][l][r];
                        if (dp[i + 1][j][l][0] >= mod) dp[i + 1][j][l][0] -= mod;
                        
                        if (i > 0 && a[i - 1] == 1 && r >= 2) continue;
                        
                        dp[i][j + 1][l + 1][0] += dp[i][j][l][r];
                        if (dp[i][j + 1][l + 1][0] >= mod) dp[i][j + 1][l + 1][0] -= mod;
                    } else {
                        dp[i + 1][j][l][r | 1] += dp[i][j][l][r];
                        if (dp[i + 1][j][l][r | 1] >= mod) dp[i + 1][j][l][r | 1] -= mod;
                        
                        if (j > 0 && (r & 1) == 0) {
                            dp[i + 1][j - 1][l][r | 2] += dp[i][j][l][r];
                            if (dp[i + 1][j - 1][l][r | 2] >= mod) dp[i + 1][j - 1][l][r | 2] -= mod;
                        }
                    }
                }
            }
        }
    }
    
    for (i = 0; i <= k && i <= n; i++) {
        for (j = 0; j < 4; j++) {
            ans += dp[n][0][i][j];
        }
    }
    
    printf("%lld\n", ans % mod);
    
    return 0;
}

//#include<bits/stdc++.h>
#include<cstdio>
#include<algorithm>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define Would
#define you
#define please

const int cm = 1 << 17;
char cn[cm], * ci = cn + cm, ct;
inline char getcha() {
	if (ci - cn == cm) { fread(cn, 1, cm, stdin); ci = cn; }
	return *ci++;
}
inline int getint() {
	int A = 0;
	if (ci - cn + 16 > cm) while ((ct = getcha()) >= '0') A = A * 10 + ct - '0';
	else while ((ct = *ci++) >= '0') A = A * 10 + ct - '0';
	return A;
}

int main() {
	//cin.tie(0);
	//ios::sync_with_stdio(false);


	int N = getint();
	int A[200000];
	ll goukei = 0;
	rep(i, N) goukei += (A[i] = getint());


	ll kotae = 1e18;

	int q = 1, s = 3;
	ll PQ = A[0] - A[1];
	ll RS = -goukei + A[2] + A[0] + A[1] + A[2] ;
	ll diff = -goukei + A[0] + A[1] + A[0] + A[1];
	for (int r = 2; r < N - 1; r++) {
		while (abs(PQ) > abs(PQ + 2 * A[q])) {
			PQ += 2 * A[q];
			q++;
		}
		while (abs(RS) > abs(RS + 2 * A[s])) {
			RS += 2 * A[s];
			s++;
		}
		ll kari = max(abs(diff) + abs(PQ) + abs(RS), max(abs(PQ), abs(RS)) * 2);
		kotae = min(kotae, kari);

		PQ -= A[r];
		RS -= A[r];
		diff += 2 * A[r];
	}

	printf("%lld", kotae / 2);

	Would you please return 0;
}