Problem:
Score : 800 points

Problem Statement

Given is a string S consisting of 0 and 1. Find the number of strings, modulo 998244353, that can result from applying the following operation on S between 0 and K times (inclusive):

Choose a pair of integers i, j (1\leq i < j\leq |S|) such that the i-th and j-th characters of S are 0 and 1, respectively. Remove the j-th character from S and insert it to the immediate left of the i-th character.

Constraints

1 \leq |S| \leq 300

0 \leq K \leq 10^9

S consists of 0 and 1.

Input

Input is given from Standard Input in the following format:

S K

Output

Find the number of strings, modulo 998244353, that can result from applying the operation on S between 0 and K times (inclusive).

Sample Input 1

0101 1

Sample Output 1

4

Four strings, 0101, 0110, 1001, and 1010, can result.

Sample Input 2

01100110 2

Sample Output 2

14

Sample Input 3

1101010010101101110111100011011111011000111101110101010010101010101 20

Sample Output 3

113434815

Solution in C++ (GCC 9.2.1) (judge verdict: Accepted)

#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
constexpr int inf=1e9+7;
constexpr ll longinf=1LL<<60 ;
constexpr ll mod=998244353 ;


ll dp[333][333][333];
int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    string s;
    cin>>s;
    vector<int> a;
    int c=0,sum=0;
    rep(i,s.size()){
        if(s[i]=='0'){
            a.push_back(c);
            c=0;
        }
        else {
            c++;
            sum++;
        }
    }
    a.push_back(c);
    dp[0][0][0]=1;
    int m=a.size();
    rep(i,m)rep(j,301)rep(k,301){
        dp[i][j][k]%=mod;
        if(dp[i][j][k]==0)continue;
        rep(l,301){
            if(k+l-a[i]>=300)break;
            if(k+l>=a[i])dp[i+1][j+max(0,l-a[i])][k+l-a[i]]+=dp[i][j][k];
        }
    }
    int k;
    cin>>k;
    ll ans=0;
    rep(i,min(k+1,301))ans+=dp[m][i][0]%mod;
    cout<<ans%mod<<endl;;
    return 0;
}