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

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

const int MAX_N = 1e5 + 5, MOD = 1e9 + 7;
int B, W, n;
int sumW[MAX_N];
int sumB[MAX_N];
int F[MAX_N];

int _sum(int a, int b) {
  int c = a + b;

  if (MOD <= c)
    c -= MOD;

  return c;
}

int _sub(int a, int b) {
  int c = a - b;

  if (c < 0)
    c += MOD;

  return c;
}

int _mul(int a, int b) {
  int c = 1LL * a * b % MOD;

  return c;
}

int _pow(int a, int b) {
  if (!b)
    return 1;

  int res = _pow(a, b >> 1);
  res = _mul(res, res);

  if (b & 1)
    res = _mul(res, a);

  return res;
}

int _choose(int a, int b) {
  if (a < 0 || b < a)
    return 0;

  int c = _mul(F[b], _mul(_pow(F[a], MOD - 2), _pow(F[b - a], MOD - 2)));
  return c;
}

void pre_process() {
  F[0] = 1;
  for (int i = 1; i < MAX_N; i++)
    F[i] = _mul(i, F[i - 1]);
}

int main() {
  ios::sync_with_stdio(false), cin.tie(0);
  pre_process();

  cin >> B >> W;
  n = B + W;

  for (int i = W - 1; i < n - 1; i++) {
    int s = _mul(_choose(W - 1, i), _pow(_pow(2, i + 1), MOD - 2));
    sumW[i + 1] = s;
  }

  for (int i = B - 1; i < n - 1; i++) {
    int s = _mul(_choose(B - 1, i), _pow(_pow(2, i + 1), MOD - 2));
    sumB[i + 1] = s;
  }

  int w = 0, b = 0;
  for (int i = 0; i < n; i++) {
    w = _sum(w, sumW[i]);
    b = _sum(b, sumB[i]);
    int s = _sub(_sub(1, w), b);

    cout << _sum(w, _mul(s, _pow(2, MOD - 2))) << "\n";
  }

  return 0;
}

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

const int MAX_N = 2e5 + 10, MOD = 1e9 + 7;
int B, W, n;
int sumW[MAX_N];
int sumB[MAX_N];
int F[MAX_N];

int _sum(int a, int b) {
  int c = a + b;

  if (MOD <= c)
    c -= MOD;

  return c;
}

int _sub(int a, int b) {
  int c = a - b;

  if (c < 0)
    c += MOD;

  return c;
}

int _mul(int a, int b) {
  int c = 1LL * a * b % MOD;

  return c;
}

int _pow(int a, int b) {
  if (!b)
    return 1;

  int res = _pow(a, b >> 1);
  res = _mul(res, res);

  if (b & 1)
    res = _mul(res, a);

  return res;
}

int _choose(int a, int b) {
  if (a < 0 || b < a)
    return 0;

  int c = _mul(F[b], _mul(_pow(F[a], MOD - 2), _pow(F[b - a], MOD - 2)));
  return c;
}

void pre_process() {
  F[0] = 1;
  for (int i = 1; i < MAX_N; i++)
    F[i] = _mul(i, F[i - 1]);
}

int main() {
  ios::sync_with_stdio(false), cin.tie(0);
  pre_process();

  cin >> B >> W;
  n = B + W;

  for (int i = W - 1; i < n - 1; i++) {
    int s = _mul(_choose(W - 1, i), _pow(_pow(2, i + 1), MOD - 2));
    sumW[i + 1] = s;
  }

  for (int i = B - 1; i < n - 1; i++) {
    int s = _mul(_choose(B - 1, i), _pow(_pow(2, i + 1), MOD - 2));
    sumB[i + 1] = s;
  }

  int w = 0, b = 0;
  for (int i = 0; i < n; i++) {
    w = _sum(w, sumW[i]);
    b = _sum(b, sumB[i]);
    int s = _sub(_sub(1, w), b);

    cout << _sum(w, _mul(s, _pow(2, MOD - 2))) << "\n";
  }

  return 0;
}
Problem p03083 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
#define N (long long)(1e9 + 7)
#define MAX 500000
using namespace std;
long long factorial[MAX] = {0}, finverse[MAX] = {0}, inverse[MAX] = {0};

void smodfact() {
  factorial[0] = factorial[1] = 1;
  finverse[0] = finverse[1] = 1;
  inverse[1] = 1;
  for (int i = 2; i < MAX; ++i) {
    factorial[i] = factorial[i - 1] * i % N;
    inverse[i] = N - (inverse[N % i] * (N / i)) % N;
    finverse[i] = finverse[i - 1] * inverse[i] % N;
  }
}

long long calccomb(long long n, long long k) {
  if (n == k && n == 0)
    return 1;
  if (n < 0 || k < 0 || n < k)
    return 0;
  return factorial[n] * finverse[k] % N * finverse[n - k] % N;
}

long long b, w, n;
long long dpb[100005] = {0}, dpw[100005] = {0};

void solve();

int main() {
  smodfact();
  cin >> b >> w;
  n = b + w;
  solve();
  return 0;
}

void solve() {
  long long bin = 1;
  for (int i = 0; i < n; ++i) {
    long long now = 1;
    now += (dpw[i] - dpb[i] + N) % N;
    now %= N;
    bin *= inverse[2];
    bin %= N;
    dpb[i + 1] = (dpb[i] + bin * calccomb(i, b - 1) % N) % N;
    dpw[i + 1] = (dpw[i] + bin * calccomb(i, w - 1) % N) % N;
    cout << now * inverse[2] % N << endl;
  }
}

Fixed submission:
#include <bits/stdc++.h>
#define N (long long)(1e9 + 7)
#define MAX 500000
using namespace std;
long long factorial[MAX] = {0}, finverse[MAX] = {0}, inverse[MAX] = {0};

void smodfact() {
  factorial[0] = factorial[1] = 1;
  finverse[0] = finverse[1] = 1;
  inverse[1] = 1;
  for (int i = 2; i < MAX; ++i) {
    factorial[i] = factorial[i - 1] * i % N;
    inverse[i] = N - (inverse[N % i] * (N / i)) % N;
    finverse[i] = finverse[i - 1] * inverse[i] % N;
  }
}

long long calccomb(long long n, long long k) {
  if (n == k && n == 0)
    return 1;
  if (n < 0 || k < 0 || n < k)
    return 0;
  return factorial[n] * finverse[k] % N * finverse[n - k] % N;
}

long long b, w, n;
long long dpb[300005] = {0}, dpw[300005] = {0};

void solve();

int main() {
  smodfact();
  cin >> b >> w;
  n = b + w;
  solve();
  return 0;
}

void solve() {
  long long bin = 1;
  for (int i = 0; i < n; ++i) {
    long long now = 1;
    now += (dpw[i] - dpb[i] + N) % N;
    now %= N;
    bin *= inverse[2];
    bin %= N;
    dpb[i + 1] = (dpb[i] + bin * calccomb(i, b - 1) % N) % N;
    dpw[i + 1] = (dpw[i] + bin * calccomb(i, w - 1) % N) % N;
    cout << now * inverse[2] % N << endl;
  }
}
Problem p03083 (C++)

