prithivMLmods/Coder-Stat huggingface dataset:
Problem p02634 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int inf = 1e9 + 7;
const int N = 3 * 1e3 + 1;
const int MOD = 998244353;
int dp[N][N];
signed main() {
  ios_base::sync_with_stdio(NULL);
  cin.tie(0);
  cout.tie(0);
  int a, b, c, d;
  cin >> a >> b >> c >> d;
  dp[a][b] = 1;
  for (int i = a; i <= c; i++)
    for (int j = b; j <= d; j++) {
      dp[i + 1][j] += j * dp[i][j];
      dp[i][j + 1] += i * dp[i][j];
      dp[i + 1][j] %= MOD;
      dp[i][j + 1] %= MOD;
      dp[i + 1][j + 1] -= (dp[i][j] * (i) * (j) % MOD);
      dp[i + 1][j + 1] += MOD;
      dp[i + 1][j + 1] %= MOD;
    }
  cout << dp[c][d] << '\n';
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int inf = 1e9 + 7;
const int N = 3 * 1e3 + 111;
const int MOD = 998244353;
int dp[N][N];
signed main() {
  ios_base::sync_with_stdio(NULL);
  cin.tie(0);
  cout.tie(0);
  int a, b, c, d;
  cin >> a >> b >> c >> d;
  dp[a][b] = 1;
  for (int i = a; i <= c; i++)
    for (int j = b; j <= d; j++) {
      dp[i + 1][j] += j * dp[i][j];
      dp[i][j + 1] += i * dp[i][j];
      dp[i + 1][j] %= MOD;
      dp[i][j + 1] %= MOD;
      dp[i + 1][j + 1] -= (dp[i][j] * (i) * (j) % MOD);
      dp[i + 1][j + 1] += MOD;
      dp[i + 1][j + 1] %= MOD;
    }
  cout << dp[c][d] << '\n';
  return 0;
}
Problem p02634 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <iostream>
using namespace std;
const long long mod = 998244353;
int main(void) {
  long long A, B, C, D;
  cin >> A >> B >> C >> D;
  long long DP[3001][3001];
  DP[A][B] = 1;
  long long ans = 0;
  long long N;

  long long i, j, t, k;
  for (i = A + 1; i < C + 1; i++) {
    DP[i][B] = DP[i - 1][B] * B % mod;
  }
  for (i = B + 1; i < D + 1; i++) {
    DP[A][i] = DP[A][i - 1] * A % mod;
  }
  N = (C - A) + (D - B) + 1;
  for (i = 2; i < N; i++) {
    long long s = max((long long)0, i - (D - B));
    long long g = min(i, C - A + 1);
    for (j = s; j < g; j++) {
      int x = A + j;
      int y = B + i - j;
      DP[x][y] = (DP[x - 1][y] * y + DP[x][y - 1] * x) % mod;
      DP[x][y] -= DP[x - 1][y - 1] * (x - 1) * (y - 1);
      while (DP[x][y] < 0) {
        DP[x][y] += mod;
      }
    }
  }
  cout << DP[C][D] << endl;
}


Fixed submission:
#include <algorithm>
#include <iostream>
using namespace std;
const long long mod = 998244353;
int main(void) {
  long long A, B, C, D;
  cin >> A >> B >> C >> D;
  long long DP[3001][3001];
  DP[A][B] = 1;
  long long ans = 0;
  long long N;

  long long i, j, t, k;
  for (i = A + 1; i < C + 1; i++) {
    DP[i][B] = DP[i - 1][B] * B % mod;
  }
  for (i = B + 1; i < D + 1; i++) {
    DP[A][i] = DP[A][i - 1] * A % mod;
  }
  N = (C - A) + (D - B) + 1;
  for (i = 2; i < N; i++) {
    long long s = max((long long)0, i - (D - B));
    long long g = min(i, C - A + 1);
    for (j = s; j < g; j++) {
      int x = A + j;
      int y = B + i - j;
      DP[x][y] = (DP[x - 1][y] * y + DP[x][y - 1] * x) % mod;
      DP[x][y] -= DP[x - 1][y - 1] * (x - 1) * (y - 1) % mod;
      while (DP[x][y] < 0) {
        DP[x][y] += mod;
      }
    }
  }
  cout << DP[C][D] << endl;
}
Problem p02635 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define REP(i, m, n) for (int i = (int)(m); i < (int)(n); i++)
#define rep(i, n) REP(i, 0, n)
#define RREP(i, m, n) for (int i = (int)(m); i >= (int)(n); i--)
#define rrep(i, n) RREP(i, n - 1, 0)
#define all(v) v.begin(), v.end()
const int inf = 1e9 + 7;
const ll longinf = 1LL << 60;
const ll mod = 998244353;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  string S;
  ll K;
  cin >> S >> K;
  int N = S.size();
  int cnt = 0;
  vector<int> C;
  rep(i, N) {
    if (S[i] == '1')
      cnt++;
    else {
      C.push_back(cnt);
      cnt = 0;
    }
  }
  C.push_back(cnt);
  reverse(all(C));
  int n = C.size();
  int m = accumulate(all(C), 0);
  vector<vector<vector<ll>>> dp(n + 1,
                                vector<vector<ll>>(m + 1, vector<ll>(m + 1)));
  dp[0][0][0] = 1;
  rep(i, n) {       // i番目の区間
    rep(j, m + 1) { // 取り出した回数
      if (j > K)
        continue;
      rep(k, m + 1) { // 挿入した回数
        int rem = j - k;
        if (rem < 0)
          continue;
        rep(l, rem + 1) { // ここで挿入する回数
          (dp[i + 1][j][k + l] += dp[i][j][k]) %= mod;
        }
        rep(l, C[i] + 1) { // ここで取り出す回数
          if (j + l > m)
            continue;
          if (l == 0)
            continue;
          (dp[i + 1][j + l][k] += dp[i][j][k]) %= mod;
        }
      }
    }
  }
  ll ans = 0;
  rep(i, K + 1)(ans += dp[n][i][i]) %= mod;
  cout << ans << endl;
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define REP(i, m, n) for (int i = (int)(m); i < (int)(n); i++)
#define rep(i, n) REP(i, 0, n)
#define RREP(i, m, n) for (int i = (int)(m); i >= (int)(n); i--)
#define rrep(i, n) RREP(i, n - 1, 0)
#define all(v) v.begin(), v.end()
const int inf = 1e9 + 7;
const ll longinf = 1LL << 60;
const ll mod = 998244353;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  string S;
  ll K;
  cin >> S >> K;
  int N = S.size();
  int cnt = 0;
  vector<int> C;
  rep(i, N) {
    if (S[i] == '1')
      cnt++;
    else {
      C.push_back(cnt);
      cnt = 0;
    }
  }
  C.push_back(cnt);
  reverse(all(C));
  int n = C.size();
  int m = accumulate(all(C), 0);
  vector<vector<vector<ll>>> dp(n + 1,
                                vector<vector<ll>>(m + 1, vector<ll>(m + 1)));
  dp[0][0][0] = 1;
  rep(i, n) {       // i番目の区間
    rep(j, m + 1) { // 取り出した回数
      if (j > K)
        continue;
      rep(k, m + 1) { // 挿入した回数
        int rem = j - k;
        if (rem < 0)
          continue;
        rep(l, rem + 1) { // ここで挿入する回数
          (dp[i + 1][j][k + l] += dp[i][j][k]) %= mod;
        }
        rep(l, C[i] + 1) { // ここで取り出す回数
          if (j + l > m)
            continue;
          if (l == 0)
            continue;
          (dp[i + 1][j + l][k] += dp[i][j][k]) %= mod;
        }
      }
    }
  }
  ll ans = 0;
  rep(i, min(K + 1, (ll)m + 1))(ans += dp[n][i][i]) %= mod;
  cout << ans << endl;
  return 0;
}
Problem p02635 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>

