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: Runtime Error)

// -----------------------------------
// author   : MatsuTaku
// country  : Japan
// created  : 06/20/20 20:14:02
// -----------------------------------

#include <bits/stdc++.h>

using namespace std;
using ll = long long;

template <typename T, T MOD>
class modular {
 private:
  T val_;

 public:
  constexpr modular() : val_(0) {}
  constexpr modular(T v) : val_(v%MOD) {}
  constexpr modular& operator=(T v) { val_ = v%MOD; return *this; }

  constexpr T val() const { return val_; }
  constexpr modular operator+(modular x) const { return (val() + x.val())%MOD; }
  constexpr modular operator+=(modular x) { return *this = *this + x; }
  constexpr modular operator++() { return *this += 1; }
  constexpr modular operator++(int) { modular c = *this; ++(*this); return c; }
  constexpr modular operator-(modular x) const { return (val() + MOD - x.val())%MOD; }
  constexpr modular operator-=(modular x) { return *this = *this - x; }
  constexpr modular operator--() { return *this -= 1; }
  constexpr modular operator--(int) { modular c = *this; --(*this); return c; }
  constexpr modular operator*(modular x) const { return (val() * x.val())%MOD; }
  constexpr modular operator*=(modular x) { return *this = *this * x; }
  friend constexpr modular pow(modular x, T p) {
    modular t = 1;
    modular u = x;
    while (p) {
      if (p & 1)
        t *= u;
      u *= u;
      p >>= 1;
    }
    return t;
  }
  constexpr modular operator/(modular x) const { return *this * pow(modular{x}, MOD-2); }
  constexpr modular operator/=(modular x) { return *this = *this / x; }

  constexpr bool operator==(modular x) const { return val() == x.val(); }
  constexpr bool operator!=(modular x) const { return val() != x.val(); }
  constexpr bool operator<(modular x) const { return val() < x.val(); };
  constexpr bool operator<=(modular x) const { return val() <= x.val(); };
  constexpr bool operator>(modular x) const { return val() > x.val(); };
  constexpr bool operator>=(modular x) const { return val() >= x.val(); };

  friend std::ostream& operator<<(std::ostream& os, const modular& x) {
    return os << x.val();
  }
  friend std::istream& operator>>(std::istream& is, modular& x) {
    return is >> x.val_;
  }

};
using mint = modular<ll, 998244353>;

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

  string s; cin>>s;
  int k; cin>>k;
  vector<int> os;
  int co = 0;
  for (auto c:s) {
    if (c == '1')
      co++;
    else {
      os.push_back(co);
      co = 0;
    }
  }
  os.push_back(co);
  int n = os.size();
  vector<vector<mint>> dp[2];
  dp[0].resize(k+1, vector<mint>(k+1));
  dp[0].resize(k+1, vector<mint>(k+1));
  dp[0][0][0] = 1;
  int dpi = 0;
  for (int i = n-1; i >= 0; i--) {
    ++dpi;
    auto& nxt = dp[dpi%2];
    auto& pdp = dp[dpi%2^1];
    for (int i = 0; i <= k; i++) {
      copy(pdp[i].begin(), pdp[i].end(), nxt[i].begin());
    }
    // push
    for (int j = 1; j <= k; j++) {
      mint rsum = 0;
      for (int l = 0; l <= j; l++) {
        nxt[j][l] += rsum;
        rsum += pdp[j][l];
      }
    }
    // pop
    for (int l = 0; l <= k; l++) {
      mint rsum = 0;
      for (int j = 0; j <= k; j++) {
        nxt[j][l] += rsum;
        rsum += pdp[j][l];
        if (j-os[i] >= 0)
          rsum -= pdp[j-os[i]][l];
      }
    }
  }
  mint ans = 0;
  for (int l = 0; l <= k; l++) {
    ans += dp[dpi%2][l][l];
  }
  cout << ans << endl;

  return 0;
}