Buggy submission (status: Runtime Error):
#include <iostream>
using namespace std;
const int N = 1e5 + 10, mod = 1e9 + 7;
int jc[N], inv[N], bit[N], B, W, sw[N], sb[N];
int ksm(int x, int k) {
  int s = 1;
  for (; k; k >>= 1, x = 1ll * x * x % mod)
    if (k & 1)
      s = 1ll * s * x % mod;
  return s;
}
int C(int n, int k) { return 1ll * jc[n] * inv[k] % mod * inv[n - k] % mod; }
int main() {
  cin >> B >> W;
  jc[0] = bit[0] = inv[0] = 1;
  for (int i = 1; i <= B + W; i++)
    jc[i] = 1ll * i * jc[i - 1] % mod;
  for (int i = 1; i <= B + W; i++)
    inv[i] = ksm(jc[i], mod - 2);
  for (int i = 1; i <= B + W; i++)
    bit[i] = 1ll * bit[i - 1] * inv[2] % mod;

  for (int i = W; i < B + W; i++)
    sw[i] = 1ll * bit[i] * C(i - 1, i - W) % mod;
  for (int i = B; i < B + W; i++)
    sb[i] = 1ll * bit[i] * C(i - 1, i - B) % mod;
  //	for(int i=1;i<=B+W;i++)
  //		printf("sw[%d]=%d,sb[%d]=%d\n",i,sw[i],i,sb[i]);
  for (int i = 1; i <= B + W; i++) {
    (sw[i] += sw[i - 1]) %= mod;
    (sb[i] += sb[i - 1]) %= mod;
  }
  for (int i = 1; i <= B + W; i++) {
    int w = (sw[i - 1] + 1ll * ((mod + 1 - sw[i - 1] - sb[i - 1]) % mod + mod) %
                             mod * (i == B + W ? 1 : inv[2]) % mod) %
            mod;
    cout << w << endl;
  }
}


Fixed submission:
#include <iostream>
using namespace std;
const int N = 2e5 + 10, mod = 1e9 + 7;
int jc[N], inv[N], bit[N], B, W, sw[N], sb[N];
int ksm(int x, int k) {
  int s = 1;
  for (; k; k >>= 1, x = 1ll * x * x % mod)
    if (k & 1)
      s = 1ll * s * x % mod;
  return s;
}
int C(int n, int k) { return 1ll * jc[n] * inv[k] % mod * inv[n - k] % mod; }
int main() {
  cin >> B >> W;
  jc[0] = bit[0] = inv[0] = 1;
  for (int i = 1; i <= B + W; i++)
    jc[i] = 1ll * i * jc[i - 1] % mod;
  for (int i = 1; i <= B + W; i++)
    inv[i] = ksm(jc[i], mod - 2);
  for (int i = 1; i <= B + W; i++)
    bit[i] = 1ll * bit[i - 1] * inv[2] % mod;

  for (int i = W; i < B + W; i++)
    sw[i] = 1ll * bit[i] * C(i - 1, i - W) % mod;
  for (int i = B; i < B + W; i++)
    sb[i] = 1ll * bit[i] * C(i - 1, i - B) % mod;
  //	for(int i=1;i<=B+W;i++)
  //		printf("sw[%d]=%d,sb[%d]=%d\n",i,sw[i],i,sb[i]);
  for (int i = 1; i <= B + W; i++) {
    (sw[i] += sw[i - 1]) %= mod;
    (sb[i] += sb[i - 1]) %= mod;
  }
  for (int i = 1; i <= B + W; i++) {
    int w = (sw[i - 1] + 1ll * ((mod + 1 - sw[i - 1] - sb[i - 1]) % mod + mod) %
                             mod * (i == B + W ? 1 : inv[2]) % mod) %
            mod;
    cout << w << endl;
  }
}
Problem p03083 (C++)

Buggy submission (status: Runtime Error):
#include <iostream>
#include <vector>
using namespace std;
const long long mod = 1e9 + 7;

long long mod_pow(long long x, long long k) {
  long long ret = 1;
  while (k) {
    if (k & 1)
      ret *= x, ret %= mod;
    x *= x, x %= mod;
    k >>= 1;
  }
  return ret;
}

int main() {
  int b, w;
  cin >> b >> w;
  int N = b + w;
  vector<long long> B(N, 0), W(N, 0), F(N + 1, 1), F_(N + 1, 1);
  for (int i = 1; i <= N; ++i)
    F[i] = F[i - 1] * i % mod;
  F_[N] = mod_pow(F[N], mod - 2);
  for (int i = N - 1; i > 0; --i)
    F_[i] = F_[i + 1] * (i + 1) % mod;
  auto comb = [&F, &F_](int n, int m) {
    if (m > n)
      return 0LL;
    return F[n] * F_[m] % mod * F_[n - m] % mod;
  };
  long long t = 1, inv2 = mod_pow(2, mod - 2);
  for (int i = 1; i <= N; ++i) {
    t *= inv2, t %= mod;
    B[i] = (B[i - 1] + comb(i - 1, w - 1) * t % mod) % mod;
    W[i] = (W[i - 1] + comb(i - 1, b - 1) * t % mod) % mod;
  }
  for (int i = 0; i < N; ++i) {
    cout << ((1 + B[i] - W[i]) % mod + mod) % mod * inv2 % mod << endl;
  }
}


Fixed submission:
#include <iostream>
#include <vector>
using namespace std;
const long long mod = 1e9 + 7;

long long mod_pow(long long x, long long k) {
  long long ret = 1;
  while (k) {
    if (k & 1)
      ret *= x, ret %= mod;
    x *= x, x %= mod;
    k >>= 1;
  }
  return ret;
}

int main() {
  int b, w;
  cin >> b >> w;
  int N = b + w;
  vector<long long> B(N, 0), W(N, 0), F(N + 1, 1), F_(N + 1, 1);
  for (int i = 1; i <= N; ++i)
    F[i] = F[i - 1] * i % mod;
  F_[N] = mod_pow(F[N], mod - 2);
  for (int i = N - 1; i > 0; --i)
    F_[i] = F_[i + 1] * (i + 1) % mod;
  auto comb = [&F, &F_](int n, int m) {
    if (m > n)
      return 0LL;
    return F[n] * F_[m] % mod * F_[n - m] % mod;
  };
  long long t = 1, inv2 = mod_pow(2, mod - 2);
  for (int i = 1; i < N; ++i) {
    t *= inv2, t %= mod;
    B[i] = (B[i - 1] + comb(i - 1, w - 1) * t % mod) % mod;
    W[i] = (W[i - 1] + comb(i - 1, b - 1) * t % mod) % mod;
  }
  for (int i = 0; i < N; ++i) {
    cout << ((1 + B[i] - W[i]) % mod + mod) % mod * inv2 % mod << endl;
  }
}
Problem p03083 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
const char nl = '\n';
using namespace std;
using ll = long long;
using ld = long double;
const int MOD = 1e9 + 7;
const int N = 1e5 + 10;

ll pw(ll x, ll e) {
  ll ans = 1;
  for (; e; e /= 2, x = (x * x) % MOD) {
    if (e % 2)
      ans = (ans * x) % MOD;
  }
  return ans;
}

ll fac[N], ifac[N], inv[N];
void pre() {
  fac[0] = ifac[0] = 1;
  inv[1] = 1;
  for (int i = 2; i < N; i++) {
    inv[i] = (MOD - (ll)(MOD / i) * inv[MOD % i] % MOD) % MOD;
  }
  for (int i = 1; i < N; i++) {
    fac[i] = fac[i - 1] * i % MOD;
    ifac[i] = ifac[i - 1] * inv[i] % MOD;
  }
}

