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

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define INF 0x7fffffff
using namespace std;
typedef long long ll;
inline ll min(ll x, ll y) { return x < y ? x : y; }
inline ll max(ll x, ll y) { return x > y ? x : y; }
const int Maxn = 1e5 + 5;
char s[Maxn];
int n, f[Maxn][2];
int main() {
  cin >> n >> s + 1;
  for (int i = 1; i <= n; i++) {
    f[i][0] = f[i - 1][0] + (s[i] != '.');
    f[i][1] = min(f[i - 1][0], f[i - 1][1]) + (s[i] != '#');
  }
  cout << min(f[n][0], f[n][1]) << endl;
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
#define INF 0x7fffffff
using namespace std;
typedef long long ll;
inline ll min(ll x, ll y) { return x < y ? x : y; }
inline ll max(ll x, ll y) { return x > y ? x : y; }
const int Maxn = 2e5 + 5;
char s[Maxn];
int n, f[Maxn][2];
int main() {
  cin >> n >> s + 1;
  for (int i = 1; i <= n; i++) {
    f[i][0] = f[i - 1][0] + (s[i] != '.');
    f[i][1] = min(f[i - 1][0], f[i - 1][1]) + (s[i] != '#');
  }
  cout << min(f[n][0], f[n][1]) << endl;
  return 0;
}
Problem p03063 (C++)

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

using namespace std;

#define rep(i, n) REP(i, 0, n)
#define REP(i, s, e) for (int i = (s); i < (int)(e); i++)
#define repr(i, n) REPR(i, n, 0)
#define REPR(i, s, e) for (int i = (int)(s - 1); i >= (int)(e); i--)
#define pb push_back
#define all(r) r.begin(), r.end()
#define rall(r) r.rbegin(), r.rend()
#define fi first
#define se second

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const int INF = 1e9;
const ll MOD = 1e9 + 7;
double EPS = 1e-8;

const int MAX_N = 1e5 + 10;
int dp[MAX_N][2];

template <typename T> T chmax(T &a, const T &b) { return a = (a > b ? a : b); }
template <typename T> T chmin(T &a, const T &b) { return a = (a < b ? a : b); }

int main() {
  rep(i, MAX_N) rep(j, 2) dp[i][j] = INF;
  int n;
  cin >> n;
  string s;
  cin >> s;
  if (s[0] == '#') {
    dp[0][1] = 0;
    dp[0][0] = 1;
  } else {
    dp[0][0] = 0;
    dp[0][1] = 1;
  }
  REP(i, 1, n) {
    if (s[i] == '#') {
      chmin(dp[i][1], dp[i - 1][1]);
      chmin(dp[i][1], dp[i - 1][0]);

      // chmin(dp[i][0], dp[i-1][1]+1);
      chmin(dp[i][0], dp[i - 1][0] + 1);
    } else {
      chmin(dp[i][0], dp[i - 1][0]);
      // chmin(dp[i][0], dp[i-1][1]);

      chmin(dp[i][1], dp[i - 1][0] + 1);
      chmin(dp[i][1], dp[i - 1][1] + 1);
    }
  }
  cout << min(dp[n - 1][0], dp[n - 1][1]) << endl;
  return 0;
}

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

using namespace std;

#define rep(i, n) REP(i, 0, n)
#define REP(i, s, e) for (int i = (s); i < (int)(e); i++)
#define repr(i, n) REPR(i, n, 0)
#define REPR(i, s, e) for (int i = (int)(s - 1); i >= (int)(e); i--)
#define pb push_back
#define all(r) r.begin(), r.end()
#define rall(r) r.rbegin(), r.rend()
#define fi first
#define se second

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const int INF = 1e9;
const ll MOD = 1e9 + 7;
double EPS = 1e-8;

const int MAX_N = 2e5 + 10;
int dp[MAX_N][2];

template <typename T> T chmax(T &a, const T &b) { return a = (a > b ? a : b); }
template <typename T> T chmin(T &a, const T &b) { return a = (a < b ? a : b); }

int main() {
  rep(i, MAX_N) rep(j, 2) dp[i][j] = INF;
  int n;
  cin >> n;
  string s;
  cin >> s;
  if (s[0] == '#') {
    dp[0][1] = 0;
    dp[0][0] = 1;
  } else {
    dp[0][0] = 0;
    dp[0][1] = 1;
  }
  REP(i, 1, n) {
    if (s[i] == '#') {
      chmin(dp[i][1], dp[i - 1][1]);
      chmin(dp[i][1], dp[i - 1][0]);

      // chmin(dp[i][0], dp[i-1][1]+1);
      chmin(dp[i][0], dp[i - 1][0] + 1);
    } else {
      chmin(dp[i][0], dp[i - 1][0]);
      // chmin(dp[i][0], dp[i-1][1]);

      chmin(dp[i][1], dp[i - 1][0] + 1);
      chmin(dp[i][1], dp[i - 1][1] + 1);
    }
  }
  cout << min(dp[n - 1][0], dp[n - 1][1]) << endl;
  return 0;
}
Problem p03063 (C++)

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

const int N = 1e5;

int cntW[N];
int cntB[N];

int main() {
  int n;
  string s;
  cin >> n >> s;

  cntW[0] = cntB[0] = 0;
  for (int i = 0; i < n; ++i) {
    cntW[i + 1] = cntW[i] + (s[i] == '.');
    cntB[i + 1] = cntB[i] + (s[i] == '#');
  }

  int ans = 1e9;
  for (int i = 0; i <= n; ++i)
    ans = min(ans, cntB[i] + cntW[n] - cntW[i]);

  printf("%d", ans);
}


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

const int N = 2e5 + 5;

int cntW[N];
int cntB[N];

int main() {
  int n;
  string s;
  cin >> n >> s;

  cntW[0] = cntB[0] = 0;
  for (int i = 0; i < n; ++i) {
    cntW[i + 1] = cntW[i] + (s[i] == '.');
    cntB[i + 1] = cntB[i] + (s[i] == '#');
  }

  int ans = 1e9;
  for (int i = 0; i <= n; ++i)
    ans = min(ans, cntB[i] + cntW[n] - cntW[i]);

  printf("%d", ans);
}
Problem p03063 (C++)

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

using namespace std;

typedef long long LL;
typedef pair<int, int> pii;

int N;
int S[100010];
char s[100010];

int main() {
  scanf("%d", &N);
  scanf("%s", s + 1);
  for (int i = 1; i <= N; i++) {
    S[i] = S[i - 1];
    if (s[i] == '#') {
      S[i]++;
    }
  }
  int ans = 1e9;
  for (int i = 0; i <= N; i++) {
    ans = min(ans, S[i] + N - i - (S[N] - S[i]));
  }
  printf("%d\n", ans);
}

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

using namespace std;

typedef long long LL;
typedef pair<int, int> pii;

int N;
int S[200010];
char s[200010];

int main() {
  scanf("%d", &N);
  scanf("%s", s + 1);
  for (int i = 1; i <= N; i++) {
    S[i] = S[i - 1];
    if (s[i] == '#') {
      S[i]++;
    }
  }
  int ans = 1e9;
  for (int i = 0; i <= N; i++) {
    ans = min(ans, S[i] + N - i - (S[N] - S[i]));
  }
  printf("%d\n", ans);
}
Problem p03063 (C++)

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

using namespace std;

const int maxn = 100000 + 5;

int n;
char a[maxn];
int pre[maxn];

void inline Init() {
  scanf("%d %s", &n, a + 1);
  for (int i = 1; i <= n; ++i)
    pre[i] = pre[i - 1] + (a[i] == '#');
}

int ans = 0x7fffffff;
void inline Solve() {
  for (int i = 0; i <= n; ++i) {
    int x = pre[i];
    int y = (n - i) - (pre[n] - pre[i]);
    //		cerr << x << ' ' << y << endl;
    ans = min(ans, x + y);
  }
  printf("%d\n", ans);
}

int main() {
  Init();
  Solve();
  return 0;
}

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

using namespace std;

const int maxn = 200000 + 5;

int n;
char a[maxn];
int pre[maxn];

void inline Init() {
  scanf("%d %s", &n, a + 1);
  for (int i = 1; i <= n; ++i)
    pre[i] = pre[i - 1] + (a[i] == '#');
}

int ans = 0x7fffffff;
void inline Solve() {
  for (int i = 0; i <= n; ++i) {
    int x = pre[i];
    int y = (n - i) - (pre[n] - pre[i]);
    //		cerr << x << ' ' << y << endl;
    ans = min(ans, x + y);
  }
  printf("%d\n", ans);
}

int main() {
  Init();
  Solve();
  return 0;
}
Problem p03063 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
int main() {
  int n, ans[20001] = {0};
  string s;
  cin >> n >> s;
  reverse(s.begin(), s.end());
  rep(i, n) if (s[i] == '#') ans[0]++;
  rep(i, n) {
    if (s[i] == '#')
      ans[i + 1] = ans[i] - 1;
    else
      ans[i + 1] = ans[i] + 1;
  }
  sort(ans, ans + n + 1);
  cout << ans[0];
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
int main() {
  int n, ans[200001] = {0};
  string s;
  cin >> n >> s;
  reverse(s.begin(), s.end());
  rep(i, n) if (s[i] == '#') ans[0]++;
  rep(i, n) {
    if (s[i] == '#')
      ans[i + 1] = ans[i] - 1;
    else
      ans[i + 1] = ans[i] + 1;
  }
  sort(ans, ans + n + 1);
  cout << ans[0];
}
Problem p03063 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <iostream>
#define ll long long
using namespace std;
const int N = 100005;
int n, sum[N], b[N], ans = 1e9;
char s[N];

inline void read(int &i) {
  i = 0;
  char c = getchar();
  bool j = 0;
  for (; !isdigit(c); c = getchar())
    if (c == '-')
      j = 1;
  for (; isdigit(c); c = getchar())
    i = (i << 1) + (i << 3) + c - '0';
  i = j ? -i : i;
}

int main() {
  read(n);
  scanf("%s", s + 1);
  for (int i = 1; i <= n; ++i)
    sum[i] = sum[i - 1] + (s[i] == '.');
  for (int i = n; i >= 1; --i)
    b[i] = b[i + 1] + (s[i] == '#');
  for (int i = 0; i <= n; ++i) {
    ans = min(ans, (i - sum[i]) + (n - i - b[i + 1]));
  }
  printf("%d\n", ans);
  return 0;
}

Fixed submission:
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <iostream>
#define ll long long
using namespace std;
const int N = 200005;
int n, sum[N], b[N], ans = 1e9;
char s[N];

inline void read(int &i) {
  i = 0;
  char c = getchar();
  bool j = 0;
  for (; !isdigit(c); c = getchar())
    if (c == '-')
      j = 1;
  for (; isdigit(c); c = getchar())
    i = (i << 1) + (i << 3) + c - '0';
  i = j ? -i : i;
}

int main() {
  read(n);
  scanf("%s", s + 1);
  for (int i = 1; i <= n; ++i)
    sum[i] = sum[i - 1] + (s[i] == '.');
  for (int i = n; i >= 1; --i)
    b[i] = b[i + 1] + (s[i] == '#');
  for (int i = 0; i <= n; ++i) {
    ans = min(ans, (i - sum[i]) + (n - i - b[i + 1]));
  }
  printf("%d\n", ans);
  return 0;
}
Problem p03063 (C++)

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

int B[101010];
int W[101010];

int b(int l, int r) { return B[r] - B[l - 1]; }
int w(int l, int r) { return W[r] - W[l - 1]; }

int main() {

  int N;
  cin >> N;
  int ans = N;
  for (int i = 2; i <= N + 1; i++) {
    char c;
    cin >> c;
    B[i] = B[i - 1];
    W[i] = W[i - 1];
    if (c == '#')
      B[i]++;
    else
      W[i]++;
  }
  B[N + 2] = B[N + 1];
  W[N + 2] = W[N + 1];
  for (int i = 1; i <= N + 1; i++) {
    int tmp = b(1, i) + w(i + 1, N + 2);
    ans = min(ans, tmp);
  }
  cout << ans << endl;

  return 0;
}

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

int B[201010];
int W[201010];

int b(int l, int r) { return B[r] - B[l - 1]; }
int w(int l, int r) { return W[r] - W[l - 1]; }

int main() {

  int N;
  cin >> N;
  int ans = N;
  for (int i = 2; i <= N + 1; i++) {
    char c;
    cin >> c;
    B[i] = B[i - 1];
    W[i] = W[i - 1];
    if (c == '#')
      B[i]++;
    else
      W[i]++;
  }
  B[N + 2] = B[N + 1];
  W[N + 2] = W[N + 1];
  for (int i = 1; i <= N + 1; i++) {
    int tmp = b(1, i) + w(i + 1, N + 2);
    ans = min(ans, tmp);
  }
  cout << ans << endl;

  return 0;
}
Problem p03063 (C++)

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

const int INF = 1 << 30;

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

  int n;
  cin >> n;
  string s;
  cin >> s;

  vector<int> b(n, INF), w(n, INF);
  b[0] = w[0] = 0;
  for (int i = 0; i < n; i++) {
    b[i + 1] = min(b[i], w[i]) + (s[i] != '#');
    w[i + 1] = w[i] + (s[i] != '.');
  }
  cout << min(b[n], w[n]) << endl;

  return 0;
}


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

const int INF = 1 << 30;

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

  int n;
  cin >> n;
  string s;
  cin >> s;

  vector<int> b(n + 1, INF), w(n + 1, INF);
  b[0] = w[0] = 0;
  for (int i = 0; i < n; i++) {
    b[i + 1] = min(b[i], w[i]) + (s[i] != '#');
    w[i + 1] = w[i] + (s[i] != '.');
  }
  cout << min(b[n], w[n]) << endl;

  return 0;
}
Problem p03064 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int max_n = 305;
const int mod = 998244353;
int n, a[max_n];
int dp[max_n][max_n];
int f[max_n][max_n];
int Pow(int a, int b) {
  int res = 1;
  while (b) {
    if (b & 1)
      res = 1ll * res * a % mod;
    b >>= 1;
    a = 1ll * a * a % mod;
  }
  return res;
}
int main() {
  scanf("%d", &n);
  int sum = 0;
  for (int i = 1; i <= n; i++)
    scanf("%d", a + i), sum += a[i];
  int t = (sum + 1) / 2;
  dp[0][0] = 1;
  for (int i = 1; i <= n; i++) {
    for (int j = 0; j <= sum; j++) {
      dp[i][j] += dp[i - 1][j] * 2 % mod, dp[i][j] %= mod;
      if (j >= a[i])
        dp[i][j] += dp[i - 1][j - a[i]], dp[i][j] %= mod;
    }
  }
  int ans = 0;
  for (int i = t; i <= sum; i++)
    ans += dp[n][i], ans %= mod;
  ans = 1ll * ans * 3 % mod;
  if (sum % 2 == 0) {
    f[0][0] = 1;
    for (int i = 1; i <= n; i++) {
      for (int j = 0; j <= sum; j++) {
        f[i][j] += f[i - 1][j], f[i][j] %= mod;
        if (j >= a[i])
          f[i][j] += f[i - 1][j - a[i]], f[i][j] %= mod;
      }
    }
    ans += mod - 1ll * 3 * f[n][t] % mod, ans %= mod;
  }
  ans = (Pow(3, n) + mod - ans) % mod;
  printf("%d\n", ans);
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int max_n = 305;
const int mod = 998244353;
int n, a[max_n];
int dp[max_n][90005];
int f[max_n][90005];
int Pow(int a, int b) {
  int res = 1;
  while (b) {
    if (b & 1)
      res = 1ll * res * a % mod;
    b >>= 1;
    a = 1ll * a * a % mod;
  }
  return res;
}
int main() {
  scanf("%d", &n);
  int sum = 0;
  for (int i = 1; i <= n; i++)
    scanf("%d", a + i), sum += a[i];
  int t = (sum + 1) / 2;
  dp[0][0] = 1;
  for (int i = 1; i <= n; i++) {
    for (int j = 0; j <= sum; j++) {
      dp[i][j] += dp[i - 1][j] * 2 % mod, dp[i][j] %= mod;
      if (j >= a[i])
        dp[i][j] += dp[i - 1][j - a[i]], dp[i][j] %= mod;
    }
  }
  int ans = 0;
  for (int i = t; i <= sum; i++)
    ans += dp[n][i], ans %= mod;
  ans = 1ll * ans * 3 % mod;
  if (sum % 2 == 0) {
    f[0][0] = 1;
    for (int i = 1; i <= n; i++) {
      for (int j = 0; j <= sum; j++) {
        f[i][j] += f[i - 1][j], f[i][j] %= mod;
        if (j >= a[i])
          f[i][j] += f[i - 1][j - a[i]], f[i][j] %= mod;
      }
    }
    ans += mod - 1ll * 3 * f[n][t] % mod, ans %= mod;
  }
  ans = (Pow(3, n) + mod - ans) % mod;
  printf("%d\n", ans);
  return 0;
}
Problem p03064 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
#define N 300
#define A 300
#define mod 998244353
int a[N + 1], dp1[2][N * A / 2 + 1], dp2[2][N * A / 2 + 1], Sum[N + 1];
int main() {
  int n, imp = 0, power = 1, i, j;
  scanf("%d", &n);
  for (i = 1; i <= n; i++)
    scanf("%d", a + i), Sum[i] = Sum[i - 1] + a[i], power = 3ll * power % mod;
  dp1[0][0] = 1;
  for (i = 1; i <= n; i++)
    for (j = 0; j <= Sum[i]; j++)
      dp1[i & 1][j] = (2 * dp1[i - 1 & 1][j] % mod +
                       (j >= a[i] ? dp1[i - 1 & 1][j - a[i]] : 0)) %
                      mod
          //		,printf("dp[%d][%d]=%d\n",i,j,dp1[i&1][j])
          ;
  for (i = Sum[n] + 1 >> 1; i <= Sum[n]; i++)
    imp += 3ll * dp1[n & 1][i] % mod, imp %= mod;
  if (!(Sum[n] & 1)) {
    dp2[0][0] = 1;
    for (i = 1; i <= n; i++)
      for (j = 0; j <= Sum[i]; j++)
        dp2[i & 1][j] =
            (dp2[i - 1 & 1][j] + (j >= a[i] ? dp2[i - 1 & 1][j - a[i]] : 0)) %
            mod;
    imp -= 3ll * dp2[n & 1][Sum[n] >> 1] % mod;
    while (imp < 0)
      imp += mod;
    imp %= mod;
  }
  power -= imp;
  if (power < 0)
    power += mod;
  printf("%d\n", power);
  return 0;
}
/*1
4
1
1
1
2
*/
/*2
6
1
3
2
3
5
2
*/
/*3
20
3
1
4
1
5
9
2
6
5
3
5
8
9
7
9
3
2
3
8
4
*/

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define N 300
#define A 300
#define mod 998244353
int a[N + 1], dp1[2][N * A + 1], dp2[2][N * A + 1], Sum[N + 1];
int main() {
  int n, imp = 0, power = 1, i, j;
  scanf("%d", &n);
  for (i = 1; i <= n; i++)
    scanf("%d", a + i), Sum[i] = Sum[i - 1] + a[i], power = 3ll * power % mod;
  dp1[0][0] = 1;
  for (i = 1; i <= n; i++)
    for (j = 0; j <= Sum[i]; j++)
      dp1[i & 1][j] = (2 * dp1[i - 1 & 1][j] % mod +
                       (j >= a[i] ? dp1[i - 1 & 1][j - a[i]] : 0)) %
                      mod
          //		,printf("dp[%d][%d]=%d\n",i,j,dp1[i&1][j])
          ;
  for (i = Sum[n] + 1 >> 1; i <= Sum[n]; i++)
    imp += 3ll * dp1[n & 1][i] % mod, imp %= mod;
  if (!(Sum[n] & 1)) {
    dp2[0][0] = 1;
    for (i = 1; i <= n; i++)
      for (j = 0; j <= Sum[i]; j++)
        dp2[i & 1][j] =
            (dp2[i - 1 & 1][j] + (j >= a[i] ? dp2[i - 1 & 1][j - a[i]] : 0)) %
            mod;
    imp -= 3ll * dp2[n & 1][Sum[n] >> 1] % mod;
    while (imp < 0)
      imp += mod;
    imp %= mod;
  }
  power -= imp;
  if (power < 0)
    power += mod;
  printf("%d\n", power);
  return 0;
}
/*1
4
1
1
1
2
*/
/*2
6
1
3
2
3
5
2
*/
/*3
20
3
1
4
1
5
9
2
6
5
3
5
8
9
7
9
3
2
3
8
4
*/
Problem p03064 (C++)

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

using namespace std;
typedef long long ll;

const ll MOD = 998244353;
ll n, a[330] = {0}, sum = 0;
ll dp[2][300][90010] = {0};

ll power(ll a, ll b) {
  if (b == 0) {
    return 1;
  } else if (b == 1) {
    return a % MOD;
  } else if (b % 2 == 0) {
    ll c = power(a, b / 2);
    return (c * c) % MOD;
  } else {
    ll c = power(a, b / 2);
    return (((c * c) % MOD) * a) % MOD;
  }
}

signed main() {
  cin >> n;
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
    sum += a[i];
  }

  dp[0][0][0] = 1;
  ll s1 = 0;
  for (int i = 1; i <= n; ++i) {
    for (int j = 0; j <= sum; ++j) {
      if (j - a[i - 1] >= 0) {
        dp[0][i][j] += dp[0][i - 1][j - a[i - 1]];
      }
      dp[0][i][j] += 2 * dp[0][i - 1][j];
      dp[0][i][j] %= MOD;
      if ((sum + 1) / 2 <= j && i == n)
        s1 = (s1 + dp[0][i][j]) % MOD;
    }
  }

  dp[1][0][0] = 1;
  ll s2 = 0;
  if (sum % 2 == 0) {
    for (int i = 1; i <= n; ++i) {
      for (int j = 0; j <= sum; ++j) {
        if (j - a[i - 1] >= 0) {
          dp[1][i][j] += dp[1][i - 1][j - a[i - 1]];
        }
        dp[1][i][j] += dp[1][i - 1][j];
        dp[1][i][j] %= MOD;
        if (sum / 2 == j && i == n)
          s2 = (s2 + dp[1][i][j]) % MOD;
      }
    }
  }

  ll res = power(3, n);
  res = (res + MOD - 3 * s1) % MOD;
  res = (res + MOD + 3 * s2) % MOD;

  cout << res << endl;

  return 0;
}