using namespace std;

typedef long long lol;
const int mod = 998244353;
inline int pls(int a, int b) {
  a += b - mod;
  return a + (a >> 31 & mod);
}
inline int mns(int a, int b) {
  a -= b;
  return a + (a >> 31 & mod);
}
inline void inc(int &a, int b) {
  a += b - mod;
  a += a >> 31 & mod;
}
inline void dec(int &a, int b) {
  a -= b;
  a += a >> 31 & mod;
}
inline int fpow(int base, int k) {
  int res = 1;
  while (k) {
    if (k & 1)
      res = (lol)res * base % mod;
    base = (lol)base * base % mod;
    k >>= 1;
  }
  return res;
}
int _w;

const int N = 3e2 + 5;

int f[N][N][N], n, k, sum[N], m, ss[N];
char str[N];

int main(void) {
  _w = scanf("%s%d", str + 1, &k);
  n = strlen(str + 1);
  str[n + 1] = '0';
  for (int i = 0, r; i <= n; i = r) {
    r = i + 1;
    while (r <= n && str[r] != '0')
      ++r;
    sum[++m] = r - i - 1;
  }
  for (int i = m; i; --i)
    ss[i] = ss[i + 1] + sum[i];
  f[0][0][0] = 1;
  for (int i = 1, s = 0; i <= m; s += sum[i], ++i)
    for (int j = s; j <= ss[1]; ++j)
      for (int l = 0; l <= k; ++l)
        if (f[i - 1][j][l])
          for (int p = 0; p + j <= ss[1] && l + p - sum[i] <= k; ++p) {
            inc(f[i][j + p][l + max(p - sum[i], 0)], f[i - 1][j][l]);
          }
  int ans = 0;
  for (int i = 0; i <= k; ++i)
    inc(ans, f[m][ss[1]][i]);
  printf("%d", ans);
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>

using namespace std;

typedef long long lol;
const int mod = 998244353;
inline int pls(int a, int b) {
  a += b - mod;
  return a + (a >> 31 & mod);
}
inline int mns(int a, int b) {
  a -= b;
  return a + (a >> 31 & mod);
}
inline void inc(int &a, int b) {
  a += b - mod;
  a += a >> 31 & mod;
}
inline void dec(int &a, int b) {
  a -= b;
  a += a >> 31 & mod;
}
inline int fpow(int base, int k) {
  int res = 1;
  while (k) {
    if (k & 1)
      res = (lol)res * base % mod;
    base = (lol)base * base % mod;
    k >>= 1;
  }
  return res;
}
int _w;

const int N = 3e2 + 5;

int f[N][N][N], n, k, sum[N], m, ss[N];
char str[N];

int main(void) {
  _w = scanf("%s%d", str + 1, &k);
  n = strlen(str + 1);
  str[n + 1] = '0';
  for (int i = 0, r; i <= n; i = r) {
    r = i + 1;
    while (r <= n && str[r] != '0')
      ++r;
    sum[++m] = r - i - 1;
  }
  for (int i = m; i; --i)
    ss[i] = ss[i + 1] + sum[i];
  k = min(k, ss[1]);
  f[0][0][0] = 1;
  for (int i = 1, s = 0; i <= m; s += sum[i], ++i)
    for (int j = s; j <= ss[1]; ++j)
      for (int l = 0; l <= k; ++l)
        if (f[i - 1][j][l])
          for (int p = 0; p + j <= ss[1] && l + p - sum[i] <= k; ++p) {
            inc(f[i][j + p][l + max(p - sum[i], 0)], f[i - 1][j][l]);
          }
  int ans = 0;
  for (int i = 0; i <= k; ++i)
    inc(ans, f[m][ss[1]][i]);
  printf("%d", ans);
  return 0;
}
Problem p02635 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;

string S;
ll N;
ll K;
vector<ll> A;
ll M;
vector<vector<vector<ll>>> Dp;
const ll MOD = 998244353;
ll Res;

int main() {
  cin >> S >> K;
  N = S.size();
  reverse(S.begin(), S.end());
  ll now = 0;
  for (char c : S) {
    if (c == '0') {
      A.push_back(now);
      now = 0;
    } else {
      ++now;
    }
  }
  A.push_back(now);
  M = A.size();
  Dp.resize(M + 1);
  for (auto &Dpi : Dp) {
    Dpi.resize(N + 1);
    for (auto &Dpij : Dpi)
      Dpij.resize(K + 1);
  }
  Dp[0][0][0] = 1;
  for (ll i = 0; i < M; ++i) {
    for (ll j = N; j >= 0; --j) {
      for (ll k = 0; k <= K; ++k) {
        (Dp[i + 1][j][k] += Dp[i][j][k]) %= MOD;
        if (j != N) {
          (Dp[i + 1][j][k] += Dp[i + 1][j + 1][k]) %= MOD;
        }
      }
    }
    for (ll j = 0; j <= N; ++j) {
      for (ll k = 0; k <= K; ++k) {
        for (ll a = 1; a <= A[i] && j + a <= N && k + a <= K; ++a) {
          (Dp[i + 1][j + a][k + a] += Dp[i][j][k]) %= MOD;
        }
      }
    }
  }
  for (ll k = 0; k <= K; ++k) {
    (Res += Dp[M][0][k]) %= MOD;
  }
  cout << Res << endl;
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;

string S;
ll N;
ll K;
vector<ll> A;
ll M;
vector<vector<vector<ll>>> Dp;
const ll MOD = 998244353;
ll Res;

int main() {
  cin >> S >> K;
  N = S.size();
  K = min(N, K);
  reverse(S.begin(), S.end());
  ll now = 0;
  for (char c : S) {
    if (c == '0') {
      A.push_back(now);
      now = 0;
    } else {
      ++now;
    }
  }
  A.push_back(now);
  M = A.size();
  Dp.resize(M + 1);
  for (auto &Dpi : Dp) {
    Dpi.resize(N + 1);
    for (auto &Dpij : Dpi)
      Dpij.resize(K + 1);
  }
  Dp[0][0][0] = 1;
  for (ll i = 0; i < M; ++i) {
    for (ll j = N; j >= 0; --j) {
      for (ll k = 0; k <= K; ++k) {
        (Dp[i + 1][j][k] += Dp[i][j][k]) %= MOD;
        if (j != N) {
          (Dp[i + 1][j][k] += Dp[i + 1][j + 1][k]) %= MOD;
        }
      }
    }
    for (ll j = 0; j <= N; ++j) {
      for (ll k = 0; k <= K; ++k) {
        for (ll a = 1; a <= A[i] && j + a <= N && k + a <= K; ++a) {
          (Dp[i + 1][j + a][k + a] += Dp[i][j][k]) %= MOD;
        }
      }
    }
  }
  for (ll k = 0; k <= K; ++k) {
    (Res += Dp[M][0][k]) %= MOD;
  }
  cout << Res << endl;
  return 0;
}
Problem p02635 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int MAX = 510000;
const int MOD = 998244353;

signed main() {
  string s;
  int K;
  cin >> s >> K;
  vector<int> c;
  c.push_back(0);
  int t = 0;
  for (auto &&i : s) {
    if (i == '0')
      c.push_back(0);
    else {
      c[c.size() - 1]++;
      t++;
    }
  }
  int dp[c.size() + 1][t + 1][301];
  for (int i = 0; i <= t; i++)
    fill(dp[0][i], dp[0][i] + 301, 0);
  dp[0][0][0] = 1;
  int o = 0;
  for (int i = 1; i <= c.size(); i++) {
    o += c[i - 1];
    for (int j = 0; j <= t; j++)
      fill(dp[i][j], dp[i][j] + 301, 0);
    for (int j = 0; j <= t; j++)
      for (int k = 0; k < 301; k++)
        for (int j2 = 0; j2 <= j; j2++)
          if (k - max(j - j2 - c[i - 1], 0ll) >= 0 && j >= o)
            dp[i][j][k] =
                (dp[i][j][k] + dp[i - 1][j2][k - max(j - j2 - c[i - 1], 0ll)]) %
                MOD;
  }
  int ans = 0;
  for (int i = 0; i <= min(K, 301ll); i++) {
    ans = (ans + dp[c.size()][t][i]) % MOD;
  } // cerr<<dp[c.size()][t][i]<<endl;}

  cout << ans << endl;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int MAX = 510000;
const int MOD = 998244353;

signed main() {
  string s;
  int K;
  cin >> s >> K;
  vector<int> c;
  c.push_back(0);
  int t = 0;
  for (auto &&i : s) {
    if (i == '0')
      c.push_back(0);
    else {
      c[c.size() - 1]++;
      t++;
    }
  }
  int dp[c.size() + 1][t + 1][301];
  for (int i = 0; i <= t; i++)
    fill(dp[0][i], dp[0][i] + 301, 0);
  dp[0][0][0] = 1;
  int o = 0;
  for (int i = 1; i <= c.size(); i++) {
    o += c[i - 1];
    for (int j = 0; j <= t; j++)
      fill(dp[i][j], dp[i][j] + 301, 0);
    for (int j = 0; j <= t; j++)
      for (int k = 0; k < 301; k++)
        for (int j2 = 0; j2 <= j; j2++)
          if (k - max(j - j2 - c[i - 1], 0ll) >= 0 && j >= o)
            dp[i][j][k] =
                (dp[i][j][k] + dp[i - 1][j2][k - max(j - j2 - c[i - 1], 0ll)]) %
                MOD;
  }
  int ans = 0;
  for (int i = 0; i <= min(K, 300ll); i++) {
    ans = (ans + dp[c.size()][t][i]) % MOD;
  } // cerr<<dp[c.size()][t][i]<<endl;}

  cout << ans << endl;
}
Problem p02635 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
const int maxn = 300 + 10;
typedef long long ll;
const ll mod = 998244353;
int tot, K;
char s[maxn];
int a[maxn];
ll f[maxn][maxn][maxn];
ll ans;
inline ll norm(const ll &x) { return x >= mod ? x - mod : x; }
int main() {
  scanf("%s%d", s + 1, &K);
  int len = strlen(s + 1);
  reverse(s + 1, s + len + 1);
  int cur = 0;
  for (int i = 1; i <= len; ++i)
    if (s[i] == '0') {
      a[++tot] = cur;
      cur = 0;
    } else
      ++cur;
  a[++tot] = cur;
  f[0][0][0] = 1;
  for (int i = 1; i <= tot; ++i)
    for (int k = 0; k <= K; ++k) {
      for (int j = k; ~j; --j)
        f[i][j][k] = norm(f[i - 1][j][k] + f[i][j + 1][k]);
      for (int j = 0; j <= k; ++j) {
        /*
        for(int jd = j; jd <= k; ++jd)
                f[i][j][k] = (f[i][j][k] + f[i - 1][jd][k]) % mod;
        */
        int lim = min(j, a[i]);
        for (int jd = 1; jd <= lim; ++jd)
          f[i][j][k] = norm(f[i][j][k] + f[i - 1][j - jd][k - jd]);
      }
    }
  for (int k = 0; k <= K; ++k)
    ans = norm(ans + f[tot][0][k]);
  cout << ans << endl;
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
const int maxn = 300 + 10;
typedef long long ll;
const ll mod = 998244353;
int tot, K;
char s[maxn];
int a[maxn];
ll f[maxn][maxn][maxn];
ll ans;
inline ll norm(const ll &x) { return x >= mod ? x - mod : x; }
int main() {
  scanf("%s%d", s + 1, &K);
  K = min(K, 300);
  int len = strlen(s + 1);
  reverse(s + 1, s + len + 1);
  int cur = 0;
  for (int i = 1; i <= len; ++i)
    if (s[i] == '0') {
      a[++tot] = cur;
      cur = 0;
    } else
      ++cur;
  a[++tot] = cur;
  f[0][0][0] = 1;
  for (int i = 1; i <= tot; ++i)
    for (int k = 0; k <= K; ++k) {
      for (int j = k; ~j; --j)
        f[i][j][k] = norm(f[i - 1][j][k] + f[i][j + 1][k]);
      for (int j = 0; j <= k; ++j) {
        /*
        for(int jd = j; jd <= k; ++jd)
                f[i][j][k] = (f[i][j][k] + f[i - 1][jd][k]) % mod;
        */
        int lim = min(j, a[i]);
        for (int jd = 1; jd <= lim; ++jd)
          f[i][j][k] = norm(f[i][j][k] + f[i - 1][j - jd][k - jd]);
      }
    }
  for (int k = 0; k <= K; ++k)
    ans = norm(ans + f[tot][0][k]);
  cout << ans << endl;
  return 0;
}
Problem p02635 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
#define rep(i, a, b) for (int i = (a); i <= (b); ++i)
#define rrep(i, a, b) for (int i = (a); i >= (b); --i)
#define PB push_back
#define ar2 array<int, 2>
#define vs vector<string>
typedef long long LL;
const int P = 998244353;
const int N = 305;
mt19937 rng(time(0));

int T, n, K, n0 = 0, n1;
char s[N];
int a[N], sum[N], dp[N][N][N], sdp[N][N][N];
// i-th, j-same, k-max

void madd(int &x, int y) {
  x += y;
  x = (x >= P ? x - P : x);
}

int main() {
  cin >> (s + 1) >> K;
  n = strlen(s + 1);
  rep(i, 1, n) if (s[i] == '0') n0++;
  else a[n0]++;
  sum[0] = a[0];
  rep(i, 1, n0) sum[i] = sum[i - 1] + a[i];
  n1 = n - n0;

  rep(i, 0, n1) rep(j, 0, i) {
    dp[i][j][0] = sdp[i][j][0] = (min(i, a[0]) == j ? 1 : 0);
    // cout<<i<<" "<<j<<" 0 "<<dp[i][j][0]<<endl;
    rep(k, 1, n0) {
      if (sum[k] > i) {
        sdp[i][j][k] = sdp[i][j][k - 1];
        continue;
      }
      rep(t, sum[k - 1], i - 1) {
        madd(dp[i][j][k], sdp[t][j - min(i - t, a[k])][k - 1]);
      }
      sdp[i][j][k] = sdp[i][j][k - 1];
      madd(sdp[i][j][k], dp[i][j][k]);
      // cout<<i<<" "<<j<<" "<<k<<" "<<dp[i][j][k]<<endl;
    }
  }

  int ans = 0;
  rep(j, max(0, n1 - K), n1) madd(ans, sdp[n1][j][n0]);
  cout << ans << endl;
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define rep(i, a, b) for (int i = (a); i <= (b); ++i)
#define rrep(i, a, b) for (int i = (a); i >= (b); --i)
#define PB push_back
#define ar2 array<int, 2>
#define vs vector<string>
typedef long long LL;
const int P = 998244353;
const int N = 305;
mt19937 rng(time(0));

int T, n, K, n0 = 0, n1;
char s[N];
int a[N], sum[N], dp[N][N][N], sdp[N][N][N];
// i-th, j-same, k-max

void madd(int &x, int y) {
  x += y;
  x = (x >= P ? x - P : x);
}

int main() {
  cin >> (s + 1) >> K;
  n = strlen(s + 1);
  rep(i, 1, n) if (s[i] == '0') n0++;
  else a[n0]++;
  sum[0] = a[0];
  rep(i, 1, n0) sum[i] = sum[i - 1] + a[i];
  n1 = n - n0;

  rep(i, 0, n1) rep(j, 0, i) {
    dp[i][j][0] = sdp[i][j][0] = (min(i, a[0]) == j ? 1 : 0);
    // cout<<i<<" "<<j<<" 0 "<<dp[i][j][0]<<endl;
    rep(k, 1, n0) {
      if (sum[k] > i) {
        sdp[i][j][k] = sdp[i][j][k - 1];
        continue;
      }
      rep(t, sum[k - 1], i - 1) {
        if (j - min(i - t, a[k]) < 0)
          continue;
        madd(dp[i][j][k], sdp[t][j - min(i - t, a[k])][k - 1]);
      }
      sdp[i][j][k] = sdp[i][j][k - 1];
      madd(sdp[i][j][k], dp[i][j][k]);
      // cout<<i<<" "<<j<<" "<<k<<" "<<dp[i][j][k]<<endl;
    }
  }

  int ans = 0;
  rep(j, max(0, n1 - K), n1) madd(ans, sdp[n1][j][n0]);
  cout << ans << endl;
  return 0;
}
Problem p02635 (C++)

Buggy submission (status: Runtime Error):
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <vector>
using namespace std;
typedef long long ll;
const int N = 310, mod = 998244353;
char s[N];
int K, ct, n, m;
int w[N];
ll sum, f[N][N][N];
void pls(ll &x, ll y) {
  x += y;
  x >= mod ? x -= mod : 0;
}
int main() {
  //	freopen("a.in","r",stdin);
  scanf("%s%d", s + 1, &K);
  n = strlen(s + 1);
  for (int i = 1; i <= n; i++)
    if (s[i] == '0')
      m++, w[m] = ct, ct = 0;
    else
      ct++;
  m++;
  w[m] = ct;
  f[m + 1][0][0] = 1;
  for (int i = m; i; i--) {
    sum = min(sum, (ll)K);
    for (int j = 0; j <= sum; j++)
      for (int k = j; k <= sum; k++)
        for (int c = 0; c <= j + w[i]; c++) {
          if (c < w[i])
            pls(f[i][j + w[i] - c][k + w[i] - c], f[i + 1][j][k]);
          else
            pls(f[i][j + w[i] - c][k], f[i + 1][j][k]);
        }
    sum += w[i];
  }
  sum = 0;
  for (int i = 0; i <= K; i++)
    pls(sum, f[1][0][i]);
  cout << sum;
}

Fixed submission:
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <vector>
using namespace std;
typedef long long ll;
const int N = 310, mod = 998244353;
char s[N];
int K, ct, n, m;
int w[N];
ll sum, f[N][N][N];
void pls(ll &x, ll y) {
  x += y;
  x >= mod ? x -= mod : 0;
}
int main() {
  //	freopen("a.in","r",stdin);
  scanf("%s%d", s + 1, &K);
  n = strlen(s + 1);
  for (int i = 1; i <= n; i++)
    if (s[i] == '0')
      m++, w[m] = ct, ct = 0;
    else
      ct++;
  m++;
  w[m] = ct;
  f[m + 1][0][0] = 1;
  for (int i = m; i; i--) {
    sum = min(sum, (ll)K);
    for (int j = 0; j <= sum; j++)
      for (int k = j; k <= sum; k++)
        for (int c = 0; c <= j + w[i]; c++) {
          if (c < w[i])
            pls(f[i][j + w[i] - c][k + w[i] - c], f[i + 1][j][k]);
          else
            pls(f[i][j + w[i] - c][k], f[i + 1][j][k]);
        }
    sum += w[i];
  }
  K = min(K, n);
  sum = 0;
  for (int i = 0; i <= K; i++)
    pls(sum, f[1][0][i]);
  cout << sum;
}
Problem p02635 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int p = 998244353;
int n, m, mx, i, j, k, l, val, ans, f[302][302][302], a[302], b[302], sum, sz;
char s[10010];
int main() {
  scanf("%s", s + 1);
  scanf("%d", &mx);
  n = strlen(s + 1);
  for (i = 1; i <= n; i++) {
    if (s[i] == '1')
      sz++, sum++;
    else {
      a[++m] = sz;
      sz = 0;
    }
  }
  f[0][0][0] = 1;
  for (i = 1; i <= m; i++) {
    b[i] = a[i];
    a[i] += a[i - 1];
    for (j = a[i - 1]; j <= sum; j++)
      for (k = 0; k <= min(j, mx); k++)
        if (f[i - 1][j][k])
          for (l = max(0, a[i] - j); l <= sum - j; l++) {
            val = max(0, l - b[i]);
            if (k + val <= mx)
              (f[i][j + l][k + val] += f[i - 1][j][k]) %= p;
          }
  }
  for (j = a[m]; j <= sum; j++)
    for (k = 0; k <= mx; k++)
      ans = (ans + f[m][j][k]) % p;
  printf("%d", ans);
}

Fixed submission:
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int p = 998244353;
int n, m, mx, i, j, k, l, val, ans, f[302][302][302], a[302], b[302], sum, sz;
char s[10010];
int main() {
  scanf("%s", s + 1);
  scanf("%d", &mx);
  n = strlen(s + 1);
  for (i = 1; i <= n; i++) {
    if (s[i] == '1')
      sz++, sum++;
    else {
      a[++m] = sz;
      sz = 0;
    }
  }
  f[0][0][0] = 1;
  for (i = 1; i <= m; i++) {
    b[i] = a[i];
    a[i] += a[i - 1];
    for (j = a[i - 1]; j <= sum; j++)
      for (k = 0; k <= min(j, mx); k++)
        if (f[i - 1][j][k])
          for (l = max(0, a[i] - j); l <= sum - j; l++) {
            val = max(0, l - b[i]);
            if (k + val <= mx)
              (f[i][j + l][k + val] += f[i - 1][j][k]) %= p;
          }
  }
  for (j = a[m]; j <= sum; j++)
    for (k = 0; k <= min(mx, sum); k++)
      ans = (ans + f[m][j][k]) % p;
  printf("%d", ans);
}
Problem p02635 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cstdio>
#include <cstring>
#define For(i, a, b) for (register int i = a; i <= b; ++i)
using namespace std;
const int maxn = 3e2 + 5;
const int mod = 998244353;
int f[maxn][maxn][maxn], K, N, n, num[maxn], ans;
// x     k     owe
char s[maxn];
void Add(int &x, const int &a) { x = (x + a) >= mod ? x + a - mod : x + a; }

int main() {
  scanf("%s%d", s, &K);
  N = strlen(s), n = 1;
  f[0][0][0] = 1;
  For(i, 0, N - 1) {
    if (s[i] == '0')
      ++n;
    if (s[i] == '1')
      ++num[n];
  }
  For(i, 0, n - 1) For(j, 0, K) For(k, 0, j) {
    Add(f[i + 1][j][k], f[i][j][k]);
    // in
    For(l, 1, K - j) Add(f[i + 1][j + l][k + l], f[i][j][k]);
    // out
    For(l, 1, min(k, num[i + 1])) Add(f[i + 1][j][k - l], f[i][j][k]);
  }
  For(i, 0, K) Add(ans, f[n][i][0]);
  printf("%d", ans);
  return 0;
}

Fixed submission:
#include <algorithm>
#include <cstdio>
#include <cstring>
#define For(i, a, b) for (register int i = a; i <= b; ++i)
using namespace std;
const int maxn = 3e2 + 5;
const int mod = 998244353;
int f[maxn][maxn][maxn], K, N, n, num[maxn], ans;
// x     k     owe
char s[maxn];
void Add(int &x, const int &a) { x = (x + a) >= mod ? x + a - mod : x + a; }

int main() {
  scanf("%s%d", s, &K);
  N = strlen(s), n = 1;
  f[0][0][0] = 1;
  For(i, 0, N - 1) {
    if (s[i] == '0')
      ++n;
    if (s[i] == '1')
      ++num[n];
  }
  K = min(K, N);
  For(i, 0, n - 1) For(j, 0, K) For(k, 0, j) {
    Add(f[i + 1][j][k], f[i][j][k]);
    // in
    For(l, 1, K - j) Add(f[i + 1][j + l][k + l], f[i][j][k]);
    // out
    For(l, 1, min(k, num[i + 1])) Add(f[i + 1][j][k - l], f[i][j][k]);
  }
  For(i, 0, K) Add(ans, f[n][i][0]);
  printf("%d", ans);
  return 0;
}
Problem p02635 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;

const int MOD = 998244353;
const int INF = 0x3f3f3f3f;
const ll INFL = 0x3f3f3f3f3f3f3f3f;

ll dp[400][400][400];
int a[400];
int d[400];

int main() {
  string s;
  cin >> s;
  int K;
  cin >> K;
  int n = 0;
  int cnt = 0;
  for (char c : s) {
    if (c == '0')
      cnt++;
    else
      a[n++] = cnt;
  }
  rep(i, n) { d[a[i]]++; }
  dp[cnt + 1][0][0] = 1;
  for (int i = cnt + 1; i >= 1; i--)
    rep(j, K + 1) rep(k, n + 1) {
      if (dp[i][j][k] == 0)
        continue;
      for (int t = 0; t <= d[i - 1] + k; t++) {
        int nj = j + max(0, d[i - 1] - t);
        //~ if(nj>K)break;
        (dp[i - 1][nj][d[i - 1] + k - t] += dp[i][j][k]) %= MOD;
      }
    }
  ll ans = 0;
  rep(i, K + 1) { (ans += dp[0][i][0]) %= MOD; }
  cout << ans << endl;
}

Fixed submission:
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;

const int MOD = 998244353;
const int INF = 0x3f3f3f3f;
const ll INFL = 0x3f3f3f3f3f3f3f3f;

ll dp[400][400][400];
int a[400];
int d[400];

int main() {
  string s;
  cin >> s;
  int K;
  cin >> K;
  int n = 0;
  int cnt = 0;
  for (char c : s) {
    if (c == '0')
      cnt++;
    else
      a[n++] = cnt;
  }
  rep(i, n) { d[a[i]]++; }
  K = min(K, n);
  dp[cnt + 1][0][0] = 1;
  for (int i = cnt + 1; i >= 1; i--)
    rep(j, K + 1) rep(k, n + 1) {
      if (dp[i][j][k] == 0)
        continue;
      for (int t = 0; t <= d[i - 1] + k; t++) {
        int nj = j + max(0, d[i - 1] - t);
        //~ if(nj>K)break;
        (dp[i - 1][nj][d[i - 1] + k - t] += dp[i][j][k]) %= MOD;
      }
    }
  ll ans = 0;
  rep(i, K + 1) { (ans += dp[0][i][0]) %= MOD; }
  cout << ans << endl;
}
Problem p02635 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;

const int maxN = 305, mod = 998244353;

int n, m;
int f[2][maxN + 1][maxN + 1];
int a[maxN + 1], cnt;
char s[maxN + 1];

inline void update(int &x, int y) { x = x + y >= mod ? x + y - mod : x + y; }

int main() {
  scanf("%s %d", s + 1, &m);
  n = strlen(s + 1);

  int l = 1;
  while (l <= n) {
    int r = l;
    while (r <= n && s[r] == '1')
      r++;
    a[++cnt] = r - l;
    l = r + 1;
  }

  int now = 0;
  f[now][0][0] = 1;
  for (int i = cnt; i >= 1; i--) {
    now ^= 1;
    memset(f[now], 0, sizeof(f[now]));
    for (int j = 0; j <= m; j++)
      for (int k = 0; k <= j; k++) {
        if (!f[now ^ 1][j][k])
          continue;
        int res = f[now ^ 1][j][k];
        for (int t = 0; t <= a[i]; t++)
          update(f[now][j + t][k + t], res);
        for (int t = 1; t <= k; t++)
          update(f[now][j][k - t], res);
      }
  }

  int ans = 0;
  for (int i = 0; i <= m; i++)
    update(ans, f[now][i][0]);

  printf("%d\n", ans);
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;

const int maxN = 305, mod = 998244353;

int n, m;
int f[2][maxN + 1][maxN + 1];
int a[maxN + 1], cnt;
char s[maxN + 1];

inline void update(int &x, int y) { x = x + y >= mod ? x + y - mod : x + y; }

int main() {
  scanf("%s %d", s + 1, &m);
  n = strlen(s + 1);
  m = min(m, n);

  int l = 1;
  while (l <= n) {
    int r = l;
    while (r <= n && s[r] == '1')
      r++;
    a[++cnt] = r - l;
    l = r + 1;
  }

  int now = 0;
  f[now][0][0] = 1;
  for (int i = cnt; i >= 1; i--) {
    now ^= 1;
    memset(f[now], 0, sizeof(f[now]));
    for (int j = 0; j <= m; j++)
      for (int k = 0; k <= j; k++) {
        if (!f[now ^ 1][j][k])
          continue;
        int res = f[now ^ 1][j][k];
        for (int t = 0; t <= a[i]; t++)
          update(f[now][j + t][k + t], res);
        for (int t = 1; t <= k; t++)
          update(f[now][j][k - t], res);
      }
  }

  int ans = 0;
  for (int i = 0; i <= m; i++)
    update(ans, f[now][i][0]);

  printf("%d\n", ans);
  return 0;
}
Problem p02635 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
#define rep(i, a, n) for (int i = a; i < n; i++)
#define per(i, a, n) for (int i = n - 1; i >= a; i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())
#define fi first
#define se second
typedef vector<int> VI;
typedef long long ll;
typedef pair<int, int> PII;
const ll mod = 998244353;
ll powmod(ll a, ll b) {
  ll res = 1;
  a %= mod;
  for (; b; b >>= 1) {
    if (b & 1)
      res = res * a % mod;
    a = a * a % mod;
  }
  return res;
}
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
// head

const int N = 310;
char s[N];
int m, ss[N], p[N];
int dp[N][N][N], ans;

void upd(int &a, int b) {
  a += b;
  if (a >= mod)
    a -= mod;
}
int main() {
  scanf("%s%d", s, &m);
  int n = strlen(s);
  reverse(s, s + n);
  m = min(m, n);
  int p0 = 0;
  rep(i, 0, n) {
    if (s[i] == '0')
      ss[p0 + 1] = ss[p0], p0++;
    else
      p[p0]++, ss[p0]++;
  }

  dp[0][0][0] = 1;
  rep(i, 1, p0 + 2) rep(k, 0, m + 1) {
    int t = 0;
    rep(j, 0, ss[i - 1] + 1) {
      for (int z = 0; z < p[i - 1]; z++)
        upd(dp[i][j][k + p[i - 1] - z], dp[i - 1][j - z][k]);
      if (j - p[i - 1] >= 0)
        upd(t, dp[i - 1][j - p[i - 1]][k]);
      upd(dp[i][j][k], t);
    }
  }
  rep(i, 0, m + 1) upd(ans, dp[p0 + 1][ss[p0]][i]);
  printf("%d\n", ans);
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define rep(i, a, n) for (int i = a; i < n; i++)
#define per(i, a, n) for (int i = n - 1; i >= a; i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())
#define fi first
#define se second
typedef vector<int> VI;
typedef long long ll;
typedef pair<int, int> PII;
const ll mod = 998244353;
ll powmod(ll a, ll b) {
  ll res = 1;
  a %= mod;
  for (; b; b >>= 1) {
    if (b & 1)
      res = res * a % mod;
    a = a * a % mod;
  }
  return res;
}
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
// head

const int N = 310;
char s[N];
int m, ss[N], p[N];
int dp[N][N][N], ans;

void upd(int &a, int b) {
  a += b;
  if (a >= mod)
    a -= mod;
}
int main() {
  scanf("%s%d", s, &m);
  int n = strlen(s);
  reverse(s, s + n);
  m = min(m, n);
  int p0 = 0;
  rep(i, 0, n) {
    if (s[i] == '0')
      ss[p0 + 1] = ss[p0], p0++;
    else
      p[p0]++, ss[p0]++;
  }

  dp[0][0][0] = 1;
  rep(i, 1, p0 + 2) rep(k, 0, m + 1) {
    int t = 0;
    rep(j, 0, ss[i - 1] + 1) {
      for (int z = 0; z < p[i - 1] && z <= j; z++)
        upd(dp[i][j][k + p[i - 1] - z], dp[i - 1][j - z][k]);
      if (j - p[i - 1] >= 0)
        upd(t, dp[i - 1][j - p[i - 1]][k]);
      upd(dp[i][j][k], t);
    }
  }
  rep(i, 0, m + 1) upd(ans, dp[p0 + 1][ss[p0]][i]);
  printf("%d\n", ans);
}
Problem p02635 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define pb push_back
#define int long long
using namespace std;

const int N = 3e2 + 5;

int n, a[N], dp[N][N][N], pref[N];
const int M = 998244353;

signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  string S;
  int k;
  cin >> S >> k;
  int cur = 0;
  for (int i = 0; i < S.size(); i++)
    if (S[i] == '1')
      cur++;
    else
      n++, a[n] = cur, cur = 0;
  n++;
  a[n] = cur;
  for (int i = 1; i <= n; i++)
    pref[i] = pref[i - 1] + a[i];
  dp[0][0][0] = 1;
  for (int i = 1; i <= n; i++)
    for (int s = pref[i]; s <= pref[n]; s++)
      for (int j = 0; j <= k; j++) {
        for (int q = max(1ll, a[i] - s); q <= a[i]; q++)
          // if (s >= a[i] - q)
          dp[i][s][j] += dp[i - 1][s - (a[i] - q)][j], dp[i][s][j] %= M;
        for (int q = 0; q <= min(j, s - a[i]); q++)
          // if (s >= a[i] + q)
          dp[i][s][j] += dp[i - 1][s - (a[i] + q)][j - q], dp[i][s][j] %= M;
        // cout << i << ' ' << s << ' ' << j << ' ' << dp[i][s][j] << endl;
      }
  int ans = 0;
  for (int j = 0; j <= k; j++)
    ans += dp[n][pref[n]][j], ans %= M;
  cout << ans;
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
#define pb push_back
#define int long long
using namespace std;

const int N = 3e2 + 5;

int n, a[N], dp[N][N][N], pref[N];
const int M = 998244353;

signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  string S;
  int k;
  cin >> S >> k;
  int sz = S.size();
  k = min(k, sz);
  int cur = 0;
  for (int i = 0; i < S.size(); i++)
    if (S[i] == '1')
      cur++;
    else
      n++, a[n] = cur, cur = 0;
  n++;
  a[n] = cur;
  for (int i = 1; i <= n; i++)
    pref[i] = pref[i - 1] + a[i];
  dp[0][0][0] = 1;
  for (int i = 1; i <= n; i++)
    for (int s = pref[i]; s <= pref[n]; s++)
      for (int j = 0; j <= k; j++) {
        for (int q = max(1ll, a[i] - s); q <= a[i]; q++)
          // if (s >= a[i] - q)
          dp[i][s][j] += dp[i - 1][s - (a[i] - q)][j], dp[i][s][j] %= M;
        for (int q = 0; q <= min(j, s - a[i]); q++)
          // if (s >= a[i] + q)
          dp[i][s][j] += dp[i - 1][s - (a[i] + q)][j - q], dp[i][s][j] %= M;
        // cout << i << ' ' << s << ' ' << j << ' ' << dp[i][s][j] << endl;
      }
  int ans = 0;
  for (int j = 0; j <= k; j++)
    ans += dp[n][pref[n]][j], ans %= M;
  cout << ans;
  return 0;
}
Problem p02635 (C++)

Buggy submission (status: Memory Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;

long d[333][666][666];
vector<int> u;
int p = 998244353;
int f(int i, int v, int w) {
  if (!i)
    return v ? 0 : 1;
  if (v > w)
    return 0;
  if (d[i][v][w] >= 0)
    return d[i][v][w];
  d[i][v][w] = 0;
  for (int j = max(-u[i - 1], -w); j <= v; j++)
    (d[i][v][w] += f(i - 1, v - j, w - abs(j))) %= p;
  return d[i][v][w];
}
int main() {
  string s;
  int k;
  cin >> s >> k;
  k = min(k, 300);
  k += k;
  for (s += '0';;) {
    auto i = s.find('0');
    if (i == -1)
      break;
    s = s.substr(i + 1);
    u.push_back(i);
  }
  for (int i = 0; i < 333; i++)
    for (int j = 0; j <= k; j++)
      for (int w = 0; w <= k; w++)
        d[i][j][w] = -1;
  cout << f(u.size(), 0, k) << endl;
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;

int d[333][666][666];
vector<int> u;
int p = 998244353;
int f(int i, int v, int w) {
  if (!i)
    return v ? 0 : 1;
  if (v > w)
    return 0;
  if (d[i][v][w] >= 0)
    return d[i][v][w];
  d[i][v][w] = 0;
  for (int j = max(-u[i - 1], -w); j <= v; j++)
    (d[i][v][w] += f(i - 1, v - j, w - abs(j))) %= p;
  return d[i][v][w];
}
int main() {
  string s;
  int k;
  cin >> s >> k;
  k = min(k, 300);
  k += k;
  for (s += '0';;) {
    auto i = s.find('0');
    if (i == -1)
      break;
    s = s.substr(i + 1);
    u.push_back(i);
  }
  for (int i = 0; i < 333; i++)
    for (int j = 0; j <= k; j++)
      for (int w = 0; w <= k; w++)
        d[i][j][w] = -1;
  cout << f(u.size(), 0, k) << endl;
  return 0;
}
Problem p02635 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>

using namespace std;

typedef pair<int, int> pi;
typedef long long ll;

const ll mod = 998244353;

string s;
ll K, dp[305][305][305]; // groups, moves, carry
ll N, sz[305];

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cin >> s >> K;

  int gn = 1, gz = 0;
  N = s.size();
  K = min(K, N);
  reverse(s.begin(), s.end());

  for (int i = 0; i < s.size(); ++i) {
    if (s[i] == '0') {
      sz[gn] = gz;
      gz = 0;
      gn++;
    } else
      gz++;
  }
  sz[gn] = gz;
  /*
  for (int i = 1; i <= gn; ++i){
          cout << sz[i] << ' ';
  }
  cout << '\n';
  */
  dp[0][0][0] = 1;
  for (ll i = 1; i <= gn; ++i) {
    for (ll k = 0; k <= K; ++k) {
      for (ll c = 0; c <= k; ++c) {
        for (ll l = 0; (c + l) <= N; ++l) {
          dp[i][k][c] += dp[i - 1][k][c + l];
          dp[i][k][c] %= mod;
        }
        for (ll l = 1; l <= min(min(sz[i], k), c); ++l) {
          dp[i][k][c] += dp[i - 1][k - l][c - l];
          dp[i][k][c] %= mod;
        }
        // cout << i << ' ' << k << ' ' << c << ' ' << dp[i][k][c] << '\n';
      }
    }
  }
  ll ans = 0;
  for (int i = 0; i <= K; ++i) {
    ans += dp[gn][i][0];
    ans %= mod;
  }
  cout << ans << '\n';
}

Fixed submission:
#include <bits/stdc++.h>

using namespace std;

typedef pair<int, int> pi;
typedef long long ll;

const ll mod = 998244353;

string s;
ll K, dp[305][305][305]; // groups, moves, carry
ll N, sz[305];

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cin >> s >> K;

  int gn = 1, gz = 0;
  N = s.size();
  K = min(K, N);
  reverse(s.begin(), s.end());

  for (int i = 0; i < s.size(); ++i) {
    if (s[i] == '0') {
      sz[gn] = gz;
      gz = 0;
      gn++;
    } else
      gz++;
  }
  sz[gn] = gz;
  /*
  for (int i = 1; i <= gn; ++i){
          cout << sz[i] << ' ';
  }
  cout << '\n';
  */
  dp[0][0][0] = 1;
  for (ll i = 1; i <= gn; ++i) {
    for (ll k = 0; k <= K; ++k) {
      for (ll c = 0; c <= k; ++c) {
        for (ll l = 0; (c + l) <= k; ++l) {
          dp[i][k][c] += dp[i - 1][k][c + l];
          dp[i][k][c] %= mod;
        }
        for (ll l = 1; l <= min(min(sz[i], k), c); ++l) {
          dp[i][k][c] += dp[i - 1][k - l][c - l];
          dp[i][k][c] %= mod;
        }
        // cout << i << ' ' << k << ' ' << c << ' ' << dp[i][k][c] << '\n';
      }
    }
  }
  ll ans = 0;
  for (int i = 0; i <= K; ++i) {
    ans += dp[gn][i][0];
    ans %= mod;
  }
  cout << ans << '\n';
}
Problem p02639 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
#define ll long long

int main() {

  int a[5];
  for (int i = 0; i < 5; i++)
    cin >> a[i];
  for (int i = 0; i < 5; i++) {
    if (a[i] == 0)
      return i + 1;
  }
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define ll long long

int main() {

  int a[5];
  for (int i = 0; i < 5; i++)
    cin >> a[i];
  for (int i = 0; i < 5; i++) {
    if (a[i] == 0) {
      cout << i + 1;
      break;
    }
  }
}
Problem p02639 (C++)

Buggy submission (status: Runtime Error):
#include <iostream>

using namespace std;

int main() {
  int x[5];
  for (int i = 1; i <= 5; ++i)
    cin >> x[i];
  for (int i = 1; i <= 5; ++i) {
    if (!x[i])
      cout << i << '\n';
  }
  return 0;
}

Fixed submission:
#include <iostream>

using namespace std;

int main() {
  int x[6];
  for (int i = 1; i <= 5; ++i)
    cin >> x[i];
  for (int i = 1; i <= 5; ++i) {
    if (!x[i])
      cout << i << '\n';
  }
  return 0;
}
Problem p02639 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
int main() {
  int ara[5], i, c = 0;
  for (i = 1; i <= 5; i++) {
    cin >> ara[i];
  }
  for (i = 1; i <= 5; i++) {
    if (ara[i] == 0)
      cout << i << endl;
  }
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int main() {
  int x1, x2, x3, x4, x5;
  cin >> x1 >> x2 >> x3 >> x4 >> x5;
  if (x1 == 0)
    cout << 1 << endl;

  else if (x2 == 0)
    cout << 2 << endl;
  else if (x3 == 0)
    cout << 3 << endl;
  else if (x4 == 0)
    cout << 4 << endl;
  else if (x5 == 0)
    cout << 5 << endl;
}
Problem p02639 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
int main() {
  vector<int> result;
  for (int i = 0; i < 5; i++) {
    cin >> result.at(i);
    if (result.at(i) == 0) {
      cout << i + 1 << endl;
      break;
    }
  }
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int main() {
  vector<int> result(5);
  for (int i = 0; i < 5; i++) {
    cin >> result.at(i);
    if (result.at(i) == 0) {
      cout << i + 1 << endl;
      break;
    }
  }
}
Problem p02639 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;

int main() {
  int a[5];
  for (int i = 1; i <= 5; i++) {
    cin >> a[i];
    if (a[i] == 0)
      cout << i;
  }
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;

int main() {
  int a[6];
  for (int i = 1; i <= 5; i++) {
    cin >> a[i];
    if (a[i] == 0)
      cout << i;
  }
  return 0;
}
Problem p02639 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <iostream>
using namespace std;

int main() {
  while (true) {
    int num;
    for (int i = 1; i <= 5; i++) {
      cin >> num;
      if (num == 0)
        cout << i << endl;
    }
  }
}

Fixed submission:
#include <iostream>
using namespace std;

int main() {
  int var[5];
  while (cin >> var[0] >> var[1] >> var[2] >> var[3] >> var[4]) {
    for (int i = 0; i < 5; i++) {
      if (var[i] == 0)
        cout << i + 1 << endl;
    }
  }
}
Problem p02639 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;

int main() {
  int v, ans = -1;
  for (int i = 0; i < 5; i++) {

    cin >> v;
    if (v == 0) {
      ans = i;
    }
  }
  return ans;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;

int main() {
  int v, ans = -1;
  for (int i = 0; i < 5; i++) {

    cin >> v;
    if (v == 0) {
      ans = i;
    }
  }
  cout << ans + 1;
  return 0;
}
Problem p02639 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;

int main() {

  int a[5];
  int pri;
  for (int i = 1; i <= 5; i++) {
    cin >> a[i];
    if (a[i] == 0)
      pri = i;
  }
  cout << pri << endl;

  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;

int main() {

  int a[10];
  int pri;
  for (int i = 1; i <= 5; i++) {
    cin >> a[i];
    if (a[i] == 0)
      pri = i;
  }
  cout << pri << endl;

  return 0;
}
Problem p02639 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <iostream>
using namespace std;

int main() {
  int A[5];
  int x = 0;
  for (int i = 1; i <= 5; i++) {
    cin >> A[i];
    if (A[i] == 0)
      x = i;
  }
  cout << x;
  return 0;
}

Fixed submission:
#include <iostream>
using namespace std;

int main() {
  int A[5];
  int x = 0;
  for (int i = 1; i <= 5; i++) {
    cin >> A[i];
  }
  for (int i = 1; i <= 5; i++) {
    if (A[i] == 0)
      x = i;
  }
  cout << x;
  return 0;
}
Problem p02639 (C++)

Buggy submission (status: Runtime Error):
#pragma GCC optimize("Ofast")
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using ull = unsigned long long;
#define PI 3.141592
#define all(a) (a).begin(), (a).end()

int main() {
  vector<int> A;
  for (int i = 0; i < 5; i++)
    cin >> A[i];
  for (int i = 0; i < 5; i++) {
    if (A[i] == 0) {
      cout << i + 1 << endl;
      return 0;
    }
  }
}


Fixed submission:
#pragma GCC optimize("Ofast")
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using ull = unsigned long long;
#define PI 3.141592
#define all(a) (a).begin(), (a).end()

int main() {
  vector<int> A(5);
  for (int i = 0; i < 5; i++)
    cin >> A[i];
  for (int i = 0; i < 5; i++) {
    if (A[i] == 0) {
      cout << i + 1 << endl;
      return 0;
    }
  }
}
Problem p02639 (Python)

Buggy submission (status: Runtime Error):
import sys

line = sys.stdin.readlines()[0].rstrip("\n")
print(line.split(" ").index("0", 1))


Fixed submission:
import sys

line = sys.stdin.readlines()[0].rstrip("\n")
nums = line.split(" ")
print(nums.index("0") + 1)
Problem p02639 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <math.h>
#include <string>
#define pi 3.1415926535897932384626
#include <cmath>
#define test(t) while (t--)

#define ll long long int

#define in cin >>
#define out cout <<
#define en "\n"
#define sp " "
#define pb push_back
#define fast()                                                                 \
  ios_base::sync_with_stdio(false);                                            \
  cin.tie(0);
#define double long double

using namespace std;
ll form(ll n) { return (n * (n + 1)) / 2; }
ll exponent(ll base, ll power) {
  ll res = 1;
  ll m = 1000000007;
  while (power) {
    if (power & 1)
      res = (res * base) % m;
    base = (base * base) % m;
    power = power >> 1;
  }
  return res;
}
bool count_one(ll n) {
  ll cnt = 0;
  while (n > 0) {
    cnt += 1;
    n = n & (n - 1);
  }
  if (cnt > 1)
    return true;
  return false;
}
void solve() {
  ll a[5];
  ll ans;
  for (ll i = 1; i <= 5; i++) {
    in a[i];
    if (a[i] == 0)
      ans = i;
  }
  out ans << en;
}

int main() {
  fast()
      // freopen("input.txt","r",stdin);
      // freopen("output.txt","w",stdout);
      ll t = 1;
  // cin>>t;
  test(t) { solve(); }
  return 0;
}


Fixed submission:
#include <algorithm>
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <math.h>
#include <string>
#define pi 3.1415926535897932384626
#include <cmath>
#define test(t) while (t--)

#define ll long long int

#define in cin >>
#define out cout <<
#define en "\n"
#define sp " "
#define pb push_back
#define fast()                                                                 \
  ios_base::sync_with_stdio(false);                                            \
  cin.tie(0);
#define double long double

using namespace std;
ll form(ll n) { return (n * (n + 1)) / 2; }
ll exponent(ll base, ll power) {
  ll res = 1;
  ll m = 1000000007;
  while (power) {
    if (power & 1)
      res = (res * base) % m;
    base = (base * base) % m;
    power = power >> 1;
  }
  return res;
}
bool count_one(ll n) {
  ll cnt = 0;
  while (n > 0) {
    cnt += 1;
    n = n & (n - 1);
  }
  if (cnt > 1)
    return true;
  return false;
}
void solve() {
  ll x1, x2, x3, x4, x5;
  in x1 >> x2 >> x3 >> x4 >> x5;
  if (x1 == 0)
    out 1 << en;
  else if (x2 == 0)
    out 2 << en;
  else if (x3 == 0)
    out 3 << en;
  else if (x4 == 0)
    out 4 << en;
  else
    out 5 << en;
}

int main() {
  fast()
      // freopen("input.txt","r",stdin);
      // freopen("output.txt","w",stdout);
      ll t = 1;
  // cin>>t;
  test(t) { solve(); }
  return 0;
}
Problem p02639 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define ar array

void solve() {}

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int x[5];
  cin >> x[0] >> x[1] >> x[2] >> x[3] >> x[4];
  for (int i = 0; i < 5; i++) {
    if (x[i] == 0) {
      cout << i + 1 << "\n";
      return 1;
    }
  }
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define ar array

void solve() {}

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int x[5];
  cin >> x[0] >> x[1] >> x[2] >> x[3] >> x[4];
  for (int i = 0; i < 5; i++) {
    if (x[i] == 0) {
      cout << i + 1 << "\n";
      return 0;
    }
  }
}
Problem p02639 (C++)

Buggy submission (status: Runtime Error):
// --------------
// Tejas Pandey  |
// 14 - 06 - 20  |
// Atcoder BC 170|
// --------------

#include <bits/stdc++.h>
using namespace std;

#define mod 1000000007
#define vi vector<int>
typedef long long int ll;

int main(void) {
  // freopen("in.txt","r",stdin);
  // freopen("out.txt","w",stdout);
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  vector<pair<int, int>> v;
  for (int i = 0; i < 5; i++)
    cin >> v[i].first, v[i].second = i + 1;
  sort(v.begin(), v.end());
  cout << v[0].second;
  return 0;
}


Fixed submission:
// --------------
// Tejas Pandey  |
// 14 - 06 - 20  |
// Atcoder BC 170|
// --------------

#include <bits/stdc++.h>
using namespace std;

#define mod 1000000007
#define vi vector<int>
typedef long long int ll;

int main(void) {
  // freopen("in.txt","r",stdin);
  // freopen("out.txt","w",stdout);
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  vector<pair<int, int>> v(5);
  for (int i = 0; i < 5; i++)
    cin >> v[i].first, v[i].second = i + 1;
  sort(v.begin(), v.end());
  cout << v[0].second;
  return 0;
}