ll choose(ll n, ll k) {
  if (k < 0 || k > n)
    return 0;
  return fac[n] * ifac[k] % MOD * ifac[n - k] % MOD;
}

ll now[N], nob[N], ow[N];

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  pre();
  int b, w;
  cin >> b >> w;
  ow[0] = 1;
  for (int i = 1; i < b + w; i++) {
    now[i] = (now[i - 1] + choose(i - 1, w - 1) * pw(inv[2], i)) % MOD;
    nob[i] = (nob[i - 1] + choose(i - 1, b - 1) * pw(inv[2], i)) % MOD;
    ow[i] = (1 - now[i] - nob[i] + 2 * MOD) % MOD;
    // cerr << now[i] << " ";
  }
  now[b + w] = nob[b + w] = 1;
  for (int i = 1; i <= b + w; i++) {
    // P(i is black) = P(no white) + 1/2 P(<W, <B eaten)
    cout << (now[i - 1] + inv[2] * ow[i - 1]) % MOD << nl;
  }
  // cerr << nl;
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
const char nl = '\n';
using namespace std;
using ll = long long;
using ld = long double;
const int MOD = 1e9 + 7;
const int N = 2e5 + 10;

ll pw(ll x, ll e) {
  ll ans = 1;
  for (; e; e /= 2, x = (x * x) % MOD) {
    if (e % 2)
      ans = (ans * x) % MOD;
  }
  return ans;
}

ll fac[N], ifac[N], inv[N];
void pre() {
  fac[0] = ifac[0] = 1;
  inv[1] = 1;
  for (int i = 2; i < N; i++) {
    inv[i] = (MOD - (ll)(MOD / i) * inv[MOD % i] % MOD) % MOD;
  }
  for (int i = 1; i < N; i++) {
    fac[i] = fac[i - 1] * i % MOD;
    ifac[i] = ifac[i - 1] * inv[i] % MOD;
  }
}

ll choose(ll n, ll k) {
  if (k < 0 || k > n)
    return 0;
  return fac[n] * ifac[k] % MOD * ifac[n - k] % MOD;
}

ll now[N], nob[N], ow[N];

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  pre();
  int b, w;
  cin >> b >> w;
  ow[0] = 1;
  for (int i = 1; i < b + w; i++) {
    now[i] = (now[i - 1] + choose(i - 1, w - 1) * pw(inv[2], i)) % MOD;
    nob[i] = (nob[i - 1] + choose(i - 1, b - 1) * pw(inv[2], i)) % MOD;
    ow[i] = (1 - now[i] - nob[i] + 2 * MOD) % MOD;
    // cerr << now[i] << " ";
  }
  now[b + w] = nob[b + w] = 1;
  for (int i = 1; i <= b + w; i++) {
    // P(i is black) = P(no white) + 1/2 P(<W, <B eaten)
    cout << (now[i - 1] + inv[2] * ow[i - 1]) % MOD << nl;
  }
  // cerr << nl;
  return 0;
}
Problem p03083 (C++)

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

const int MAX = 100005;
const int MOD = 1000000007;
//
int fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void init() {
  fac[0] = fac[1] = 1;
  finv[0] = finv[1] = 1;
  inv[1] = 1;
  for (int i = 2; i < MAX; i++) {
    fac[i] = fac[i - 1] * i % MOD;
    inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
    finv[i] = finv[i - 1] * inv[i] % MOD;
  }
}
int COM(int n, int k) {
  if (n < k)
    return 0;
  if (n < 0 || k < 0)
    return 0;
  return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

signed main() {
  init();
  int b, w, ans = inv[2], p = 1;
  cin >> b >> w;

  for (int i = 1; i <= b + w; i++) {
    p = (p * inv[2]) % MOD;
    ans = (ans + p * (COM(i - 2, w - 1) + MOD - COM(i - 2, b - 1))) % MOD;
    cout << ans << endl;
  }

  return 0;
}


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

const int MAX = 200005;
const int MOD = 1000000007;
//
int fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void init() {
  fac[0] = fac[1] = 1;
  finv[0] = finv[1] = 1;
  inv[1] = 1;
  for (int i = 2; i < MAX; i++) {
    fac[i] = fac[i - 1] * i % MOD;
    inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
    finv[i] = finv[i - 1] * inv[i] % MOD;
  }
}
int COM(int n, int k) {
  if (n < k)
    return 0;
  if (n < 0 || k < 0)
    return 0;
  return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

signed main() {
  init();
  int b, w, ans = inv[2], p = 1;
  cin >> b >> w;

  for (int i = 1; i <= b + w; i++) {
    p = (p * inv[2]) % MOD;
    ans = (ans + p * (COM(i - 2, w - 1) + MOD - COM(i - 2, b - 1))) % MOD;
    cout << ans << endl;
  }

  return 0;
}
Problem p03083 (C++)

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

#define F first
#define S second
#define PB push_back
#define all(x) x.begin(), x.end()

typedef long long ll;
typedef long double ld;

const int N = 1000 * 100 + 10, M = 210;
const int mod = 1000 * 1000 * 1000 + 7;

int fact[N], inv[N];

int tv(int x, int y) {
  if (!y)
    return 1;
  ll ans = tv(x, y / 2);
  ans *= ans;
  ans %= mod;
  if (y & 1)
    ans *= x;
  return ans % mod;
}

int c(int x, int y) {
  if (y > x)
    return 0;
  return 1ll * fact[x] * inv[y] % mod * inv[x - y] % mod;
}

int32_t main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  fact[0] = 1;
  for (int i = 1; i < N; i++)
    fact[i] = 1ll * fact[i - 1] * i % mod;
  inv[N - 1] = tv(fact[N - 1], mod - 2);
  for (int i = N - 2; i > -1; i--)
    inv[i] = 1ll * (i + 1) * inv[i + 1] % mod;
  int n, m;
  cin >> n >> m;
  int t = tv(2, mod - 2);
  int p = 0, q = 0;
  for (int i = 0; i < n + m; i++) {
    cout << 1ll * (1ll + p - q + mod) * t % mod << '\n';
    p += 1ll * c(i, m - 1) * tv(t, i + 1) % mod;
    p %= mod;
    q += 1ll * c(i, n - 1) * tv(t, i + 1) % mod;
    q %= mod;
  }
}


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

#define F first
#define S second
#define PB push_back
#define all(x) x.begin(), x.end()

typedef long long ll;
typedef long double ld;

const int N = 10000 * 100 + 10, M = 210;
const int mod = 1000 * 1000 * 1000 + 7;

int fact[N], inv[N];

int tv(int x, int y) {
  if (!y)
    return 1;
  ll ans = tv(x, y / 2);
  ans *= ans;
  ans %= mod;
  if (y & 1)
    ans *= x;
  return ans % mod;
}

int c(int x, int y) {
  if (y > x)
    return 0;
  return 1ll * fact[x] * inv[y] % mod * inv[x - y] % mod;
}

int32_t main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  fact[0] = 1;
  for (int i = 1; i < N; i++)
    fact[i] = 1ll * fact[i - 1] * i % mod;
  inv[N - 1] = tv(fact[N - 1], mod - 2);
  for (int i = N - 2; i > -1; i--)
    inv[i] = 1ll * (i + 1) * inv[i + 1] % mod;
  int n, m;
  cin >> n >> m;
  int t = tv(2, mod - 2);
  int p = 0, q = 0;
  for (int i = 0; i < n + m; i++) {
    cout << 1ll * (1ll + p - q + mod) * t % mod << '\n';
    p += 1ll * c(i, m - 1) * tv(t, i + 1) % mod;
    p %= mod;
    q += 1ll * c(i, n - 1) * tv(t, i + 1) % mod;
    q %= mod;
  }
}
Problem p03083 (C++)

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