Fixed submission:
#include <algorithm>
#include <cmath>
#include <iostream>
#include <vector>

using namespace std;
typedef long long ll;

const ll MOD = 998244353;
ll n, a[330] = {0}, sum = 0;
ll dp[2][310][90010] = {0};

ll power(ll a, ll b) {
  if (b == 0) {
    return 1;
  } else if (b == 1) {
    return a % MOD;
  } else if (b % 2 == 0) {
    ll c = power(a, b / 2);
    return (c * c) % MOD;
  } else {
    ll c = power(a, b / 2);
    return (((c * c) % MOD) * a) % MOD;
  }
}

signed main() {
  cin >> n;
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
    sum += a[i];
  }

  dp[0][0][0] = 1;
  ll s1 = 0;
  for (int i = 1; i <= n; ++i) {
    for (int j = 0; j <= sum; ++j) {
      if (j - a[i - 1] >= 0) {
        dp[0][i][j] += dp[0][i - 1][j - a[i - 1]];
      }
      dp[0][i][j] += 2 * dp[0][i - 1][j];
      dp[0][i][j] %= MOD;
      if ((sum + 1) / 2 <= j && i == n)
        s1 = (s1 + dp[0][i][j]) % MOD;
    }
  }

  dp[1][0][0] = 1;
  ll s2 = 0;
  if (sum % 2 == 0) {
    for (int i = 1; i <= n; ++i) {
      for (int j = 0; j <= sum; ++j) {
        if (j - a[i - 1] >= 0) {
          dp[1][i][j] += dp[1][i - 1][j - a[i - 1]];
        }
        dp[1][i][j] += dp[1][i - 1][j];
        dp[1][i][j] %= MOD;
        if (sum / 2 == j && i == n)
          s2 = (s2 + dp[1][i][j]) % MOD;
      }
    }
  }

  ll res = power(3, n);
  res = (res + MOD - 3 * s1) % MOD;
  res = (res + MOD + 3 * s2) % MOD;

  cout << res << endl;

  return 0;
}
Problem p03064 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>

