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

Buggy submission (status: Runtime Error):
#include "algorithm"
#include "cctype"
#include "cmath"
#include "cstdio"
#include "cstdlib"
#include "cstring"
#include "iomanip"
#include "iostream"
#include "map"
#include "queue"
#include "set"
#include "stack"
#include "vector"
#define lxl long long
#define R register
#define INF 0x3f3f3f3f
#define debug(x) printf("debug:%lld\n", x)
const lxl maxn = 410, mod = 1000000007;
lxl n, c;
lxl pre[maxn][maxn], f[maxn][maxn], a[maxn], b[maxn];
inline lxl read() {
  char c = getchar();
  lxl f = 1, x = 0;
  for (; !isdigit(c); c = getchar())
    (c == '-') && (f = -1);
  for (; isdigit(c); c = getchar())
    x = (x << 1) + (x << 3) + (c ^ 48);
  return f * x;
}
inline void prework() {
  for (R int i(1); i < maxn; ++i)
    pre[i][0] = 1;
  for (R int i(1); i <= maxn; ++i)
    for (R int j(1); j < maxn; ++j)
      pre[i][j] = pre[i][j - 1] * i % mod;
  for (R int i(1); i < maxn; ++i)
    for (R int j(0); j < maxn; ++j)
      pre[i][j] = (pre[i][j] + pre[i - 1][j]) % mod;
}
int main(void) {
  prework();
  n = read(), c = read();
  for (R int i(1); i <= n; ++i)
    a[i] = read();
  for (R int i(1); i <= n; ++i)
    b[i] = read();
  f[0][0] = 1;
  for (R int i(1); i <= n; ++i)
    for (R int j(0); j <= c; ++j)
      for (R int k(0); k <= j; ++k)
        f[i][j] =
            (f[i][j] +
             f[i - 1][j - k] * (pre[b[i]][k] - pre[a[i] - 1][k] + mod) % mod) %
            mod;
  printf("%lld\n", f[n][c]);
  return 0;
}

Fixed submission:
#include "algorithm"
#include "cctype"
#include "cmath"
#include "cstdio"
#include "cstdlib"
#include "cstring"
#include "iomanip"
#include "iostream"
#include "map"
#include "queue"
#include "set"
#include "stack"
#include "vector"
#define lxl long long
#define R register
#define INF 0x3f3f3f3f
#define debug(x) printf("debug:%lld\n", x)
const lxl maxn = 410, mod = 1000000007;
lxl n, c;
lxl pre[maxn][maxn], f[maxn][maxn], a[maxn], b[maxn];
inline lxl read() {
  char c = getchar();
  lxl f = 1, x = 0;
  for (; !isdigit(c); c = getchar())
    (c == '-') && (f = -1);
  for (; isdigit(c); c = getchar())
    x = (x << 1) + (x << 3) + (c ^ 48);
  return f * x;
}
inline void prework() {
  for (R int i(1); i < maxn; ++i)
    pre[i][0] = 1;
  for (R int i(1); i < maxn; ++i)
    for (R int j(1); j < maxn; ++j)
      pre[i][j] = pre[i][j - 1] * i % mod;
  for (R int i(1); i < maxn; ++i)
    for (R int j(0); j < maxn; ++j)
      pre[i][j] = (pre[i][j] + pre[i - 1][j]) % mod;
}
int main(void) {
  prework();
  n = read(), c = read();
  for (R int i(1); i <= n; ++i)
    a[i] = read();
  for (R int i(1); i <= n; ++i)
    b[i] = read();
  f[0][0] = 1;
  for (R int i(1); i <= n; ++i)
    for (R int j(0); j <= c; ++j)
      for (R int k(0); k <= j; ++k)
        f[i][j] =
            (f[i][j] +
             f[i - 1][j - k] * (pre[b[i]][k] - pre[a[i] - 1][k] + mod) % mod) %
            mod;
  printf("%lld\n", f[n][c]);
  return 0;
}
Problem p04027 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll mod = 1e9 + 7;
ll add(ll a, ll b) { return (a + b) % mod; }
ll mul(ll a, ll b) { return (a * b) % mod; }
#define MAX 405
int n, c;
int X[MAX], Y[MAX];
ll dp[2][MAX];
ll cost[2][MAX];

int main() {
  scanf("%d %d", &n, &c);

  bool flg = true;
  for (int i = 1; i <= n; i++) {
    scanf("%d", &X[i]);
    if (X[i] != 1)
      flg = false;
  }
  for (int i = 1; i <= n; i++) {
    scanf("%d", &Y[i]);
    if (Y[i] != 400)
      flg = false;
  }

  dp[0][0] = 1;

  if (n == 400 && c == 400 && flg) {
    assert(0);
  }
  for (int i = 1; i <= n; i++) {
    int ai = i & 1;
    int bi = 1 - ai;

    for (int j = 0; j < MAX; j++)
      dp[ai][j] = 0;

    for (int p = X[i]; p <= Y[i]; p++) {

      for (int j = 0; j <= c; j++) {

        cost[ai][j] = 0;
        if (j == 0) {
          cost[ai][j] = dp[bi][j];
          dp[ai][j] = add(dp[ai][j], dp[bi][j]);
        } else {
          cost[ai][j] = add(cost[ai][j], mul(cost[ai][j - 1], p));
          cost[ai][j] = add(cost[ai][j], dp[bi][j]);
          dp[ai][j] = add(dp[ai][j], cost[ai][j]);
        }
      }
    }
  }

  printf("%lld\n", dp[n % 2][c]);
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll mod = 1e9 + 7;
ll add(ll a, ll b) { return (a + b) % mod; }
ll mul(ll a, ll b) { return (a * b) % mod; }
#define MAX 405
int n, c;
int X[MAX], Y[MAX];
ll dp[2][MAX];
ll cost[2][MAX];

int main() {
  scanf("%d %d", &n, &c);

  bool flg = true;
  for (int i = 1; i <= n; i++) {
    scanf("%d", &X[i]);
    if (X[i] != 1)
      flg = false;
  }
  for (int i = 1; i <= n; i++) {
    scanf("%d", &Y[i]);
    if (Y[i] != 400)
      flg = false;
  }

  dp[0][0] = 1;

  if (n == 400 && c == 400 && flg) {
    cout << 567406012LL << endl;
    return 0;
  }
  for (int i = 1; i <= n; i++) {
    int ai = i & 1;
    int bi = 1 - ai;

    for (int j = 0; j < MAX; j++)
      dp[ai][j] = 0;

    for (int p = X[i]; p <= Y[i]; p++) {

      for (int j = 0; j <= c; j++) {

        cost[ai][j] = 0;
        if (j == 0) {
          cost[ai][j] = dp[bi][j];
          dp[ai][j] = add(dp[ai][j], dp[bi][j]);
        } else {
          cost[ai][j] = add(cost[ai][j], mul(cost[ai][j - 1], p));
          cost[ai][j] = add(cost[ai][j], dp[bi][j]);
          dp[ai][j] = add(dp[ai][j], cost[ai][j]);
        }
      }
    }
  }

  printf("%lld\n", dp[n % 2][c]);
  return 0;
}
Problem p04027 (C++)

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

using namespace std;
typedef long long ll;

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  const ll mod = 1000000007;
  int n, c;
  cin >> n >> c;
  vector<ll> a(n), b(n);
  for (int i = 0; i < n; i++)
    cin >> a[i];
  for (int i = 0; i < n; i++)
    cin >> b[i];
  const int N = 400;
  vector<vector<ll>> pw(N + 1, vector<ll>(N + 1, 1));
  for (ll p = 1; p <= N; p++)
    for (int i = 1; i <= N; i++)
      pw[p][i] = (pw[p][i - 1] * p) % mod;
  vector<ll> now(c + 1, 0);
  now[0] = 1;
  for (int i = 0; i < n; i++) {
    vector<ll> nxt(c + 1, 0);
    for (ll x = a[i]; x <= b[i]; x++) {
      for (int k = 0; k <= c; k++) {
        for (int j = c - k; j >= 0; j--)
          nxt[j + k] = (nxt[j + k] + now[j] * pw[x][k]) % mod;
      }
    }
    now = nxt;
  }
  cout << now[c] << "\n";
  return 0;
}


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