const int N = 100 * 1000 + 5;
const int mod = 1000 * 1000 * 1000 + 7;

long long psw[N];
long long psb[N];
long long fac[2 * N];
int po(long long x, long long y) {
  if (y == 0)
    return 1;
  long long ans = po(x, y / 2);
  ans *= ans;
  ans %= mod;
  if (y % 2) {
    ans *= x;
    ans %= mod;
  }
  return ans;
}
int chs(int x, int y) {
  if (x < y)
    return 0;
  if (x == y)
    return 1;
  long long ans = fac[x];
  ans *= po(fac[y], mod - 2);
  ans %= mod;
  ans *= po(fac[x - y], mod - 2);
  ans %= mod;
  return ans;
}
int main() {
  fac[0] = 1;
  for (int i = 1; i < 2 * N; i++) {
    fac[i] = fac[i - 1] * i;
    fac[i] %= mod;
    //	cout << "28 " << i << " " << fac[i] << endl;
  }
  int b, w;
  cin >> b >> w;
  for (int i = 1; i <= w + b; i++) {
    long long x = chs(i - 1, w - 1);
    long long y = chs(i - 1, b - 1);
    //	cout << "73 " << x << " " << y << endl;
    x *= po(2, 1ll * i * (mod - 2));
    y *= po(2, 1ll * i * (mod - 2));
    x %= mod;
    y %= mod;
    psw[i] = psw[i - 1] + x;
    psb[i] = psb[i - 1] + y;
    psw[i] %= mod;
    psb[i] %= mod;
    long long z = 1 - psw[i - 1] - psb[i - 1] + 2 * mod;
    z %= mod;
    //	cout << i << " " << x << " " << y << " " << psw[i] << " " << psb[i] <<
    //endl;
    long long ans = (long long)psw[i - 1] + z * po(2, mod - 2);
    ans %= mod;
    cout << ans << endl;
  }
  return 0;
}


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

const int N = 100 * 1000 + 5;
const int mod = 1000 * 1000 * 1000 + 7;

long long psw[2 * N];
long long psb[2 * N];
long long fac[2 * N];
int po(long long x, long long y) {
  if (y == 0)
    return 1;
  long long ans = po(x, y / 2);
  ans *= ans;
  ans %= mod;
  if (y % 2) {
    ans *= x;
    ans %= mod;
  }
  return ans;
}
int chs(int x, int y) {
  if (x < y)
    return 0;
  if (x == y)
    return 1;
  long long ans = fac[x];
  ans *= po(fac[y], mod - 2);
  ans %= mod;
  ans *= po(fac[x - y], mod - 2);
  ans %= mod;
  return ans;
}
int main() {
  fac[0] = 1;
  for (int i = 1; i < 2 * N; i++) {
    fac[i] = fac[i - 1] * i;
    fac[i] %= mod;
    //	cout << "28 " << i << " " << fac[i] << endl;
  }
  int b, w;
  cin >> b >> w;
  for (int i = 1; i <= w + b; i++) {
    long long x = chs(i - 1, w - 1);
    long long y = chs(i - 1, b - 1);
    //	cout << "73 " << x << " " << y << endl;
    x *= po(2, 1ll * i * (mod - 2));
    y *= po(2, 1ll * i * (mod - 2));
    x %= mod;
    y %= mod;
    psw[i] = psw[i - 1] + x;
    psb[i] = psb[i - 1] + y;
    psw[i] %= mod;
    psb[i] %= mod;
    long long z = 1 - psw[i - 1] - psb[i - 1] + 2 * mod;
    z %= mod;
    //	cout << i << " " << x << " " << y << " " << psw[i] << " " << psb[i] <<
    //endl;
    long long ans = (long long)psw[i - 1] + z * po(2, mod - 2);
    ans %= mod;
    cout << ans << endl;
  }
  return 0;
}
Problem p03083 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int MOD = 1e9 + 7;
int pw(int n, int k) {
  if (k < 0)
    return pw(n, k + MOD - 1);
  int res = 1;
  while (k) {
    if (k & 1)
      res *= n;
    res %= MOD;
    n *= n;
    n %= MOD;
    k >>= 1;
  }
  return res;
}
std::vector<int> Factorial(5e6), Finverse(5e6);
void Cinit() { // limit is 5e6 /// write Cinit&pw /// this takes 792ms at
               // AtCoder
  Factorial[0] = 1;
  for (int i = 1; i < 5e6; i++)
    Factorial[i] = Factorial[i - 1] * i % MOD;
  for (int i = 0; i < 5e6; i++)
    Finverse[i] = pw(Factorial[i], MOD - 2);
}
int nCk(int n, int k) {
  if (n < k)
    return 1;
  if (k < 0)
    return 0;
  int res = Factorial[n];
  res *= Finverse[k];
  res %= MOD;
  res *= Finverse[n - k];
  res %= MOD;
  return res;
}

/*
黒がなくなってる可能性と白がなくなってる可能性をそれぞれb_i,w_iとすると
(1-b_i-w_i)*1/2+w_i
更新は？
k回目でなくなってる可能性　(1/2)^k*nCk(k-1,B-1);
*/
int B, W;
int b[123456], w[123456];