using namespace std;
typedef long long LL;
typedef pair<int, int> P;

const LL M = 998244353;
const int L = 300 * 300 + 1;
LL dp[300][L];
LL dp2[300][L];
int main() {
  int N;
  cin >> N;
  dp[0][0] = 1;
  dp2[0][0] = 1;
  LL ret = 1;
  LL sum = 0;
  for (int i = 1; i <= N; i++) {
    ret *= 3;
    ret %= M;
    for (int j = 0; j < L; j++) {
      dp[i][j] = 2 * dp[i - 1][j];
      dp[i][j] %= M;
      dp2[i][j] = dp2[i - 1][j];
    }
    int v;
    cin >> v;
    sum += v;
    for (int j = 0; j + v < L; j++) {
      dp[i][j + v] += dp[i - 1][j];
      dp[i][j + v] %= M;
      dp2[i][j + v] += dp2[i - 1][j];
      dp2[i][j + v] %= M;
    }
  }
  // cerr << ret << ", " << sum << endl;
  for (int i = 0; i < L; i++) {
    if (i >= sum - i) {
      ret += M - (3 * dp[N][i] % M);
      ret %= M;
    }
    if (2 * i == sum) {
      // cerr << dp2[N][i] << endl;
      ret += 3 * dp2[N][i] % M;
      ret %= M;
    }
  }
  cout << ret << endl;

  return 0;
}