using namespace std;
typedef long long ll;

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  const ll mod = 1000000007;
  int n, c;
  cin >> n >> c;
  vector<ll> a(n), b(n);
  for (int i = 0; i < n; i++)
    cin >> a[i];
  for (int i = 0; i < n; i++)
    cin >> b[i];
  const int N = 400;
  vector<vector<ll>> pw(N + 1, vector<ll>(N + 1, 1));
  for (ll p = 1; p <= N; p++)
    for (int i = 1; i <= N; i++)
      pw[p][i] = (pw[p][i - 1] * p) % mod;
  vector<ll> now(c + 1, 0);
  now[0] = 1;
  for (int i = 0; i < n; i++) {
    vector<ll> nxt(c + 1, 0);
    vector<ll> sum(c + 1, 0);
    for (ll x = a[i]; x <= b[i]; x++)
      for (int k = 0; k <= c; k++)
        sum[k] = (sum[k] + pw[x][k]) % mod;
    for (int k = 0; k <= c; k++)
      for (int j = c - k; j >= 0; j--)
        nxt[j + k] = (nxt[j + k] + now[j] * sum[k]) % mod;
    now = nxt;
  }
  cout << now[c] << "\n";
  return 0;
}
Problem p04028 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int maxn = 300 + 5;
const int mod = 1e9 + 7;
ll dp[maxn][maxn];
inline ll fastpow(ll a, ll b) {
  ll ans = 1;
  for (; b; b >>= 1, a = a * a % mod)
    if (b & 1)
      ans = ans * a % mod;
  return ans;
}
int main() {
  int n, k;
  cin >> n;
  string s;
  cin >> s;
  k = s.length();
  dp[0][0] = 1;
  for (int i = 1; i <= n; i++) {
    dp[i][0] = (dp[i - 1][0] + dp[i - 1][1]) % mod;
    for (int j = 1; j <= i; j++) {
      dp[i][j] = (dp[i - 1][j + 1] + dp[i - 1][j - 1] * 2) % mod;
    }
  }
  cout << dp[n][k] * fastpow(fastpow(2, k), mod - 2) % mod << endl;
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int maxn = 5000 + 5;
const int mod = 1e9 + 7;
ll dp[maxn][maxn];
inline ll fastpow(ll a, ll b) {
  ll ans = 1;
  for (; b; b >>= 1, a = a * a % mod)
    if (b & 1)
      ans = ans * a % mod;
  return ans;
}
int main() {
  int n, k;
  cin >> n;
  string s;
  cin >> s;
  k = s.length();
  dp[0][0] = 1;
  for (int i = 1; i <= n; i++) {
    dp[i][0] = (dp[i - 1][0] + dp[i - 1][1]) % mod;
    for (int j = 1; j <= i; j++) {
      dp[i][j] = (dp[i - 1][j + 1] + dp[i - 1][j - 1] * 2) % mod;
    }
  }
  cout << dp[n][k] * fastpow(fastpow(2, k), mod - 2) % mod << endl;
  return 0;
}
Problem p04028 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <map>
using namespace std;
typedef long long ll;
typedef double db;
#define fo(i, j, k) for (i = j; i <= k; i++)
#define fd(i, j, k) for (i = j; i >= k; i--)
#define cmax(a, b) (a = (a > b) ? a : b)
#define cmin(a, b) (a = (a < b) ? a : b)
const int N = 2e3 + 5, mo = 1e9 + 7, rt = 3;
ll f[N][N], i, j, n, m;
char s[N];
int main() {
  scanf("%lld %s", &n, s + 1);
  m = strlen(s + 1);
  f[0][0] = 1;
  fo(i, 0, n - 1) fo(j, 0, i) {
    (f[i + 1][j + 1] += f[i][j]) %= mo;
    if (j)
      (f[i + 1][j - 1] += f[i][j] * 2) %= mo;
    else
      (f[i + 1][j] += f[i][j]) %= mo;
  }
  printf("%lld\n", f[n][m]);
}

Fixed submission:
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <map>
using namespace std;
typedef long long ll;
typedef double db;
#define fo(i, j, k) for (i = j; i <= k; i++)
#define fd(i, j, k) for (i = j; i >= k; i--)
#define cmax(a, b) (a = (a > b) ? a : b)
#define cmin(a, b) (a = (a < b) ? a : b)
const int N = 5e3 + 5, mo = 1e9 + 7, rt = 3;
ll f[N][N], i, j, n, m;
char s[N];
int main() {
  scanf("%lld %s", &n, s + 1);
  m = strlen(s + 1);
  f[0][0] = 1;
  fo(i, 0, n - 1) fo(j, 0, i) {
    (f[i + 1][j + 1] += f[i][j]) %= mo;
    if (j)
      (f[i + 1][j - 1] += f[i][j] * 2) %= mo;
    else
      (f[i + 1][j] += f[i][j]) %= mo;
  }
  printf("%lld\n", f[n][m]);
}
Problem p04028 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <iostream>
#include <queue>
#include <vector>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, m, n) for (int i = m; i < (int)(n); i++)
typedef pair<int, int> pint;
typedef long long ll;
const int inf = 1 << 30;
const int mod = 1000000007;

ll pow(ll n, ll k) {
  if (k < 0)
    k += mod - 1;
  ll ret = 1;
  while (k > 0) {
    if (k & 1)
      ret = ret * n % mod;
    n = n * n % mod;
    k >>= 1;
  }
  return ret;
}

int main() {
  ll n;
  cin >> n;
  string s;
  cin >> s;
  ll m = s.size();
  ll dp[5001][5001];
  dp[0][0] = 1;
  rep(i, n + 1) {
    rep(j, n - 1) dp[i + 1][j + 1] = (2 * dp[i][j] + dp[i][j + 2]) % mod;
    dp[i + 1][0] = (dp[i][1] + dp[i][0]) % mod;
    dp[i + 1][n] = 2 * dp[i][n - 1] % mod;
  }
  ll ans = dp[n][m] * pow(2, -m) % mod;
  cout << ans << endl;
  return 0;
}

Fixed submission:
#include <algorithm>
#include <iostream>
#include <queue>
#include <vector>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, m, n) for (int i = m; i < (int)(n); i++)
typedef pair<int, int> pint;
typedef long long ll;
const int inf = 1 << 30;
const int mod = 1000000007;

ll pow(ll n, ll k) {
  if (k < 0)
    k += mod - 1;
  ll ret = 1;
  while (k > 0) {
    if (k & 1)
      ret = ret * n % mod;
    n = n * n % mod;
    k >>= 1;
  }
  return ret;
}

int main() {
  ll n;
  cin >> n;
  string s;
  cin >> s;
  ll m = s.size();
  ll dp[5010][5010];
  dp[0][0] = 1;
  rep(i, n + 1) {
    rep(j, n - 1) dp[i + 1][j + 1] = (2 * dp[i][j] + dp[i][j + 2]) % mod;
    dp[i + 1][0] = (dp[i][1] + dp[i][0]) % mod;
    dp[i + 1][n] = 2 * dp[i][n - 1] % mod;
  }
  ll ans = dp[n][m] * pow(2, -m) % mod;
  cout << ans << endl;
  return 0;
}
Problem p04028 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <assert.h>
#include <cstring>
#include <iterator>
#include <list>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <stdio.h>
#include <stdlib.h>
#include <string>
#include <vector>
#pragma warning(disable : 4996)

typedef long long ll;
#define MIN(a, b) ((a) > (b) ? (b) : (a))
#define MAX(a, b) ((a) < (b) ? (b) : (a))
#define LINF 9223300000000000000
#define INF 2140000000
const long long MOD = 1000000007;
// const long long MOD = 998244353;
using namespace std;

char str[5005];
ll dp[5000][5005];

ll mpow(ll x, ll n) { // x^n(mod M)
  ll ans = 1;
  while (n != 0) {
    if (n & 1)
      ans = ans * x % MOD;
    x = x * x % MOD;
    n = n >> 1;
  }
  return ans;
}

ll minv(ll x) { return mpow(x, MOD - 2); }

int main(int argc, char *argv[]) {
  int n;
  scanf("%d", &n);
  scanf("%s", str);
  int m = strlen(str);

  dp[0][0] = 1;
  int i, j;
  for (i = 0; i < n; i++) {
    for (j = 0; j <= n; j++) {
      if (dp[i][j]) {
        dp[i + 1][j + 1] = (dp[i + 1][j + 1] + dp[i][j] * 2) % MOD;
        if (j > 0)
          dp[i + 1][j - 1] = (dp[i + 1][j - 1] + dp[i][j]) % MOD;
        if (j == 0)
          dp[i + 1][j] = (dp[i + 1][j] + dp[i][j]) % MOD;
      }
    }
  }
  ll ans = (dp[n][m] * minv(mpow(2, m))) % MOD;

  printf("%lld\n", ans);

  return 0;
}


Fixed submission:
#include <algorithm>
#include <assert.h>
#include <cstring>
#include <iterator>
#include <list>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <stdio.h>
#include <stdlib.h>
#include <string>
#include <vector>
#pragma warning(disable : 4996)

typedef long long ll;
#define MIN(a, b) ((a) > (b) ? (b) : (a))
#define MAX(a, b) ((a) < (b) ? (b) : (a))
#define LINF 9223300000000000000
#define INF 2140000000
const long long MOD = 1000000007;
// const long long MOD = 998244353;
using namespace std;

char str[5005];
ll dp[5005][5005];

ll mpow(ll x, ll n) { // x^n(mod M)
  ll ans = 1;
  while (n != 0) {
    if (n & 1)
      ans = ans * x % MOD;
    x = x * x % MOD;
    n = n >> 1;
  }
  return ans;
}

ll minv(ll x) { return mpow(x, MOD - 2); }

int main(int argc, char *argv[]) {
  int n;
  scanf("%d", &n);
  scanf("%s", str);
  int m = strlen(str);

  dp[0][0] = 1;
  int i, j;
  for (i = 0; i < n; i++) {
    for (j = 0; j <= n; j++) {
      if (dp[i][j]) {
        dp[i + 1][j + 1] = (dp[i + 1][j + 1] + dp[i][j] * 2) % MOD;
        if (j > 0)
          dp[i + 1][j - 1] = (dp[i + 1][j - 1] + dp[i][j]) % MOD;
        if (j == 0)
          dp[i + 1][j] = (dp[i + 1][j] + dp[i][j]) % MOD;
      }
    }
  }
  ll ans = (dp[n][m] * minv(mpow(2, m))) % MOD;

  printf("%lld\n", ans);

  return 0;
}
Problem p04028 (C++)

Buggy submission (status: Runtime Error):
#include <cstring>
#include <iostream>
#define N 5000
#define MOD 1000000007
using namespace std;
typedef long long LL;
LL dp[N + 1][N + 1];
LL solve() {
  int K;
  cin >> K;

  string s;
  cin >> s;
  int n = s.length();

  memset(dp, 0, sizeof dp);
  dp[0][0] = 1;
  for (int k = 1; k <= K; k++)
    for (int x = 0; x <= k; x++)
      if (x == 0)
        dp[x][k] = (dp[x][k - 1] + 2 * dp[x + 1][k - 1]) % MOD;
      else
        dp[x][k] = (dp[x - 1][k - 1] + 2 * dp[x + 1][k - 1]) % MOD;

  return dp[n][K];
}
int main() {
  cout << solve() << endl;
  return 0;
}


Fixed submission:
#include <cstring>
#include <iostream>
#define N 5000
#define MOD 1000000007
using namespace std;
typedef long long LL;
LL dp[N + 2][N + 2];
LL solve() {
  int K;
  cin >> K;

  string s;
  cin >> s;
  int n = s.length();

  memset(dp, 0, sizeof dp);
  dp[0][0] = 1;
  for (int k = 1; k <= K; k++)
    for (int x = 0; x <= k; x++)
      if (x == 0)
        dp[x][k] = (dp[x][k - 1] + 2 * dp[x + 1][k - 1]) % MOD;
      else
        dp[x][k] = (dp[x - 1][k - 1] + 2 * dp[x + 1][k - 1]) % MOD;

  return dp[n][K];
}
int main() {
  cout << solve() << endl;
  return 0;
}
Problem p04028 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <bitset>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;
using LL = long long;
using ULL = unsigned long long;
constexpr long long MOD = 1000000000 + 7;
constexpr long long INF = 1000000000;
const double PI = acos(-1);

LL dp[5001][5001];

int main() {
  int n;
  string s;
  cin >> n >> s;
  dp[0][0] = 1;
  for (int i = 0; i <= n; i++) {
    if (i != 0) {
      dp[i][0] += dp[i - 1][0];
    }
    for (int j = 1; j <= i; j++) {
      dp[i][j] += (dp[i - 1][j - 1] * 2) % MOD;
      dp[i + 1][j - 1] = (dp[i][j] + dp[i + 1][j - 1]) % MOD;
    }
  }
  LL ans = dp[n][s.size()];
  for (int i = 0; i < s.size(); i++) {
    ans = (ans * 500000004) % MOD;
  }
  cout << ans << endl;
}

Fixed submission:
#include <algorithm>
#include <bitset>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;
using LL = long long;
using ULL = unsigned long long;
constexpr long long MOD = 1000000000 + 7;
constexpr long long INF = 1000000000;
const double PI = acos(-1);

LL dp[5010][5010];

int main() {
  int n;
  string s;
  cin >> n >> s;
  dp[0][0] = 1;
  for (int i = 0; i <= n; i++) {
    if (i != 0) {
      dp[i][0] += dp[i - 1][0];
    }
    for (int j = 1; j <= i; j++) {
      dp[i][j] += (dp[i - 1][j - 1] * 2) % MOD;
      dp[i + 1][j - 1] = (dp[i][j] + dp[i + 1][j - 1]) % MOD;
    }
  }
  LL ans = dp[n][s.size()];
  for (int i = 0; i < s.size(); i++) {
    ans = (ans * 500000004) % MOD;
  }
  cout << ans << endl;
}
Problem p04028 (C++)

Buggy submission (status: Runtime Error):
#define FILEIO(a)                                                              \
  freopen(a ".in", "r", stdin);                                                \
  freopen(a ".out", "w", stdout);
#include <stdio.h>
#include <string.h>
#define N 2005
#define CLZ 1000000007
typedef long long ll;
int n, m, f[N][N];
char s[N];
inline ll qpow(ll a, int b) {
  ll ans = 1;
  for (; b; b >>= 1) {
    if (b & 1)
      ans = ans * a % CLZ;
    a = a * a % CLZ;
  }
  return ans;
}
int main() {
  // FILEIO("keyboard");
  int i, j, k, *cur, *nxt;
  scanf("%d%s", &n, s);
  m = strlen(s);
  f[0][0] = 1;
  for (i = 0; i < n; ++i) {
    cur = f[i];
    nxt = f[i + 1];
    for (j = 0; j <= i; ++j) {
      nxt[j + 1] = (nxt[j + 1] + (cur[j] << 1)) % CLZ;
      k = j ? j - 1 : 0;
      nxt[k] = (nxt[k] + cur[j]) % CLZ;
    }
  }
  printf("%d", int(f[n][m] * qpow(qpow(2, m), CLZ - 2) % CLZ));
  return 0;
}

Fixed submission:
#define FILEIO(a)                                                              \
  freopen(a ".in", "r", stdin);                                                \
  freopen(a ".out", "w", stdout);
#include <stdio.h>
#include <string.h>
#define N 5005
#define CLZ 1000000007
typedef long long ll;
int n, m, f[N][N];
char s[N];
inline ll qpow(ll a, int b) {
  ll ans = 1;
  for (; b; b >>= 1) {
    if (b & 1)
      ans = ans * a % CLZ;
    a = a * a % CLZ;
  }
  return ans;
}
int main() {
  // FILEIO("keyboard");
  int i, j, k, *cur, *nxt;
  scanf("%d%s", &n, s);
  m = strlen(s);
  f[0][0] = 1;
  for (i = 0; i < n; ++i) {
    cur = f[i];
    nxt = f[i + 1];
    for (j = 0; j <= i; ++j) {
      nxt[j + 1] = (nxt[j + 1] + (cur[j] << 1)) % CLZ;
      k = j ? j - 1 : 0;
      nxt[k] = (nxt[k] + cur[j]) % CLZ;
    }
  }
  printf("%d", int(f[n][m] * qpow(qpow(2, m), CLZ - 2) % CLZ));
  return 0;
}
Problem p04028 (C++)

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

using namespace std;

typedef long long ll;

const ll M = 1e9 + 7;
const int N = 10000;

ll dp[N][N];

int main() {
  // freopen("input.txt", "r", stdin);
  // freopen("output.txt", "w", stdout);
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int k;
  string s;
  cin >> k >> s;
  int n = s.length();
  dp[0][0] = 1;
  for (int i = 0; i < k; ++i) {
    for (int j = 0; j <= k + 1; ++j) {
      if (j) {
        dp[i + 1][j] = (dp[i][j - 1] + 2 * dp[i][j + 1]) % M;
      } else {
        dp[i + 1][j] = (dp[i][j] + 2 * dp[i][j + 1]) % M;
      }
    }
  }
  cout << dp[k][n];
  return 0;
}

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

using namespace std;

typedef long long ll;

const ll M = 1e9 + 7;
const int N = 5010;

ll dp[N][N];

int main() {
  // freopen("input.txt", "r", stdin);
  // freopen("output.txt", "w", stdout);
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int k;
  string s;
  cin >> k >> s;
  int n = s.length();
  dp[0][0] = 1;
  for (int i = 0; i < k; ++i) {
    for (int j = 0; j <= k + 1; ++j) {
      if (j) {
        dp[i + 1][j] = (dp[i][j - 1] + 2 * dp[i][j + 1]) % M;
      } else {
        dp[i + 1][j] = (dp[i][j] + 2 * dp[i][j + 1]) % M;
      }
    }
  }
  cout << dp[k][n];
  return 0;
}
Problem p04028 (C++)

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

using namespace std;

typedef long long ll;

ll MOD = 1000000007;

ll inverse(ll a) {
  ll pow = MOD - 2;
  ll res = 1;
  while (pow) {
    if (pow & 1)
      res = res * a % MOD;
    a = a * a % MOD;
    pow /= 2;
  }
  return res;
}

int n;
string s;
ll cache[15123][5123];
bool seen[15123][5123];

int dp(int t, int k) {
  if (t == 0 && k == 0)
    return 1;
  if (k == 0 && t)
    return 0;
  if (seen[t][k])
    return cache[t][k];
  seen[t][k] = true;

  // now k > 0, t whatever

  ll ans = 0;
  if (t)
    ans = (ans + 2 * dp(t - 1, k - 1)) % MOD;
  ans = (ans + dp(t + 1, k - 1)) % MOD;
  if (!t)
    ans = (ans + dp(t, k - 1)) % MOD;
  cache[t][k] = ans;
  return ans;
}

int main() {
  cin >> n >> s;
  ll ans = dp(s.length(), n);
  // cout << ans << '\n';
  const ll inv = inverse(2);
  for (int i = 0; i < s.length(); i++)
    ans = (ans * inv) % MOD;
  cout << ans << '\n';
  return 0;
}


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

using namespace std;

typedef long long ll;

ll MOD = 1000000007;

ll inverse(ll a) {
  ll pow = MOD - 2;
  ll res = 1;
  while (pow) {
    if (pow & 1)
      res = res * a % MOD;
    a = a * a % MOD;
    pow /= 2;
  }
  return res;
}

int n;
string s;
int cache[11123][5123];
bool seen[11123][5123];

int dp(int t, int k) {
  if (t == 0 && k == 0)
    return 1;
  if (k == 0 && t)
    return 0;
  if (seen[t][k])
    return cache[t][k];
  seen[t][k] = true;

  // now k > 0, t whatever

  ll ans = 0;
  if (t)
    ans = (ans + 2 * dp(t - 1, k - 1)) % MOD;
  ans = (ans + dp(t + 1, k - 1)) % MOD;
  if (!t)
    ans = (ans + dp(t, k - 1)) % MOD;
  cache[t][k] = ans;
  return ans;
}

int main() {
  cin >> n >> s;
  ll ans = dp(s.length(), n);
  // cout << ans << '\n';
  const ll inv = inverse(2);
  for (int i = 0; i < s.length(); i++)
    ans = (ans * inv) % MOD;
  cout << ans << '\n';
  return 0;
}
Problem p04028 (C++)

Buggy submission (status: Runtime Error):
#include <iostream>
#include <string>
using namespace std;

const long long mod = 1e9 + 7;

const int MAX_N = 5001;

long long dp[MAX_N][MAX_N];

int main() {
  int n;
  string str;
  cin >> n >> str;
  dp[0][0] = 1;
  for (int i = 1; i <= n; i++) {
    for (int j = 0; j <= i; j++) {
      if (j)
        dp[j][i] = (2 * dp[j - 1][i - 1] + dp[j + 1][i - 1]) % mod;
      else
        dp[j][i] = (dp[j + 1][i - 1] + dp[j][i - 1]) % mod;
    }
  }
  long long ans = dp[str.size()][n];
  for (int i = 0; i < str.size(); i++) {
    ans = (ans * 500000004) % mod;
  }
  cout << ans << endl;
}


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

const long long mod = 1e9 + 7;

const int MAX_N = 5003;

long long dp[MAX_N][MAX_N];

int main() {
  int n;
  string str;
  cin >> n >> str;
  dp[0][0] = 1;
  for (int i = 1; i <= n; i++) {
    for (int j = 0; j <= i; j++) {
      if (j)
        dp[j][i] = (2 * dp[j - 1][i - 1] + dp[j + 1][i - 1]) % mod;
      else
        dp[j][i] = (dp[j + 1][i - 1] + dp[j][i - 1]) % mod;
    }
  }
  long long ans = dp[str.size()][n];
  for (int i = 0; i < str.size(); i++) {
    ans = (ans * 500000004) % mod;
  }
  cout << ans << endl;
}
Problem p04029 (C++)

Buggy submission (status: Runtime Error):
#include <iostream>
using namespace std;

int main() {
  int n;
  cin >> n;
  return (n * (n + 1)) / 2;
  return 0;
}

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

int main() {
  int n;
  cin >> n;
  cout << (n * (n + 1)) / 2;
  return 0;
}
Problem p04029 (C++)

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

using namespace std;

int main() {

  int N;

  cin >> N;

  int ans = 0;

  for (int i = N; i >= 1; i++) {
    ans += i;
  }

  cout << ans << endl;

  return 0;
}


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

using namespace std;

int main() {

  int N;

  cin >> N;

  int ans = 0;

  for (int i = N; i >= 1; i--) {
    ans += i;
  }

  cout << ans << endl;

  return 0;
}
Problem p04029 (C++)

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

int main() {
  int i, n, sum;
  cin >> n;
  for (i = n; i > 0; i++) {
    sum += i;
  }
  cout << sum << endl;
  return 0;
}

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

int main() {
  int i, n, sum;
  cin >> n;
  for (i = n; i > 0; i--) {
    sum += i;
  }
  cout << sum << endl;
  return 0;
}
Problem p04029 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
typedef vector<int> VI;

int main() {
  int n;
  cin >> n;
  int sum = 0;
  for (int i = 1; i <= n; n++)
    sum += i;
  cout << sum << endl;

  return 0;
}

Fixed submission:
#include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
typedef vector<int> VI;

int main() {
  int n;
  cin >> n;
  int sum = 0;
  for (int i = 1; i <= n; i++)
    sum += i;
  cout << sum << endl;

  return 0;
}
Problem p04029 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define IOS                                                                    \
  ios_base::sync_with_stdio(false);                                            \
  cin.tie(NULL);                                                               \
  cout.tie(NULL);

void io_set() {
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif
}

int main() {
  IOS io_set();
  ll n;
  cin >> n;
  cout << (n * (n + 1)) / 2 << endl;
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define IOS                                                                    \
  ios_base::sync_with_stdio(false);                                            \
  cin.tie(NULL);                                                               \
  cout.tie(NULL);

void io_set() {
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif
}

int main() {
  IOS
      // io_set();
      ll n;
  cin >> n;
  cout << (n * (n + 1)) / 2 << endl;
  return 0;
}
Problem p04029 (C++)

Buggy submission (status: Runtime Error):
#include <cstdio>
int main() {
  int n;
  scanf("%d", n);
  printf("%d\n", n * (n + 1) / 2);
}

Fixed submission:
#include <cstdio>
int main() {
  int n;
  scanf("%d", &n);
  printf("%d\n", n * (n + 1) / 2);
}
Problem p04029 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <bitset>
#include <cmath>
#include <iostream>
#include <map>
#include <stdio.h>
#include <string>
#include <vector>

#define Vsort(a) sort(a.begin(), a.end())
#define Vreverse(a) reverse(a.begin(), a.end())
#define Srep(n) for (int i = 0; i < (n); i++)
#define Lrep(i, a, n) for (int i = (a); i < (n); i++)
#define Brep(n) for (int bit = 0; bit < (1 << n); bit++)
#define rep2nd(n, m) Srep(n) Lrep(j, 0, m)
#define vi vector<int>
#define vi64 vector<int64_t>
#define vvi vector<vector<int>>
#define vvi64 vector<vector<int64_t>>
#define P pair<int, int>
#define F first
#define S second

using namespace std;

int main() {
  int n;
  vi dp(n);
  dp[0] = 1;
  Lrep(i, 1, 100) dp[i] = dp[i - 1] + i + 1;
  cout << dp[n - 1] << endl;
}

Fixed submission:
#include <algorithm>
#include <bitset>
#include <cmath>
#include <iostream>
#include <map>
#include <stdio.h>
#include <string>
#include <vector>

#define Vsort(a) sort(a.begin(), a.end())
#define Vreverse(a) reverse(a.begin(), a.end())
#define Srep(n) for (int i = 0; i < (n); i++)
#define Lrep(i, a, n) for (int i = (a); i < (n); i++)
#define Brep(n) for (int bit = 0; bit < (1 << n); bit++)
#define rep2nd(n, m) Srep(n) Lrep(j, 0, m)
#define vi vector<int>
#define vi64 vector<int64_t>
#define vvi vector<vector<int>>
#define vvi64 vector<vector<int64_t>>
#define P pair<int, int>
#define F first
#define S second

using namespace std;

int main() {
  int n;
  cin >> n;
  vi dp(n);
  dp[0] = 1;
  Lrep(i, 1, 100) dp[i] = dp[i - 1] + i + 1;
  cout << dp[n - 1] << endl;
}
Problem p04029 (C++)

Buggy submission (status: Runtime Error):
#include <stdio.h>
#include <stdlib.h>
int main(void) {
  int N, n, sum;
  printf("请输入孩子数量\n");
  scanf("%d", &N);
  if (1 <= N <= 100) {
    sum = 0;
    for (n = 1; n <= N; n = n + 1) {
      sum = sum + n;
    }
  } else
    (N <= 1 & N >= 100);
  {
    printf("输入错误\n", sum);
    return n;
  }
  printf("Sum is %d.\n", sum);

  return 0;
}


Fixed submission:
#include <cstdio>
#include <iostream>
using namespace std;
int main() {
  int i;
  cin >> i;
  cout << (1 + i) * i / 2 << endl;
  return 0;
}
Problem p04029 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <stdio.h>
int main() {
  int sum = 0;
  int N = 1;
  while (N <= 100)
    ;
  sum = sum + N;
  N = N + 1;
  printf("%d\n", sum);
  return 0;
}

Fixed submission:
#include <stdio.h>
int main() {
  int n, i = 1, sum = 0;
  scanf("%d", &n);
  while (i <= n) {
    sum += i;
    ++i;
  }
  printf("%d", sum);
  return 0;
}
Problem p04029 (Python)

Buggy submission (status: Runtime Error):
N = input()
print(N * (N + 1) / 2)


Fixed submission:
N = int(input())
print(int(N * (N + 1) / 2))
Problem p04029 (C++)

Buggy submission (status: Runtime Error):
#include <stdio.h>
int main() {
  int a, r = 0, i;
  scanf("%d", a);
  for (i = 1; i <= a; i++) {
    r += i;
  }
  printf("%d", r);
}

Fixed submission:
#include <stdio.h>
int main() {
  int a, r = 0, i;
  scanf("%d", &a);
  for (i = 1; i <= a; i++) {
    r += i;
  }
  printf("%d", r);
}
Problem p04029 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;

#define INF 210000000
#define int long long

int gcd(int a, int b) {
  int amari = a % b;
  int c = b;
  if (amari == 0) {
    return b;
  } else {
    return gcd(b, amari);
  }
}

int lcm(int a, int b) { return a * b / gcd(a, b); }
void solve() {
  int n;
  cin >> n;
  int ans = 1;
  for (int i = n; i > 0; i++) {
    ans *= n;
  }
  cout << ans;
}
signed main() { solve(); }


Fixed submission:
#include <algorithm>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;

#define INF 210000000
#define int long long

int gcd(int a, int b) {
  int amari = a % b;
  int c = b;
  if (amari == 0) {
    return b;
  } else {
    return gcd(b, amari);
  }
}

int lcm(int a, int b) { return a * b / gcd(a, b); }
void solve() {
  int n;
  cin >> n;
  int ans = 0;
  for (int i = n; i > 0; i--) {
    ans += i;
  }
  cout << ans;
}
signed main() { solve(); }
Problem p04029 (C++)

Buggy submission (status: Runtime Error):
/**
 *       Author:  kulubat
 *       Written on Thursday, 16 April 2020.
 **/

#include <bits/stdc++.h>

using namespace std;

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

  int n;

  cin >> n;

  return n * (n + 1) / 2;
}


Fixed submission:
/**
 *       Author:  kulubat
 *       Written on Thursday, 16 April 2020.
 **/

#include <bits/stdc++.h>

using namespace std;

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

  int n;

  cin >> n;

  cout << n * (n + 1) / 2 << "\n";

  return 0;
}
Problem p04030 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
int main() {
  string S;
  string ans = "";
  cin >> S;
  for (int X = 0; X < S.size(); X++) {
    if (S[X] == '1' || S[X] == '0') {
      ans.push_back(S[X]);
    } else if (S[X] == 'B' && S.size() != 0) {
      ans.erase(ans.size() - 1);
    }
  }
  cout << ans << endl;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int main() {
  string S;
  string ans = "";
  cin >> S;
  for (int X = 0; X < S.size(); X++) {
    if (S[X] == '1' || S[X] == '0') {
      ans.push_back(S[X]);
    } else if (S[X] == 'B' && ans.size() != 0) {
      ans.erase(ans.size() - 1);
    }
  }
  cout << ans << endl;
}
Problem p04030 (C++)

Buggy submission (status: Runtime Error):
#include <iostream>
#include <string>
using namespace std;
int main() {
  string S, result;
  cin >> S;
  for (int index = 0; index < S.length(); index++) {
    if (S[index] == 'B') {
      if (result.length() != 0) {
        result.erase(index - 1);
      }
    } else {
      result += S[index];
    }
  }
  cout << result << "\n";
}

Fixed submission:
#include <iostream>
#include <string>
using namespace std;
int main() {
  string S, result;
  cin >> S;
  for (int index = 0; index < S.length(); index++) {
    if (S[index] == 'B') {
      if (result.length() != 0) {
        result.erase(result.length() - 1);
      }
    } else {
      result += S[index];
    }
  }
  cout << result << "\n";
}
Problem p04030 (C++)

Buggy submission (status: Runtime Error):
#include <iostream>
#include <string>
using namespace std;

int main() {

  string str;
  string str2;

  cin >> str;

  int i;
  for (i = 0; i < str.size(); i++) {

    if (str[i] == '0' || str[i] == '1') {

      str2.push_back(str[i]);
    } else {

      str2.pop_back();
    }
  }

  cout << str2 << endl;
}

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

int main() {

  string str;
  string str2;

  cin >> str;

  int i;
  for (i = 0; i < str.size(); i++) {

    if (str[i] == '0' || str[i] == '1') {

      str2.push_back(str[i]);
    } else {

      if (str2[0] != '\0') {
        str2.pop_back();
      }
    }
  }

  cout << str2 << endl;
}
Problem p04030 (C++)

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

int main() {
  string S;
  cin >> S;
  string ans = "";
  for (auto s : S) {
    if (s == '0')
      ans += '0';
    else if (s == '1')
      ans += '1';
    else
      ans.erase(ans.size() - 1);
  }
  cout << ans << endl;
}

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

int main() {
  string S;
  cin >> S;
  string ans = "";
  for (auto s : S) {
    if (s == '0')
      ans += '0';
    else if (s == '1')
      ans += '1';
    else if (!ans.empty())
      ans.erase(ans.size() - 1);
  }
  cout << ans << endl;
}
Problem p04030 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
#define endl "\n"
#define FIO                                                                    \
  ios_base::sync_with_stdio(false);                                            \
  cin.tie(0);                                                                  \
  cout.tie(0);
#define ll long long
#define vi vector<ll>
#define pb push_back
#define F first
#define S second
#define all(v) (v).begin(), (v).end()
#define pii pair<ll, ll>
#define vii vector<pii>
#define MOD 1000000007LL
#define calc_fact(n) tgamma(n + 1)
#define INF LONG_LONG_MAX

signed main() {
  FIO;
  string str;
  deque<char> q;
  cin >> str;
  for (ll i = 0; i < str.length(); i++) {
    if (str[i] == '1')
      q.pb('1');
    else if (str[i] == '0')
      q.pb('0');
    else
      q.pop_back();
  }
  while (!q.empty()) {
    cout << q.front();
    q.pop_front();
  }
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define endl "\n"
#define FIO                                                                    \
  ios_base::sync_with_stdio(false);                                            \
  cin.tie(0);                                                                  \
  cout.tie(0);
#define ll long long
#define vi vector<ll>
#define pb push_back
#define F first
#define S second
#define all(v) (v).begin(), (v).end()
#define pii pair<ll, ll>
#define vii vector<pii>
#define MOD 1000000007LL
#define calc_fact(n) tgamma(n + 1)
#define INF LONG_LONG_MAX

signed main() {
  FIO;
  string str;
  deque<char> q;
  cin >> str;
  for (ll i = 0; i < str.length(); i++) {
    if (str[i] == '1')
      q.pb('1');
    else if (str[i] == '0')
      q.pb('0');
    else if (str[i] == 'B' and !q.empty())
      q.pop_back();
  }
  while (!q.empty()) {
    cout << q.front();
    q.pop_front();
  }
}
Problem p04030 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
int main() {
  string t;
  char c;
  while (cin >> c)
    c == 'B' ? t.pop_back(), t : t += c;
  cout << t;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int main() {
  string t;
  char c;
  while (cin >> c)
    c == 'B' ? t != "" ? t.pop_back(), t : t : t += c;
  cout << t;
}
Problem p04030 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const ll INF = 1LL << 29;
const ll mod = 1e9 + 7;
#define rep(i, n) for (int(i) = 0; (i) < (ll)(n); ++(i))
#define repd(i, n, d) for (ll(i) = 0; (i) < (ll)(n); (i) += (d))
#define all(v) (v).begin(), (v).end()
#define pb(x) push_back(x)
#define mp(x, y) make_pair((x), (y))
#define mset(m, v) memset((m), (v), sizeof(m))
#define chmin(x, y) (x = min(x, y))
#define chmax(x, y) (x = max(x, y))
#define fst first
#define snd second
#define UNIQUE(x) (x).erase(unique(all(x)), (x).end())
template <class T> ostream &operator<<(ostream &os, const vector<T> &v) {
  int n = v.size();
  rep(i, n) os << v[i] << (i == n - 1 ? "" : " ");
  return os;
}

int main() {
  string s, res;
  cin >> s;
  for (auto c : s) {
    if (c == 'B')
      res.erase(res.end() - 1);
    else
      res += c;
  }
  cout << res << endl;
  return 0;
}


Fixed submission:
#include <algorithm>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const ll INF = 1LL << 29;
const ll mod = 1e9 + 7;
#define rep(i, n) for (int(i) = 0; (i) < (ll)(n); ++(i))
#define repd(i, n, d) for (ll(i) = 0; (i) < (ll)(n); (i) += (d))
#define all(v) (v).begin(), (v).end()
#define pb(x) push_back(x)
#define mp(x, y) make_pair((x), (y))
#define mset(m, v) memset((m), (v), sizeof(m))
#define chmin(x, y) (x = min(x, y))
#define chmax(x, y) (x = max(x, y))
#define fst first
#define snd second
#define UNIQUE(x) (x).erase(unique(all(x)), (x).end())
template <class T> ostream &operator<<(ostream &os, const vector<T> &v) {
  int n = v.size();
  rep(i, n) os << v[i] << (i == n - 1 ? "" : " ");
  return os;
}

int main() {
  string s, res;
  cin >> s;
  for (auto c : s) {
    if (c == 'B') {
      if (!res.empty())
        res.erase(res.end() - 1);
    } else
      res += c;
  }
  cout << res << endl;
  return 0;
}
Problem p04030 (C++)

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

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);

  int t = 1;
  // cin>>t;
  while (t--) {
    string s;
    cin >> s;
    string ans;
    for (int i = 0; i < s.size(); ++i) {
      if (s[i] == '0')
        ans.pb('0');
      else if (s[i] == '1')
        ans.pb('1');
      else
        ans.pop_back();
    }
    cout << ans;
  }
}


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

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);

  int t = 1;
  // cin>>t;
  while (t--) {
    string s;
    cin >> s;
    string ans;
    for (int i = 0; i < s.size(); ++i) {
      if (s[i] == '0')
        ans.pb('0');
      else if (s[i] == '1')
        ans.pb('1');
      else if (ans.size() > 0)
        ans.pop_back();
    }
    cout << ans;
  }
}
Problem p04030 (C++)