signed main() {
  Cinit();
  cin >> B >> W;
  for (int i = B; i < B + W; i++)
    b[i] = nCk(i - 1, B - 1) * pw(pw(2, i), MOD - 2) % MOD;
  for (int i = W; i < B + W; i++)
    w[i] = nCk(i - 1, W - 1) * pw(pw(2, i), MOD - 2) % MOD;
  for (int i = 0; i < B + W; i++)
    b[i + 1] += b[i], w[i + 1] += w[i], b[i + 1] %= MOD, w[i + 1] %= MOD;
  for (int i = 1; i <= B + W; i++) {
    int res = (1 - b[i - 1] - w[i - 1]) * pw(2, MOD - 2) + w[i - 1];
    res %= MOD;
    if (res < 0)
      res += MOD;
    cout << res << endl;
  }
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int MOD = 1e9 + 7;
int pw(int n, int k) {
  if (k < 0)
    return pw(n, k + MOD - 1);
  int res = 1;
  while (k) {
    if (k & 1)
      res *= n;
    res %= MOD;
    n *= n;
    n %= MOD;
    k >>= 1;
  }
  return res;
}
std::vector<int> Factorial(5e6), Finverse(5e6);
void Cinit() { // limit is 5e6 /// write Cinit&pw /// this takes 792ms at
               // AtCoder
  Factorial[0] = 1;
  for (int i = 1; i < 5e6; i++)
    Factorial[i] = Factorial[i - 1] * i % MOD;
  for (int i = 0; i < 5e6; i++)
    Finverse[i] = pw(Factorial[i], MOD - 2);
}
int nCk(int n, int k) {
  if (n < k)
    return 1;
  if (k < 0)
    return 0;
  int res = Factorial[n];
  res *= Finverse[k];
  res %= MOD;
  res *= Finverse[n - k];
  res %= MOD;
  return res;
}

/*
黒がなくなってる可能性と白がなくなってる可能性をそれぞれb_i,w_iとすると
(1-b_i-w_i)*1/2+w_i
更新は？
k回目でなくなってる可能性　(1/2)^k*nCk(k-1,B-1);
*/
int B, W;
int b[223456], w[223456];

signed main() {
  Cinit();
  cin >> B >> W;
  for (int i = B; i < B + W; i++)
    b[i] = nCk(i - 1, B - 1) * pw(pw(2, i), MOD - 2) % MOD;
  for (int i = W; i < B + W; i++)
    w[i] = nCk(i - 1, W - 1) * pw(pw(2, i), MOD - 2) % MOD;
  for (int i = 0; i < B + W; i++)
    b[i + 1] += b[i], w[i + 1] += w[i], b[i + 1] %= MOD, w[i + 1] %= MOD;
  for (int i = 1; i <= B + W; i++) {
    int res = (1 - b[i - 1] - w[i - 1]) * pw(2, MOD - 2) + w[i - 1];
    res %= MOD;
    if (res < 0)
      res += MOD;
    cout << res << endl;
  }
}
Problem p03083 (C++)

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

const int mod = 1000000007, inv2 = mod + 1 >> 1;
long long fac[200010], inv[200010];
int B, W;

long long Pow(long long x, long long y) {
  long long ans = 1;
  for (; y; y >>= 1, x = x * x % mod)
    if (y & 1)
      ans = ans * x % mod;
  return ans;
}
void pre(int n = 200000) {
  fac[0] = 1;
  for (int i = 1; i <= n; i++)
    fac[i] = fac[i - 1] * i % mod;
  inv[n] = Pow(fac[n], mod - 2);
  for (int i = n - 1; i >= 0; i--)
    inv[i] = inv[i + 1] * (i + 1) % mod;
}
long long C(int x, int y) { return fac[x] * inv[y] % mod * inv[x - y] % mod; }
int main() {
  pre();
  scanf("%d%d", &B, &W);
  if (B < W) {
    for (int i = 1; i <= B; i++)
      printf("%d\n", inv2);
    long long hh = Pow(inv2, B + 1);
    long long now = (inv2 - hh + mod) % mod;
    for (int i = B + 1; i <= W; i++) {
      printf("%lld\n", now);
      now = (now - hh * Pow(inv2, i - B) % mod * C(i - 1, B - 1) % mod + mod) %
            mod;
    }
  } else
    for (int i = 1; i <= W; i++)
      printf("%d\n", inv2);
  long long now1 = 0, now2 = 1;
  for (int i = 1; i < B; i++)
    now1 = (now1 + C(W, i)) % mod;
  for (int i = W + 1; i <= W + B; i++) {
    printf("%lld\n",
           (now1 * Pow(inv2, i) % mod + now2 * Pow(inv2, W) % mod) % mod);
    now1 = ((now1 * 2 % mod - C(i - 1, i - W) - C(i - 1, B - 1)) % mod + mod) %
           mod;
    now2 = (now2 + Pow(inv2, i - W) * C(i - 1, W - 1) % mod) % mod;
  }
}


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

const int mod = 1000000007, inv2 = mod + 1 >> 1;
long long fac[200010], inv[200010];
int B, W;

long long Pow(long long x, long long y) {
  long long ans = 1;
  for (; y; y >>= 1, x = x * x % mod)
    if (y & 1)
      ans = ans * x % mod;
  return ans;
}
void pre(int n = 200000) {
  fac[0] = 1;
  for (int i = 1; i <= n; i++)
    fac[i] = fac[i - 1] * i % mod;
  inv[n] = Pow(fac[n], mod - 2);
  for (int i = n - 1; i >= 0; i--)
    inv[i] = inv[i + 1] * (i + 1) % mod;
}
long long C(int x, int y) {
  if (x < y)
    return 0;
  return fac[x] * inv[y] % mod * inv[x - y] % mod;
}
int main() {
  pre();
  scanf("%d%d", &B, &W);
  if (B < W) {
    for (int i = 1; i <= B; i++)
      printf("%d\n", inv2);
    long long hh = Pow(inv2, B + 1);
    long long now = (inv2 - hh + mod) % mod;
    for (int i = B + 1; i <= W; i++) {
      printf("%lld\n", now);
      now = (now - hh * Pow(inv2, i - B) % mod * C(i - 1, B - 1) % mod + mod) %
            mod;
    }
  } else
    for (int i = 1; i <= W; i++)
      printf("%d\n", inv2);
  long long now1 = 0, now2 = 1;
  for (int i = 1; i < B; i++)
    now1 = (now1 + C(W, i)) % mod;
  for (int i = W + 1; i <= W + B; i++) {
    printf("%lld\n",
           (now1 * Pow(inv2, i) % mod + now2 * Pow(inv2, W) % mod) % mod);
    now1 = ((now1 * 2 % mod - C(i - 1, i - W) - C(i - 1, B - 1)) % mod + mod) %
           mod;
    now2 = (now2 + Pow(inv2, i - W) * C(i - 1, W - 1) % mod) % mod;
  }
}
Problem p03085 (Python)

Buggy submission (status: Runtime Error):
def main():
    to = ["T", "G"]
    fr = ["A", "C"]

    print(to[fr.index(input())])


if __name__ == "__main__":
    main()


Fixed submission:
def main():
    to = ["T", "G"]
    fr = ["A", "C"]

    inc = input()

    try:
        print(to[fr.index(inc)])
    except Exception:
        print(fr[to.index(inc)])


if __name__ == "__main__":
    main()
Problem p03085 (Python)

Buggy submission (status: Runtime Error):
b = input()
a = ""
for i in range(4):
    if b[i] == "A":
        a += "T"
    elif b[i] == "T":
        a += "A"
    elif b[i] == "C":
        a += "G"
    elif b[i] == "G":
        a += "C"
print(a)


Fixed submission:
b = input()
a = ""
for i in range(len(b)):
    if b[i] == "A":
        a += "T"
    elif b[i] == "T":
        a += "A"
    elif b[i] == "C":
        a += "G"
    elif b[i] == "G":
        a += "C"
print(a)
Problem p03085 (Python)

Buggy submission (status: Runtime Error):
input("ATCG"["TAGC".find(input())])


Fixed submission:
print("ATCG"["TAGC".find(input())])
Problem p03085 (Python)

Buggy submission (status: Runtime Error):
b = int(input())
if b == "A":
    print("T")
elif b == "C":
    print("G")
elif b == "T":
    print("A")
else:
    print("C")


Fixed submission:
b = input()
if b == "A":
    print("T")
elif b == "C":
    print("G")
elif b == "T":
    print("A")
else:
    print("C")
Problem p03085 (Python)

Buggy submission (status: Runtime Error):
b = int(input())
print("A" if b == "T" else "T" if b == "A" else "C" if b == "G" else "G")


Fixed submission:
b = input()
print("A" if b == "T" else "T" if b == "A" else "C" if b == "G" else "G")
Problem p03085 (Python)

Buggy submission (status: Runtime Error):
s = input()

dict = {"A": "T", "C": "G"}
print(dict[s])


Fixed submission:
s = input()

dict = {"A": "T", "C": "G", "T": "A", "G": "C"}
print(dict[s])
Problem p03086 (C++)

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

int main() {

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

  int res = 0;
  for (int i = 0; i < n; ++i) {
    for (int j = i; j < n; ++j) {
      string sub = s.substr(i, j - i + 1);
      int num = sub.size();

      bool flg = true;
      for (int k = 0; i < num; ++k) {
        char c = sub[k];
        if (c != 'A' && c != 'C' && c != 'G' && c != 'T') {
          flg = false;
        }
      }

      if (flg)
        res = max(res, num);
    }
  }

  cout << res << endl;

  return 0;
}

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

int main() {

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

  int res = 0;
  for (int i = 0; i < n; ++i) {
    for (int j = i; j < n; ++j) {
      string sub = s.substr(i, j - i + 1);
      int num = sub.size();

      bool flg = true;
      for (int k = 0; k < num; ++k) {
        char c = sub[k];
        if (c != 'A' && c != 'C' && c != 'G' && c != 'T') {
          flg = false;
        }
      }

      if (flg)
        res = max(res, num);
    }
  }

  cout << res << endl;

  return 0;
}
Problem p03086 (C++)

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

int main() {
  string S;
  cin >> S;
  int ans = 0;

  for (int i = 0; i < S.size(); i++) {
    int ans1 = 0;
    int j = i;
    while (S.at(j) == 'A' || S.at(j) == 'T' || S.at(j) == 'G' ||
           S.at(j) == 'C') {
      ans1++;
      j++;
    }
    ans = max(ans, ans1);
  }
  cout << ans << endl;
}

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

int main() {
  string S;
  cin >> S;
  S += 'Z';
  int ans = 0;

  for (int i = 0; i < S.size(); i++) {
    int ans1 = 0;
    int j = i;
    while (S.at(j) == 'A' || S.at(j) == 'T' || S.at(j) == 'G' ||
           S.at(j) == 'C') {
      ans1++;
      j++;
    }
    ans = max(ans, ans1);
  }
  cout << ans << endl;
}
Problem p03086 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
#define rrep(i, n) for (int i = 1; i <= n; i++)
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())
#define pb push_back
using namespace std;