Fixed submission:
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>

using namespace std;
typedef long long LL;
typedef pair<int, int> P;

const LL M = 998244353;
const int L = 300 * 300 + 1;
LL dp[301][L];
LL dp2[301][L];
int main() {
  int N;
  cin >> N;
  dp[0][0] = 1;
  dp2[0][0] = 1;
  LL ret = 1;
  LL sum = 0;
  for (int i = 1; i <= N; i++) {
    ret *= 3;
    ret %= M;
    for (int j = 0; j < L; j++) {
      dp[i][j] = 2 * dp[i - 1][j];
      dp[i][j] %= M;
      dp2[i][j] = dp2[i - 1][j];
    }
    int v;
    cin >> v;
    sum += v;
    for (int j = 0; j + v < L; j++) {
      dp[i][j + v] += dp[i - 1][j];
      dp[i][j + v] %= M;
      dp2[i][j + v] += dp2[i - 1][j];
      dp2[i][j + v] %= M;
    }
  }
  // cerr << ret << ", " << sum << endl;
  for (int i = 0; i < L; i++) {
    if (i >= sum - i) {
      ret += M - (3 * dp[N][i] % M);
      ret %= M;
    }
    if (2 * i == sum) {
      // cerr << dp2[N][i] << endl;
      ret += 3 * dp2[N][i] % M;
      ret %= M;
    }
  }
  cout << ret << endl;

  return 0;
}
Problem p03064 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int mod = 998244353;
void add(int &x, int y) { x = (x + y) % mod; }
int ksm(int b, int n) {
  int res = 1;
  while (n) {
    if (n & 1)
      res = 1ll * res * b % mod;
    b = 1ll * b * b % mod;
    n >>= 1;
  }
  return res;
}
int f[100005], a[105];
signed main() {
  int n, sum = 0;
  cin >> n;
  f[0] = 1;
  for (int i = 1; i <= n; ++i) {
    cin >> a[i];
    sum += a[i];
    for (int j = sum; j >= a[i]; --j)
      add(f[j], f[j - a[i]] + f[j - a[i]]);
    //		cout<<f[1]<<endl;
  }
  int ans = ksm(3, n), res = 0;
  //	cout<<sum<<endl;
  for (int i = 0; i <= sum / 2; ++i)
    add(res, f[i]);
  //	cout<<ans<<" "<<res<<endl;
  res = res * 3ll % mod;
  add(ans, mod - res);
  memset(f, 0, sizeof(f));
  f[0] = 1;
  sum = 0;
  for (int i = 1; i <= n; ++i) {
    sum += a[i];
    for (int j = sum; j >= a[i]; --j)
      add(f[j], f[j - a[i]]);
  }
  if (sum % 2 == 0)
    add(ans, 3ll * f[sum / 2]);
  cout << ans;
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int mod = 998244353;
void add(int &x, int y) { x = (x + y) % mod; }
int ksm(int b, int n) {
  int res = 1;
  while (n) {
    if (n & 1)
      res = 1ll * res * b % mod;
    b = 1ll * b * b % mod;
    n >>= 1;
  }
  return res;
}
int f[100005], a[305];
signed main() {
  int n, sum = 0;
  cin >> n;
  f[0] = 1;
  for (int i = 1; i <= n; ++i) {
    cin >> a[i];
    sum += a[i];
    for (int j = sum; j >= a[i]; --j)
      add(f[j], f[j - a[i]] + f[j - a[i]]);
    //		cout<<f[1]<<endl;
  }
  int ans = ksm(3, n), res = 0;
  //	cout<<sum<<endl;
  for (int i = 0; i <= sum / 2; ++i)
    add(res, f[i]);
  //	cout<<ans<<" "<<res<<endl;
  res = res * 3ll % mod;
  add(ans, mod - res);
  memset(f, 0, sizeof(f));
  f[0] = 1;
  sum = 0;
  for (int i = 1; i <= n; ++i) {
    sum += a[i];
    for (int j = sum; j >= a[i]; --j)
      add(f[j], f[j - a[i]]);
  }
  if (sum % 2 == 0)
    add(ans, 3ll * f[sum / 2]);
  cout << ans;
  return 0;
}
Problem p03065 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
int n, a[N], b[N], g;
vector<int> ans;
bool isprime(int x) {
  for (int i = 2; i * i <= x; ++i)
    if (x % i == 0)
      return false;
  return true;
}
bool check(int x) {
  if (!isprime(x))
    return false;
  memcpy(b, a, sizeof(int) * (n + 3));
  for (int i = n; i >= x; --i)
    b[i - (x - 1)] += b[i];
  for (int i = 0; i < x; ++i)
    if (b[i] % x)
      return false;
  return true;
}
int main() {
  scanf("%d", &n);
  for (int i = n; ~i; --i)
    scanf("%d", &a[i]), g = __gcd(g, abs(a[i]));
  for (int i = 2; i <= g; ++i) {
    if (g % i == 0)
      ans.push_back(i);
    while (g % i == 0)
      g /= i;
  }
  if (g > 1)
    ans.push_back(g);
  for (int i = 2; i <= n; ++i)
    if (check(i))
      ans.push_back(i);
  sort(ans.begin(), ans.end());
  ans.erase(unique(ans.begin(), ans.end()), ans.end());
  for (auto x : ans)
    printf("%d\n", x);
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
int n, a[N], b[N], g;
vector<int> ans;
bool isprime(int x) {
  for (int i = 2; i * i <= x; ++i)
    if (x % i == 0)
      return false;
  return true;
}
bool check(int x) {
  if (!isprime(x))
    return false;
  memcpy(b, a, sizeof(int) * (n + 3));
  for (int i = n; i >= x; --i)
    b[i - (x - 1)] += b[i];
  for (int i = 0; i < x; ++i)
    if (b[i] % x)
      return false;
  return true;
}
int main() {
  scanf("%d", &n);
  for (int i = n; ~i; --i)
    scanf("%d", &a[i]), g = __gcd(g, abs(a[i]));
  for (int i = 2; i * i <= g; ++i) {
    if (g % i == 0 && check(i))
      ans.push_back(i);
    while (g % i == 0)
      g /= i;
  }
  if (g > 1)
    ans.push_back(g);
  for (int i = 2; i <= n; ++i)
    if (check(i))
      ans.push_back(i);
  sort(ans.begin(), ans.end());
  ans.erase(unique(ans.begin(), ans.end()), ans.end());
  for (auto x : ans)
    printf("%d\n", x);
}
Problem p03065 (Python)

Buggy submission (status: Runtime Error):
import sys
from fractions import gcd


def eratosthenes_generator():
    yield 2
    n = 3
    h = {}
    while True:
        m = n
        if n in h:
            b = h[n]
            del h[n]
        else:
            b = n
            yield n
        m += b << 1
        while m in h:
            m += b << 1
        h[m] = b
        n += 2


def prime(n):
    ret = []
    if n % 2 == 0:
        ret.append(2)
        while n % 2 == 0:
            n >>= 1
    for i in range(3, int(n**0.5) + 1, 2):
        if n % i == 0:
            ret.append(i)
            while n % i == 0:
                n = n // i
        if n == 1:
            break
    if n > 1:
        ret.append(n)
    return ret


def solve(n, aaa):
    g = abs(aaa[-1])
    for a in aaa[:-1]:
        if a != 0:
            g = gcd(g, abs(a))
    ans = set(prime(g))

    for p in prime(aaa[0]):
        if p > n + 2:
            break
        if p in ans or aaa[0] % p != 0:
            continue
        q = p - 1
        tmp = [0] * q
        for i, a in enumerate(aaa):
            tmp[i % q] += a
        if all(t % p == 0 for t in tmp):
            ans.add(p)

    ans = sorted(ans)
    return ans


n = int(input())
aaa = list(map(int, sys.stdin))
aaa.reverse()
print("\n".join(map(str, solve(n, aaa))))


Fixed submission:
import sys
from fractions import gcd


def eratosthenes_generator():
    yield 2
    n = 3
    h = {}
    while True:
        m = n
        if n in h:
            b = h[n]
            del h[n]
        else:
            b = n
            yield n
        m += b << 1
        while m in h:
            m += b << 1
        h[m] = b
        n += 2


def prime(n):
    ret = []
    if n % 2 == 0:
        ret.append(2)
        while n % 2 == 0:
            n >>= 1
    for i in range(3, int(n**0.5) + 1, 2):
        if n % i == 0:
            ret.append(i)
            while n % i == 0:
                n = n // i
        if n == 1:
            break
    if n > 1:
        ret.append(n)
    return ret


def solve(n, aaa):
    g = abs(aaa[-1])
    for a in aaa[:-1]:
        if a != 0:
            g = gcd(g, abs(a))
    ans = set(prime(g))

    for p in eratosthenes_generator():
        if p > n + 2:
            break
        if p in ans or aaa[0] % p != 0:
            continue
        q = p - 1
        tmp = [0] * q
        for i, a in enumerate(aaa):
            tmp[i % q] += a
        if all(t % p == 0 for t in tmp):
            ans.add(p)

    ans = sorted(ans)
    return ans


n = int(input())
aaa = list(map(int, sys.stdin))
aaa.reverse()
print("\n".join(map(str, solve(n, aaa))))
Problem p03065 (Python)

Buggy submission (status: Time Limit Exceeded):
import sys
from fractions import gcd


def eratosthenes_generator():
    yield 2
    n = 3
    h = {}
    while True:
        m = n
        if n in h:
            b = h[n]
            del h[n]
        else:
            b = n
            yield n
        m += b << 1
        while m in h:
            m += b << 1
        h[m] = b
        n += 2


def prime(n):
    ret = []
    for i in eratosthenes_generator():
        if n % i == 0:
            ret.append(i)
            while n % i == 0:
                n = n // i
        if n == 1:
            break
    if n > 1:
        ret.append(n)
    return ret


def solve(n, aaa):
    g = abs(aaa[-1])
    for a in aaa[:-1]:
        if a != 0:
            g = gcd(g, abs(a))
    ans = set(prime(g))

    for p in eratosthenes_generator():
        if p > n + 2:
            break
        if p in ans or aaa[0] % p != 0:
            continue
        q = p - 1
        tmp = [0] * q
        for i, a in enumerate(aaa):
            tmp[i % q] += a
        if all(t % p == 0 for t in tmp):
            ans.add(p)

    ans = sorted(ans)
    return ans


n = int(input())
aaa = list(map(int, sys.stdin))
aaa.reverse()
print("\n".join(map(str, solve(n, aaa))))


Fixed submission:
import sys
from fractions import gcd


def eratosthenes_generator():
    yield 2
    n = 3
    h = {}
    while True:
        m = n
        if n in h:
            b = h[n]
            del h[n]
        else:
            b = n
            yield n
        m += b << 1
        while m in h:
            m += b << 1
        h[m] = b
        n += 2


def prime(n):
    ret = []
    for i in eratosthenes_generator():
        if n % i == 0:
            ret.append(i)
            while n % i == 0:
                n = n // i
        if n == 1 or i * i > n:
            break
    if n > 1:
        ret.append(n)
    return ret


def solve(n, aaa):
    g = abs(aaa[-1])
    for a in aaa[:-1]:
        if a != 0:
            g = gcd(g, abs(a))
    ans = set(prime(g))

    for p in eratosthenes_generator():
        if p > n + 2:
            break
        if p in ans or aaa[0] % p != 0:
            continue
        q = p - 1
        tmp = [0] * q
        for i, a in enumerate(aaa):
            tmp[i % q] += a
        if all(t % p == 0 for t in tmp):
            ans.add(p)

    ans = sorted(ans)
    return ans


n = int(input())
aaa = list(map(int, sys.stdin))
aaa.reverse()
print("\n".join(map(str, solve(n, aaa))))
Problem p03066 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <iostream>
#define ll long long
using namespace std;
template <class T> inline void rd(T &x) {
  x = 0;
  char c = getchar();
  int f = 1;
  while (!isdigit(c)) {
    if (c == '-')
      f = -1;
    c = getchar();
  }
  while (isdigit(c))
    x = x * 10 - '0' + c, c = getchar();
  x *= f;
}
const int mod = 998244353, N = 3010;
void Add(int &x, int y) { x = (x + y) % mod; }
int Pow(int x, int y) {
  int res = 1;
  while (y) {
    if (y & 1)
      res = res * (ll)x % mod;
    x = x * (ll)x % mod, y >>= 1;
  }
  return res;
}
int fac[N], inv[N];
int C(int n, int m) {
  if (n < m)
    return 0;
  return fac[n] * (ll)inv[m] % mod * inv[n - m] % mod;
}
void get_fac(int n) {
  fac[0] = 1;
  for (int i = 1; i <= n; ++i)
    fac[i] = fac[i - 1] * (ll)i % mod;
  inv[n] = Pow(fac[n], mod - 2);
  for (int i = n; i >= 1; --i)
    inv[i - 1] = inv[i] * (ll)i % mod;
}
int cal1(int m, int n) { // m¸öÎ»ÖÃ ÓÃ 1,2 ´Õ n
  return C(m, n - m);
}
int solve(int n, int X) { // n ¸öÎ»ÖÃ  ²»³öÏÖ x
  int ans = 0;
  for (int i = 0; i < X; ++i)
    Add(ans, cal1(n, i));
  if (2 * n < X)
    return ans;

  for (int i = 1; i * 2 <= X - 1; ++i) {
    Add(ans, cal1(n - i * 2, X - 1 - 2 * i));
  }
  if (X % 2 == 1 && X - 1 < n)
    Add(ans, 1);
  return ans;
}
int main() {
  int n, X;
  rd(n), rd(X);
  get_fac(n);
  int ans = 0;
  for (int i = 0; i <= n; ++i) {
    //		cout<<solve(i,X)<<endl;
    Add(ans, C(n, i) * (ll)solve(i, X) % mod);
  }
  printf("%d", ans);
  return 0;
}

Fixed submission:
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <iostream>
#define ll long long
using namespace std;
template <class T> inline void rd(T &x) {
  x = 0;
  char c = getchar();
  int f = 1;
  while (!isdigit(c)) {
    if (c == '-')
      f = -1;
    c = getchar();
  }
  while (isdigit(c))
    x = x * 10 - '0' + c, c = getchar();
  x *= f;
}
const int mod = 998244353, N = 3010;
void Add(int &x, int y) { x = (x + y) % mod; }
int Pow(int x, int y) {
  int res = 1;
  while (y) {
    if (y & 1)
      res = res * (ll)x % mod;
    x = x * (ll)x % mod, y >>= 1;
  }
  return res;
}
int fac[N], inv[N];
int C(int n, int m) {
  if (n < m)
    return 0;
  return fac[n] * (ll)inv[m] % mod * inv[n - m] % mod;
}
void get_fac(int n) {
  fac[0] = 1;
  for (int i = 1; i <= n; ++i)
    fac[i] = fac[i - 1] * (ll)i % mod;
  inv[n] = Pow(fac[n], mod - 2);
  for (int i = n; i >= 1; --i)
    inv[i - 1] = inv[i] * (ll)i % mod;
}
int cal1(int m, int n) { // m¸öÎ»ÖÃ ÓÃ 1,2 ´Õ n
  if (m > n)
    return 0;
  return C(m, n - m);
}
int solve(int n, int X) { // n ¸öÎ»ÖÃ  ²»³öÏÖ x
  int ans = 0;
  for (int i = 0; i < X; ++i)
    Add(ans, cal1(n, i));
  if (2 * n < X)
    return ans;

  for (int i = 1; i * 2 <= X - 1; ++i) {
    Add(ans, cal1(n - i * 2, X - 1 - 2 * i));
  }
  if (X % 2 == 1 && X - 1 < n)
    Add(ans, 1);
  return ans;
}
int main() {
  int n, X;
  rd(n), rd(X);
  get_fac(n);
  int ans = 0;
  for (int i = 0; i <= n; ++i) {
    //		cout<<solve(i,X)<<endl;
    Add(ans, C(n, i) * (ll)solve(i, X) % mod);
  }
  printf("%d", ans);
  return 0;
}
Problem p03066 (C++)

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

typedef long long ll;

int N, X;
ll con[6010][6010];
ll mod = 998244353;
ll ans;

int main() {
  cin >> N >> X;

  for (int i = 0; i < 6010; i++)
    for (int j = 0; j < 6010; j++) {
      if (i == j)
        con[i][j] = 1;
      else if (j == 0)
        con[i][j] = 1;
      else
        con[i][j] = (con[i - 1][j] + con[i - 1][j - 1]) % mod;
    }

  for (int i = 0; i <= N; i++) {
    ll tmp = 0;
    for (int j = 0; j <= i; j++) {
      if (2 * j < X - 1)
        continue;
      int t = (X - 1) - j;
      if (j - t != 0 && t < i - j)
        continue;
      tmp += con[max(0, j - (i - j))][max(0, t - (i - j))] * con[N][i];
      tmp %= mod;
    }
    ans += tmp;
    ans %= mod;
  }

  for (int i = 0; i <= N; i++) {
    ll tmp = 0;
    for (int j = 0; j <= i; j++) {
      if (i - j + j * 2 < X - 1) {
        tmp += con[N][i] * con[i][j] % mod;
        tmp %= mod;
      }
    }
    ans += tmp;
    ans %= mod;
  }

  cout << ans << endl;
}


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

typedef long long ll;

int N, X;
ll con[6010][6010];
ll mod = 998244353;
ll ans;

int main() {
  cin >> N >> X;

  for (int i = 0; i < 6010; i++)
    for (int j = 0; j <= i; j++) {
      if (i == j)
        con[i][j] = 1;
      else if (j == 0)
        con[i][j] = 1;
      else
        con[i][j] = (con[i - 1][j] + con[i - 1][j - 1]) % mod;
    }

  for (int i = 0; i <= N; i++) {
    ll tmp = 0;
    for (int j = 0; j <= i; j++) {
      if (2 * j < X - 1)
        continue;
      int t = (X - 1) - j;
      if (j - t != 0 && t < i - j)
        continue;
      tmp += con[max(0, j - (i - j))][max(0, t - (i - j))] * con[N][i];
      tmp %= mod;
    }
    ans += tmp;
    ans %= mod;
  }

  for (int i = 0; i <= N; i++) {
    ll tmp = 0;
    for (int j = 0; j <= i; j++) {
      if (i - j + j * 2 < X - 1) {
        tmp += con[N][i] * con[i][j] % mod;
        tmp %= mod;
      }
    }
    ans += tmp;
    ans %= mod;
  }

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

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
inline int mygetchar() {
#ifdef WIN32
  return _getchar_nolock();
#else
  return getchar_unlocked();
#endif
}
inline int read() {
  int x = 0, f = 1;
  char c = mygetchar();
  while (!isdigit(c)) {
    if (c == '-')
      f = -1;
    c = mygetchar();
  }
  while (isdigit(c)) {
    x = x * 10 + c - '0';
    c = mygetchar();
  }
  return x * f;
}

const int MOD = 998244353;
inline void add(int &x, int y) {
  x += y;
  if (x >= MOD)
    x -= MOD;
}
inline int inc(int x, int y) {
  x += y;
  return x >= MOD ? x - MOD : x;
}
inline int mul(int x, int y) { return (ll)x * y % MOD; }
inline int qpow(int x, int y) {
  int res = 1;
  for (; y; y >>= 1, x = mul(x, x))
    if (y & 1)
      res = mul(res, x);
  return res;
}

const int MAXN = 3005;
int n, X, c[MAXN][MAXN], ans = 0;

inline int Solve(int len) {
  int res = 0;
  if (len * 2 < X || X & 1)
    res = 1;
  for (int i = 0; i < len; i++) {
    if (len + i < X)
      add(res, c[len][i]);
    else if ((len + i - X) & 1) {
      int S = len + i, l = (S - X + 1) / 2;
      if (len > l + l && i >= l + l)
        add(res, c[len - l - l][i - l - l]);
    }
  }
  return res;
}
int main() {
  n = read(), X = read();
  for (int i = 0; i <= n * 2; i++)
    c[i][0] = 1;
  for (int i = 1; i <= n * 2; i++)
    for (int j = 1; j <= i; j++)
      c[i][j] = inc(c[i - 1][j], c[i - 1][j - 1]);
  for (int i = 0; i <= n; i++)
    add(ans, mul(c[n][i], Solve(n - i)));
  printf("%d\n", ans);
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
inline int mygetchar() {
#ifdef WIN32
  return _getchar_nolock();
#else
  return getchar_unlocked();
#endif
}
inline int read() {
  int x = 0, f = 1;
  char c = mygetchar();
  while (!isdigit(c)) {
    if (c == '-')
      f = -1;
    c = mygetchar();
  }
  while (isdigit(c)) {
    x = x * 10 + c - '0';
    c = mygetchar();
  }
  return x * f;
}

const int MOD = 998244353;
inline void add(int &x, int y) {
  x += y;
  if (x >= MOD)
    x -= MOD;
}
inline int inc(int x, int y) {
  x += y;
  return x >= MOD ? x - MOD : x;
}
inline int mul(int x, int y) { return (ll)x * y % MOD; }
inline int qpow(int x, int y) {
  int res = 1;
  for (; y; y >>= 1, x = mul(x, x))
    if (y & 1)
      res = mul(res, x);
  return res;
}

const int MAXN = 6005;
int n, X, c[MAXN][MAXN], ans = 0;

inline int Solve(int len) {
  int res = 0;
  if (len * 2 < X || X & 1)
    res = 1;
  for (int i = 0; i < len; i++) {
    if (len + i < X)
      add(res, c[len][i]);
    else if ((len + i - X) & 1) {
      int S = len + i, l = (S - X + 1) / 2;
      if (len > l + l && i >= l + l)
        add(res, c[len - l - l][i - l - l]);
    }
  }
  return res;
}
int main() {
  n = read(), X = read();
  for (int i = 0; i <= n * 2; i++)
    c[i][0] = 1;
  for (int i = 1; i <= n * 2; i++)
    for (int j = 1; j <= i; j++)
      c[i][j] = inc(c[i - 1][j], c[i - 1][j - 1]);
  for (int i = 0; i <= n; i++)
    add(ans, mul(c[n][i], Solve(n - i)));
  printf("%d\n", ans);
  return 0;
}
Problem p03067 (C++)

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

#define N 1000
#define pb push_back
#define mp make_pair
#define ll long long
#define mod 1000000007
#define all(cont) cont.begin(), cont.end()
#define sortcmp(n, cmpfunc) sort(all(n), cmpfunc)
#define fastio                                                                 \
  ios::sync_with_stdio(false);                                                 \
  cin.tie(0)

ll powm(ll a, ll b);
ll divm(ll a, ll b);
ll multm(ll a, ll b);
ll subm(ll a, ll b);
ll addm(ll a, ll b);

int main() {
  int a, b, c;
  fastio;
#ifndef ONLINE_JUDGE
  freopen("input.in", "r", stdin);
  freopen("output.out", "w", stdout);
#endif
  cin >> a >> b >> c;
  if (min(a, b) < c && max(a, b) > c)
    cout << "Yes\n";
  else
    cout << "No\n";
  return 0;
}

// template function
ll gcd(int a, int b) {
  if (b == 0)
    return a;
  return gcd(b, a % b);
}

ll lcm(ll a, ll b) { return a * b / gcd(a, b); }

ll powm(ll a, ll b) {
  ll x = 1, y = a;
  while (b > 0) {
    if (b % 2)
      x = (x * y) % mod;
    y = (y * y) % mod;
    b /= 2;
  }
  return x % mod;
}

ll multm(ll a, ll b) { return ((a % mod) * (b % mod)) % mod; }

ll divm(ll a, ll b) { return (a * powm(b, mod - 2)); }

ll subm(ll a, ll b) {
  a -= b;
  if (a < 0)
    a += mod;
  return a;
}

ll addm(ll a, ll b) {
  a += b;
  if (a >= mod)
    a -= mod;
  return a;
}

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

#define N 1000
#define pb push_back
#define mp make_pair
#define ll long long
#define mod 1000000007
#define all(cont) cont.begin(), cont.end()
#define sortcmp(n, cmpfunc) sort(all(n), cmpfunc)
#define fastio                                                                 \
  ios::sync_with_stdio(false);                                                 \
  cin.tie(0)

ll powm(ll a, ll b);
ll divm(ll a, ll b);
ll multm(ll a, ll b);
ll subm(ll a, ll b);
ll addm(ll a, ll b);

int main() {
  int a, b, c;
  fastio;
  // #ifndef ONLINE_JUDGE
  //    	freopen("input.in", "r", stdin);
  //    	freopen("output.out", "w", stdout);
  // #endif
  cin >> a >> b >> c;
  if (min(a, b) < c && max(a, b) > c)
    cout << "Yes\n";
  else
    cout << "No\n";
  return 0;
}

// template function
ll gcd(int a, int b) {
  if (b == 0)
    return a;
  return gcd(b, a % b);
}

ll lcm(ll a, ll b) { return a * b / gcd(a, b); }

ll powm(ll a, ll b) {
  ll x = 1, y = a;
  while (b > 0) {
    if (b % 2)
      x = (x * y) % mod;
    y = (y * y) % mod;
    b /= 2;
  }
  return x % mod;
}

ll multm(ll a, ll b) { return ((a % mod) * (b % mod)) % mod; }

ll divm(ll a, ll b) { return (a * powm(b, mod - 2)); }

ll subm(ll a, ll b) {
  a -= b;
  if (a < 0)
    a += mod;
  return a;
}

ll addm(ll a, ll b) {
  a += b;
  if (a >= mod)
    a -= mod;
  return a;
}
Problem p03067 (Python)

Buggy submission (status: Runtime Error):
A = input()
B = input()
C = input()
if A > C > B:
    print("Yes")
elif B > C > A:
    print("Yes")
else:
    print("No")


Fixed submission:
A, B, C = map(int, input().split())
if A > C > B:
    print("Yes")
elif B > C > A:
    print("Yes")
else:
    print("No")
Problem p03067 (Python)

Buggy submission (status: Runtime Error):
n = int(input())
s = list(input())
k = int(input())
d = s[k - 1]
for i in range(n):
    if s[i] != d:
        s[i] = "*"
print("".join(s))


Fixed submission:
a, b, c = map(int, input().split())
if a < c < b or b < c < a:
    print("Yes")
else:
    print("No")
Problem p03067 (Python)

Buggy submission (status: Runtime Error):
# -*- coding: utf-8 -*-
a, b, c = map(int, input().split())
ab = int(b / a)
if a < c < b or b < c < a:
    print("Yes")
else:
    print("No")


Fixed submission:
# -*- coding: utf-8 -*-
a, b, c = map(int, input().split())
if a < c < b or b < c < a:
    print("Yes")
else:
    print("No")
Problem p03067 (Python)

Buggy submission (status: Runtime Error):
input_str = input()
homes = input_str.split(" ")
for home in homes:
    home = int(home)
print(homes)
if (homes[2] - homes[1]) * (homes[2] - homes[0]) < 0:
    print("Yes")
else:
    print("No")


Fixed submission:
input_str = input()
homes = input_str.split(" ")
for i, home in enumerate(homes):
    homes[i] = int(home)
if (homes[2] - homes[1]) * (homes[2] - homes[0]) < 0:
    print("Yes")
else:
    print("No")
Problem p03068 (C++)

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

int main() {
  int n, k;
  cin >> n;
  vector<char> s(n);
  for (int i = 0; i < n; i++) {
    cin >> s.at(i);
  }
  cin >> k;
  char con = s.at(k);
  for (int i = 0; i < n; i++) {
    if (s.at(i) != con) {
      s.at(i) = '*';
    }
  }
  for (int i = 0; i < n; i++) {
    cout << s.at(i);
  }
  cout << endl;
}


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

int main() {
  int n, k;
  cin >> n;
  vector<char> s(n);
  for (int i = 0; i < n; i++) {
    cin >> s.at(i);
  }
  cin >> k;
  char con = s.at(k - 1);
  // cout << con << endl;
  for (int i = 0; i < n; i++) {
    if (s.at(i) != con) {
      s.at(i) = '*';
    }
  }
  for (int i = 0; i < n; i++) {
    cout << s.at(i);
  }
  cout << endl;
}
Problem p03068 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <functional>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <stack>
#include <string>
#include <vector>

typedef long long ll;
ll mod = 1e9 + 7;

using namespace std;

int main() {
  int n, k;
  string s;
  cin >> n >> s >> k;

  char c = s.at(k);

  for (int i = 0; i < s.size(); i++) {
    if (s.at(i) == c)
      cout << c;
    else {
      cout << '*';
    }
  }
  cout << endl;

  return 0;
}

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

typedef long long ll;
ll mod = 1e9 + 7;

using namespace std;

int main() {
  int n, k;
  string s;
  cin >> n >> s >> k;

  char c = s.at(k - 1);

  for (int i = 0; i < s.size(); i++) {
    if (s.at(i) == c)
      cout << c;
    else {
      cout << '*';
    }
  }
  cout << endl;

  return 0;
}
Problem p03068 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, k;
  string s;
  cin >> n >> s >> k;
  for (int i = 0; i < n; i++) {
    if (s.at(i) != s.at(k)) {
      s.at(i) = '*';
    }
  }
  cout << s << endl;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, k;
  string s;
  cin >> n >> s >> k;
  for (int i = 0; i < n; i++) {
    if (s.at(i) != s.at(k - 1)) {
      s.at(i) = '*';
    }
  }
  cout << s << endl;
}
Problem p03068 (C++)

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

int main() {
  int N, K;
  string S;
  char C;

  cin >> N;
  cin >> S;
  cin >> K;

  C = S.at(K);

  for (int i = 0; i < N; i++) {
    if (S.at(i) != C) {
      cout << "*";
    } else {
      cout << S.at(i);
    }
  }
}


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

int main() {
  int N, K;
  string S;
  char C;

  cin >> N;
  cin >> S;
  cin >> K;

  C = S.at(K - 1);

  for (int i = 0; i < N; i++) {
    if (S.at(i) != C) {
      cout << "*";
    } else {
      cout << S.at(i);
    }
  }
}
Problem p03068 (C++)

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

int main() {
  int N, K;
  string S;
  cin >> N >> S >> K;
  char a = S.at(K);
  for (int i = 0; i < N; i++) {
    if (S.at(i) != a) {
      S.at(i) = '*';
    }
  }
  cout << S << endl;
}

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

int main() {
  int N, K;
  string S;
  cin >> N >> S >> K;
  char a = S.at(K - 1);
  for (int i = 0; i < N; i++) {
    if (S.at(i) != a) {
      S.at(i) = '*';
    }
  }
  cout << S << endl;
}
Problem p03068 (C++)

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

int main() {
  int N, K;
  string S;
  char X = '*', t;
  cin >> N >> S >> K;
  char Y = S.at(K);

  for (int i = 0; i < N; i++) {
    t = S.at(i);
    if (t != Y) {
      S.at(i) = X;
    }
  }

  cout << S << endl;
}


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

int main() {
  int N, K;
  string S;
  char X = '*', t;
  cin >> N >> S >> K;
  K--;
  char Y = S.at(K);

  for (int i = 0; i < N; i++) {
    t = S.at(i);
    if (t != Y) {
      S.at(i) = X;
    }
  }

  cout << S << endl;
}