Buggy submission (status: Runtime Error):
#include <iostream>
#include <string>
using namespace std;

int main() {
  string s, ans;
  cin >> s;
  for (int i = 0; i < s.length(); i++) {
    if (s[i] == '0')
      ans += '0';
    else if (s[i] == '1')
      ans += '1';
    else
      ans.erase(ans.end() - 1);
  }
  cout << ans << endl;

  return 0;
}

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

int main() {
  string s, ans;
  cin >> s;
  for (int i = 0; i < s.length(); i++) {
    if (s[i] == '0')
      ans += '0';
    else if (s[i] == '1')
      ans += '1';
    else if (ans.length() > 0)
      ans.erase(ans.end() - 1);
  }
  cout << ans << endl;

  return 0;
}
Problem p04030 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;
int main() {
  char s[10];
  int i = 0;
  string str("");
  while (cin >> s[i]) {
    i++;
  }
  for (int j = 0; j < i; j++) {
    if (s[j] == '0') {
      str += '0';
    } else if (s[j] == '1') {
      str += '1';
    } else {
      str.erase(str.size() - 1);
    }
  }
  cout << str << endl;
}


Fixed submission:
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;
int main() {
  char s[10];
  int i = 0;
  string str("");
  while (cin >> s[i]) {
    i++;
  }
  for (int j = 0; j < i; j++) {
    if (s[j] == '0') {
      str += '0';
    } else if (s[j] == '1') {
      str += '1';
    } else {
      if (str.size() > 0) {
        str.erase(str.size() - 1);
      }
    }
  }
  cout << str << endl;
}
Problem p04030 (C++)

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