int main() {
  string s;
  int ans = 0;
  cin >> s;
  rep(i, s.size()) {
    int c = 0;
    while (s.at(i) == 'A' || s.at(i) == 'C' || s.at(i) == 'G' ||
           s.at(i) == 'T') {
      i++;
      c++;
      ans = max(ans, c);
    }
  }
  cout << ans << endl;
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
#define rrep(i, n) for (int i = 1; i <= n; i++)
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())
#define pb push_back
using namespace std;

int main() {
  string s;
  int ans = 0;
  cin >> s;
  rep(i, s.size()) {
    int c = 0;
    while (s[i] == 'A' || s[i] == 'C' || s[i] == 'G' || s[i] == 'T') {
      i++;
      c++;
      ans = max(ans, c);
    }
  }
  cout << ans << endl;
  return 0;
}
Problem p03086 (C++)

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

int main() {
  string str;
  cin >> str;
  int i, j, sum = 0;
  vector<int> v;

  for (i = 0; i < str.size(); i++) {
    if (str[i] == 'A' || str[i] == 'G' || str[i] == 'C' || str[i] == 'T') {
      sum = sum + 1;
    } else {
      v.push_back(sum);
      sum = 0;
    }
  }
  sort(v.begin(), v.end());

  cout << v[v.size() - 1];
}


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

int main() {
  string str;
  cin >> str;
  int i, j, sum = 0;
  vector<int> v;

  for (i = 0; i < str.size(); i++) {
    if (str[i] == 'A' || str[i] == 'G' || str[i] == 'C' || str[i] == 'T') {
      sum = sum + 1;
    } else {
      v.push_back(sum);
      sum = 0;
    }
  }
  v.push_back(sum);
  sort(v.begin(), v.end());

  cout << v[v.size() - 1];
}
Problem p03086 (C++)

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

using namespace std;

#define REP(a, i, n) for (int i = a; i < n; ++i)

bool f(char b) {
  if ((b == 'A') || (b == 'T') || (b == 'C') || (b == 'G')) {
    return true;
  } else {
    return false;
  }
}

int main() {
  string S;
  cin >> S;

  int l = 0;
  vector<int> v;
  REP(0, i, S.length()) {
    if (f(S[i]))
      l++;
    else {
      v.push_back(l);
      l = 0;
    }
  }

  sort(v.begin(), v.end(), greater<int>());

  cout << v[0] << endl;

  return 0;
}


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

using namespace std;

#define REP(a, i, n) for (int i = a; i < n; ++i)

bool f(char b) {
  if ((b == 'A') || (b == 'T') || (b == 'C') || (b == 'G')) {
    return true;
  } else {
    return false;
  }
}

int main() {
  string S;
  cin >> S;

  int l = 0;
  vector<int> v;
  REP(0, i, S.length()) {
    if (f(S[i]))
      l++;
    else {
      v.push_back(l);
      l = 0;
    }
  }

  if (l != 0) {
    v.push_back(l);
    l = 0;
  }

  sort(v.begin(), v.end(), greater<int>());

  cout << v[0] << endl;

  return 0;
}
Problem p03086 (C++)

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

int main() {
  string S;
  cin >> S;
  priority_queue<int> ans;
  int count = 0;
  int N = S.size();
  for (int i = 0; i < N; i++) {
    if (S.at(i) == 'A' || S.at(i) == 'G' || S.at(i) == 'C' || S.at(i) == 'T')
      count++;
    else {
      ans.push(count);
      count = 0;
    }
  }
  cout << ans.top() << endl;
}


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

int main() {
  string S;
  cin >> S;
  priority_queue<int> ans;
  int count = 0;
  int N = S.size();
  for (int i = 0; i < N; i++) {
    if (S.at(i) == 'A' || S.at(i) == 'G' || S.at(i) == 'C' || S.at(i) == 'T')
      count++;
    else {
      ans.push(count);
      count = 0;
    }
  }
  ans.push(count);
  cout << ans.top() << endl;
}
Problem p03086 (C++)

Buggy submission (status: Runtime Error):
#include "algorithm"
#include "bitset"
#include "cassert"
#include "climits"
#include "cmath"
#include "cstdio"
#include "functional"
#include "iomanip"
#include "iostream"
#include "list"
#include "map"
#include "numeric"
#include "queue"
#include "random"
#include "set"
#include "stack"
#include "string"
#include "unordered_map"
#include "unordered_set"

using namespace std;

const long long int MOD = 1000000007;
// const int MOD = 1000000007;
// const int MOD = 998244353;

long long int N, M, K, H, W, L, R;
// int N, M, K, H, W, L, R;

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

  string s;
  vector<int> v(s.size());
  for (int i = 0; i < s.size(); i++) {
    if (s[i] == 'A' || s[i] == 'C' || s[i] == 'G' || s[i] == 'T')
      v[i]++;
    if (i)
      v[i] = v[i] * v[i - 1] + v[i];
  }
  cout << *max_element(v.begin(), v.end()) << endl;
  return 0;
}

Fixed submission:
#include "algorithm"
#include "bitset"
#include "cassert"
#include "climits"
#include "cmath"
#include "cstdio"
#include "functional"
#include "iomanip"
#include "iostream"
#include "list"
#include "map"
#include "numeric"
#include "queue"
#include "random"
#include "set"
#include "stack"
#include "string"
#include "unordered_map"
#include "unordered_set"

using namespace std;

const long long int MOD = 1000000007;
// const int MOD = 1000000007;
// const int MOD = 998244353;

long long int N, M, K, H, W, L, R;
// int N, M, K, H, W, L, R;

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

  string s;
  cin >> s;
  vector<int> v(s.size());
  for (int i = 0; i < s.size(); i++) {
    if (s[i] == 'A' || s[i] == 'C' || s[i] == 'G' || s[i] == 'T')
      v[i]++;
    if (i)
      v[i] = v[i] * v[i - 1] + v[i];
  }
  cout << *max_element(v.begin(), v.end()) << endl;
  return 0;
}
Problem p03086 (C++)

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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)

int main() {
  string S;
  int buf = 0;
  vector<int> cnt;
  cin >> S;
  for (int i = 0; i < S.size(); i++) {
    if (S.at(i) == 'A' || S.at(i) == 'C' || S.at(i) == 'G' || S.at(i) == 'T') {
      buf++;
    } else {
      cnt.push_back(buf);
      buf = 0;
    }
  }
  sort(cnt.begin(), cnt.end());
  reverse(cnt.begin(), cnt.end());
  cout << cnt.at(0) << endl;
}

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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)

int main() {
  string S;
  int buf = 0;
  vector<int> cnt;
  cin >> S;
  for (int i = 0; i < S.size(); i++) {
    if (S.at(i) == 'A' || S.at(i) == 'C' || S.at(i) == 'G' || S.at(i) == 'T') {
      buf++;
    } else {
      cnt.push_back(buf);
      buf = 0;
    }
  }
  cnt.push_back(buf);
  sort(cnt.begin(), cnt.end());
  reverse(cnt.begin(), cnt.end());
  cout << cnt.at(0) << endl;
}
Problem p03086 (C++)

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