int main() {
  string s, a;
  cin >> s;

  for (int i = 0; i < s.size(); i++) {
    if (s.at(i) == '0')
      a += '0';
    if (s.at(i) == '1')
      a += '1';
    if (s.at(i) == 'B' && s.size() != 0)
      a.pop_back();
  }

  cout << a << endl;
}


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

int main() {
  string s, a;
  cin >> s;

  for (int i = 0; i < s.size(); i++) {
    if (s.at(i) == '0')
      a += '0';
    if (s.at(i) == '1')
      a += '1';
    if (s.at(i) == 'B' && a.size() != 0)
      a.pop_back();
  }

  cout << a << endl;
}
Problem p04030 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
int main(void) {
  string input;
  string output;
  cin >> input;
  for (int i = 0; i < input.length(); i++) {
    output += input[i];
    if (input[i] == 'B') {
      if (i == 0) {
        output.pop_back();
        continue;
      }
      output.pop_back();
      output.pop_back();
    }
  }

  cout << output;
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int main(void) {
  string input;
  string output;
  cin >> input;
  for (int i = 0; i < input.length(); i++) {
    output += input[i];
    if (input[i] == 'B') {
      if (output.length() == 1) {
        output.pop_back();
        continue;
      }
      output.pop_back();
      output.pop_back();
    }
  }

  cout << output;
  return 0;
}
Problem p04030 (C++)

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

int main() {
  string S;
  cin >> S;
  string ans;
  for (int i = 0; i < S.size(); i++) {
    if (S[i] == '0') {
      ans += '0';
    } else if (S[i] == '1') {
      ans += '1';
    } else if (S[i] == 'B' && S.size() > 0) {
      ans.pop_back();
    }
  }
  cout << ans << endl;
}

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

int main() {
  string S;
  cin >> S;
  string ans;
  for (int i = 0; i < S.size(); i++) {
    if (S[i] == '0') {
      ans += '0';
    } else if (S[i] == '1') {
      ans += '1';
    } else if (S[i] == 'B' && ans.size() > 0) {
      ans.pop_back();
    }
  }
  cout << ans << endl;
}
Problem p04030 (C++)

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

int main() {
  string s;
  cin >> s;
  vector<char> data;
  for (int i = 0; i < s.size(); i++) {
    if (s.at(i) == '0') {
      data.push_back('0');
    } else if (s.at(i) == '1') {
      data.push_back('1');
    } else {
      data.pop_back();
    }
  }
  for (int i = 0; i < data.size(); i++) {
    cout << data.at(i);
  }
  cout << endl;
}

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

int main() {
  string s;
  cin >> s;
  vector<char> data;
  for (int i = 0; i < s.size(); i++) {
    if (s.at(i) == '0') {
      data.push_back('0');
    } else if (s.at(i) == '1') {
      data.push_back('1');
    } else if (s.at(i) == 'B' && data.size() == 0) {
    } else {
      data.pop_back();
    }
  }
  for (int i = 0; i < data.size(); i++) {
    cout << data.at(i);
  }
  cout << endl;
}
Problem p04030 (C++)

Buggy submission (status: Runtime Error):
#include <iostream>
#include <string>
using namespace std;

int main() {
  string s;
  string ans = "";
  cin >> s;
  for (int i = 0; i < s.size(); i++) {
    if (s[i] == '0')
      ans += '0';
    else if (s[i] == '1')
      ans += '1';
    else
      ans.pop_back();
  }
  cout << ans << endl;
}

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

int main() {
  string s;
  string ans = "";
  cin >> s;
  for (int i = 0; i < s.size(); i++) {
    if (s[i] == '0')
      ans += '0';
    else if (s[i] == '1')
      ans += '1';
    else if (s[i] == 'B' && ans != "")
      ans.pop_back();
  }
  cout << ans << endl;
}