int main() {
  string s;
  cin >> s;
  int size = s.size();
  vector<int> a(size);
  for (int i = 0; i < size; i++) {
    if (s.at(i) == 'A' || s.at(i) == 'C' || s.at(i) == 'G' || s.at(i) == 'T') {
      a.at(i) = 1;
    }
  }
  int k = 0;
  priority_queue<int> pq;
  for (int i = 0; i < size; i++) {
    if (a.at(i) == 1)
      k++;
    else {
      pq.push(k);
      k = 0;
    }
  }
  cout << pq.top() << endl;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int MOD = 1000000007;

int main() {
  string s;
  cin >> s;
  int size = s.size();
  vector<int> a(size);
  for (int i = 0; i < size; i++) {
    if (s.at(i) == 'A' || s.at(i) == 'C' || s.at(i) == 'G' || s.at(i) == 'T') {
      a.at(i) = 1;
    }
  }
  int k = 0;
  priority_queue<int> pq;
  for (int i = 0; i < size; i++) {
    if (a.at(i) == 1) {
      if (i == size - 1) {
        k++;
        pq.push(k);
      } else
        k++;
    } else {
      pq.push(k);
      k = 0;
    }
  }
  cout << pq.top() << endl;
}
Problem p03086 (C++)

Buggy submission (status: Runtime Error):
// スタックサイズ: 100MB

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <unordered_map>
#include <vector>
using namespace std;

typedef int64_t ll;
typedef vector<ll> vll;
typedef pair<ll, ll> pll;
const ll INF = 1000000000000000000;
#define fori(i, a, b) for (ll i = (a); i < (b); ++i)
#define ford(i, a, b) for (ll i = (b - 1); (a) <= i; --i)
#define rep(i, n) fori(i, 0, n)
#define all(v) (v).begin(), (v).end()
ll pw(ll x, ll y) {
  ll r = 1;
  rep(i, y) { r *= x; };
  return r;
}

int main() {

  char at[4] = {'A', 'T', 'C', 'G'};
  string s;
  cin >> s;
  ll tmp = 0;
  vll ans;
  rep(i, s.size()) {
    if (s[i] == at[0] || s[i] == at[1] || s[i] == at[2] || s[i] == at[3])
      ++tmp;
    else {
      ans.push_back(tmp);
      tmp = 0;
    }
  }
  cout << *max_element(all(ans)) << endl;
}

Fixed submission:
// スタックサイズ: 100MB

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <unordered_map>
#include <vector>
using namespace std;

typedef int64_t ll;
typedef vector<ll> vll;
typedef pair<ll, ll> pll;
const ll INF = 1000000000000000000;
#define fori(i, a, b) for (ll i = (a); i < (b); ++i)
#define ford(i, a, b) for (ll i = (b - 1); (a) <= i; --i)
#define rep(i, n) fori(i, 0, n)
#define all(v) (v).begin(), (v).end()
ll pw(ll x, ll y) {
  ll r = 1;
  rep(i, y) { r *= x; };
  return r;
}

int main() {

  char at[4] = {'A', 'T', 'C', 'G'};
  string s;
  cin >> s;
  ll tmp = 0;
  vll ans;
  rep(i, s.size()) {
    if (s[i] == at[0] || s[i] == at[1] || s[i] == at[2] || s[i] == at[3])
      ++tmp;
    else {
      ans.push_back(tmp);
      tmp = 0;
    }
  }
  ans.push_back(tmp);
  cout << *max_element(all(ans)) << endl;
}
Problem p03086 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <utility>
#include <vector>
#define endl '\n'
#define fi first
#define se second
#define pb push_back
#define debug(x) cout << "[debug] " << #x << ": " << x << endl
using namespace std;
typedef long long ll;
typedef pair<int, int> PII;
const int MOD = 1e9 + 7;
const int maxn = 1e6 + 5;
const int inf = 0x3f3f3f3f;
const ll INF = 0x3f3f3f3f3f3f3f3f;
const double eps = 1e-8;

int main() {
  string s;
  cin >> s;
  vector<int> ans;
  int sum = 0;
  for (int i = 0; i < s.size(); ++i) {
    if (s[i] == 'A' || s[i] == 'C' || s[i] == 'G' || s[i] == 'T')
      sum++;
    else {
      ans.pb(sum);
      sum = 0;
    }
  }
  sort(ans.begin(), ans.end());
  cout << ans[ans.size() - 1] << endl;
  return 0;
}

Fixed submission:
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <utility>
#include <vector>
#define endl '\n'
#define fi first
#define se second
#define pb push_back
#define debug(x) cout << "[debug] " << #x << ": " << x << endl
using namespace std;
typedef long long ll;
typedef pair<int, int> PII;
const int MOD = 1e9 + 7;
const int maxn = 1e6 + 5;
const int inf = 0x3f3f3f3f;
const ll INF = 0x3f3f3f3f3f3f3f3f;
const double eps = 1e-8;

int main() {
  string s;
  cin >> s;
  vector<int> ans;
  int sum = 0;
  for (int i = 0; i < s.size(); ++i) {
    if (s[i] == 'A' || s[i] == 'C' || s[i] == 'G' || s[i] == 'T')
      sum++;
    else {
      ans.pb(sum);
      sum = 0;
    }
  }
  ans.pb(sum);
  sort(ans.begin(), ans.end());
  cout << ans[ans.size() - 1] << endl;
  return 0;
}
Problem p03086 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
int main(void) {
  string str, stra;
  int j = 0, max = 0;
  cin >> str;
  for (int i = 0; i < str.size(); i++) {
    j = i;
    stra = "";
    while (str.at(j) == 'A' || str.at(j) == 'T' || str.at(j) == 'G' ||
           str.at(j) == 'C') {
      stra = stra + str.at(j);
      j++;
    }
    if (stra.size() > max)
      max = stra.size();
  }
  cout << max << endl;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int main(void) {
  string str, stra;
  int j = 0, max = 0;
  cin >> str;
  for (int i = 0; i < str.size(); i++) {
    j = i;
    stra = "";
    while (j < str.size() && (str.at(j) == 'A' || str.at(j) == 'T' ||
                              str.at(j) == 'G' || str.at(j) == 'C')) {
      stra = stra + str.at(j);
      j++;
    }
    if (stra.size() > max)
      max = stra.size();
  }
  cout << max << endl;
}
Problem p03086 (C++)

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

std::string s;
std::vector<int> vec;
int c = 0;
int main() {
  std::cin >> s;
  for (int i = 0; i < s.size(); i++) {
    if (s[i] == 'A' || s[i] == 'T' || s[i] == 'G' || s[i] == 'C') {
      c++;
    } else {
      vec.push_back(c);
      c = 0;
    }
  }
  std::cout << *std::max_element(vec.begin(), vec.end()) << std::endl;
}


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

std::string s;
std::vector<int> vec;
int c = 0;
int main() {
  std::cin >> s;
  for (int i = 0; i < s.size(); i++) {
    if (s[i] == 'A' || s[i] == 'T' || s[i] == 'G' || s[i] == 'C') {
      c++;
    } else {
      vec.push_back(c);
      c = 0;
    }
  }
  vec.push_back(c);
  std::cout << *std::max_element(vec.begin(), vec.end()) << std::endl;
}
Problem p03086 (C++)

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

int main() {
  string S;
  cin >> S;

  int ans = 0;

  int cont;
  for (int i = 0; i < S.size(); i++) {
    cont = 0;
    while (S.at(i) == 'A' || S.at(i) == 'C' || S.at(i) == 'G' ||
           S.at(i) == 'T') {
      i++;
      cont++;
    }
    if (cont > ans)
      ans = cont;
  }
  cout << ans << endl;
}

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

int main() {
  string S;
  cin >> S;

  int ans = 0;

  int cont;
  for (int i = 0; i < S.size(); i++) {
    cont = 0;
    while (i < S.size() && (S.at(i) == 'A' || S.at(i) == 'C' ||
                            S.at(i) == 'G' || S.at(i) == 'T')) {
      i++;
      cont++;
    }
    if (cont > ans)
      ans = cont;
  }
  cout << ans << endl;
}
Problem p03086 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
int main() {
  string s;
  cin >> s;
  vector<int> v;
  for (int i = 0; i < s.size(); i++)
    if (s[i] != 'A' && s[i] != 'C' && s[i] != 'G' && s[i] != 'T')
      v.push_back(i);
  int ans = 0;
  for (int i = 1; i < v.size(); i++)
    ans = max(ans, v[i] - v[i - 1] - 1);
  ans = max(ans, v[0]);
  ans = max(ans, (int)s.size() - v[v.size() - 1] - 1);
  cout << ans << endl;
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int main() {
  string s;
  cin >> s;
  vector<int> v;
  for (int i = 0; i < s.size(); i++)
    if (s[i] != 'A' && s[i] != 'C' && s[i] != 'G' && s[i] != 'T')
      v.push_back(i);
  if (v.empty()) {
    cout << s.size() << endl;
    return 0;
  }
  int ans = 0;
  for (int i = 1; i < v.size(); i++)
    ans = max(ans, v[i] - v[i - 1] - 1);
  ans = max(ans, v[0]);
  ans = max(ans, (int)s.size() - v[v.size() - 1] - 1);
  cout << ans << endl;
  return 0;
}
Problem p03086 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
int main() {
  string S;
  cin >> S;
  int cnt = 0;
  vector<int> vec;
  for (int i = 0; i < S.length(); i++) {
    if (S[i] == 'A' || S[i] == 'C' || S[i] == 'G' || S[i] == 'T') {
      cnt++;
    } else {
      vec.push_back(cnt);
      cnt = 0;
    }
  }
  sort(vec.begin(), vec.end(), greater<int>());
  cout << vec[0] << endl;
  return 0;
}


Fixed submission:
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
int main() {
  string S;
  cin >> S;
  int cnt = 0;
  vector<int> vec;
  for (int i = 0; i < S.length(); i++) {
    if (S[i] == 'A' || S[i] == 'C' || S[i] == 'G' || S[i] == 'T') {
      cnt++;
    } else {
      vec.push_back(cnt);
      cnt = 0;
    }
  }
  vec.push_back(cnt);
  sort(vec.begin(), vec.end(), greater<int>());
  cout << vec[0] << endl;
  return 0;
}
Problem p03086 (Python)

Buggy submission (status: Runtime Error):
pat = ["A", "C", "G", "T"]

s = input()

left = right = 0
ans = 0

while left < len(s):
    right = left
    while s[right] in pat:
        right += 1

    ans = max(ans, right - left)

    left = right + 1

print(ans)


Fixed submission:
pat = ["A", "C", "G", "T"]

s = input()

left = right = 0
ans = 0

while left < len(s):
    right = left
    while right < len(s) and s[right] in pat:
        right += 1

    ans = max(ans, right - left)

    left = right + 1

print(ans)
Problem p03086 (C++)

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

using namespace std;

int main() {
  string str;
  vector<int> vec;

  cin >> str;

  for (int i = 0; i < (int)str.length(); i++) {
    for (int j = 0; j < (int)str.length() - i; j++) {
      if (str[i + j] != 'A' && str[i + j] != 'C' && str[i + j] != 'G' &&
          str[i + j] != 'T') {
        vec.push_back(j);
        break;
      }
    }
  }
  sort(vec.begin(), vec.end());

  cout << vec.back() << endl;

  /* for(auto itr = vec.begin(); itr != vec.end(); ++itr) {
       cout << *itr ;
   }*/
  cout << endl;

  return 0;
}


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

using namespace std;

int main() {
  string str;
  vector<int> vec;

  cin >> str;

  for (int i = 0; i < (int)str.length(); i++) {
    for (int j = 0; j < (int)str.length() - i; j++) {
      if (str[i + j] != 'A' && str[i + j] != 'C' && str[i + j] != 'G' &&
          str[i + j] != 'T') {
        vec.push_back(j);
        break;
      }
      if (i + j == (int)str.length() - 1) {
        vec.push_back(j + 1);
        break;
      }
    }
  }
  sort(vec.begin(), vec.end());

  cout << vec.back() << endl;

  /* for(auto itr = vec.begin(); itr != vec.end(); ++itr) {
       cout << *itr ;
   }*/
  cout << endl;

  return 0;
}
Problem p03086 (C++)

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

int main() {
  string S;
  cin >> S;
  vector<int> a;
  int x = 0;
  for (int i = 0; i < S.size(); i++) {
    if (S.at(i) == 'A' || S.at(i) == 'C' || S.at(i) == 'G' || S.at(i) == 'T') {
      x++;
    } else {
      a.push_back(x);
      x = 0;
    }
  }
  sort(a.rbegin(), a.rend());
  cout << a[0];
}


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

int main() {
  string S;
  cin >> S;
  vector<int> a;
  int x = 0;
  for (int i = 0; i < S.size(); i++) {
    if (S.at(i) == 'A' || S.at(i) == 'C' || S.at(i) == 'G' || S.at(i) == 'T') {
      x++;
    } else {
      a.push_back(x);
      x = 0;
    }
  }
  a.push_back(x);
  sort(a.rbegin(), a.rend());
  cout << a[0];
}