alexjercan/bugnet huggingface dataset:
Problem p00494 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <cstring>
#include <iostream>
#include <map>
#include <set>
#include <sstream>
#include <string>
#include <vector>

#define REP(i, k, n) for (int i = k; i < n; i++)
#define rep(i, n) for (int i = 0; i < n; i++)
#define INF 1 << 30
#define pb push_back
#define mp make_pair

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

vector<string> samesplit(string s) {
  vector<string> ret;
  rep(i, s.size()) {
    stringstream ss;
    ss << s[i];
    REP(j, i + 1, s.size()) {
      if (s[i] == s[j]) {
        ss << s[j];
        i++;
      } else
        break;
    }
    ret.push_back(ss.str());
  }
  return ret;
}

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

  vector<string> ret = samesplit(s);
  int ans = 0;

  if (ret.size() <= 2) {
    cout << 0 << endl;
    return 0;
  }

  rep(i, ret.size() - 2) {
    if (ret[i][0] == 'J' && ret[i + 1][0] == 'O' && ret[i + 2][0] == 'I' &&
        ret[i].size() >= ret[i + 1].size() &&
        ret[i + 2].size() >= ret[i + 1].size()) {
      ans = max(ans, (int)ret[i + 1].size());
    }
  }

  cout << ans << endl;

  return 0;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <cstring>
#include <iostream>
#include <map>
#include <set>
#include <sstream>
#include <string>
#include <vector>

#define REP(i, k, n) for (int i = k; i < n; i++)
#define rep(i, n) for (int i = 0; i < n; i++)
#define INF 1 << 30
#define pb push_back
#define mp make_pair

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

vector<string> samesplit(string s) {
  vector<string> ret;
  rep(i, s.size()) {
    stringstream ss;
    ss << s[i];
    REP(j, i + 1, s.size()) {
      if (s[i] == s[j]) {
        ss << s[j];
        i++;
      } else
        break;
    }
    ret.push_back(ss.str());
  }
  return ret;
}

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

  if (s.size() <= 2) {
    cout << 0 << endl;
    return 0;
  }

  vector<string> ret = samesplit(s);
  int ans = 0;

  rep(i, ret.size() - 2) {
    if (ret[i][0] == 'J' && ret[i + 1][0] == 'O' && ret[i + 2][0] == 'I' &&
        ret[i].size() >= ret[i + 1].size() &&
        ret[i + 2].size() >= ret[i + 1].size()) {
      ans = max(ans, (int)ret[i + 1].size());
    }
  }

  cout << ans << endl;

  return 0;
}
Problem p00494 (C++) — buggy submission, verdict: Runtime Error

/*
    キレそう
 */

#include <cstdio>
#include <cstring>
#include <utility>
#include <vector>
using namespace std;

typedef pair<char, int> Pair;

char buf[1000001];
vector<Pair> v;

int main() {
  char prev;
  int len;
  int count;
  int size;
  int ans;

  scanf("%s", buf);
  len = strlen(buf);
  prev = buf[0];
  count = 1;
  for (int i = 1; i < len + 1; i++) {
    if (prev == buf[i])
      count++;
    else {
      v.push_back(Pair(prev, count));
      count = 1;
    }
    prev = buf[i];
  }

  ans = 0;
  size = v.size();
  for (int i = 0; i < size - 2; i++) {
    if (v[i].first == 'J' && v[i + 1].first == 'O' && v[i + 2].first == 'I') {
      if (v[i + 1].second <= min(v[i].second, v[i + 2].second)) {
        ans = max(ans, v[i + 1].second);
      }
    }
  }

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

Error: 0

Fixed submission:

#include <cstdio>
#include <cstring>
#include <utility>
#include <vector>
using namespace std;

typedef pair<char, int> Pair;

char buf[1000001];
vector<Pair> v;

int main() {
  char prev;
  int len;
  int count;
  int ans;

  scanf("%s", buf);
  len = strlen(buf);
  prev = buf[0];
  count = 1;
  for (int i = 1; i < len + 1; i++) {
    if (prev == buf[i])
      count++;
    else {
      v.push_back(Pair(prev, count));
      count = 1;
    }
    prev = buf[i];
  }

  ans = 0;
  for (int i = 0; i < v.size() - 2; i++) {
    if (v[i].first == 'J' && v[i + 1].first == 'O' && v[i + 2].first == 'I') {
      if (v[i + 1].second <= min(v[i].second, v[i + 2].second)) {
        ans = max(ans, v[i + 1].second);
      }
    }
  }

  printf("%d\\n", ans);
}
Problem p00494 (C++) — buggy submission, verdict: Time Limit Exceeded

#define _USE_MATH_DEFINES
#include <algorithm>
#include <cmath>
#include <deque>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;

int main() {

  string str;
  cin >> str;

  long i = 0;
  char c = 'J';
  int res = 0;

  while (i < str.length()) {
    int levelj = 0;
    int levelo = 0;
    int leveli = 0;

    while (str[i] == 'J') {
      levelj += 1;
      i += 1;
    }
    while (str[i] == 'O') {
      levelo += 1;
      i += 1;
    }
    while (str[i] == 'I') {
      leveli += 1;
      i += 1;
    }
    if (0 < levelo && levelo <= levelj && levelo <= leveli) {
      res = max(res, levelo);
    }
  }

  cout << res << endl;

  return 0;
}

Error: TLE

Fixed submission:

#define _USE_MATH_DEFINES
#include <algorithm>
#include <cmath>
#include <deque>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;

int main() {

  string str;
  cin >> str;

  int res = 0;
  for (int i = str.length() / 3; i >= 0; i--) {
    string sub = "";
    for (int k = 0; k < i; k++)
      sub += "J";
    for (int k = 0; k < i; k++)
      sub += "O";
    for (int k = 0; k < i; k++)
      sub += "I";
    if (str.find(sub) != string::npos) {
      res = i;
      break;
    }
  }
  cout << res << endl;

  return 0;
}
Problem p00494 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef pair<int, int> P;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-9
#define INF 2000000000
#define sz(x) ((int)(x).size())
#define fi first
#define sec second
#define SORT(x) sort((x).begin(), (x).end())
#define all(x) (x).begin(), (x).end()
#define EQ(a, b) (abs((a) - (b)) < EPS)
int main() {
  string s;
  cin >> s;
  vector<char> c;
  vector<int> r;
  int k = 1;
  for (int i = 1; i < s.size(); i++) {
    if (s[i - 1] == s[i])
      k++;
    else {
      if (s[i - 1] == 'J')
        c.pb('J');
      if (s[i - 1] == 'O')
        c.pb('O');
      if (s[i - 1] == 'I')
        c.pb('I');
      r.pb(k);
      k = 1;
    }
  }
  if (s[s.size() - 1] == 'J')
    c.pb('J');
  if (s[s.size() - 1] == 'O')
    c.pb('O');
  if (s[s.size() - 1] == 'I')
    c.pb('I');
  r.pb(k);
  int ans = 0;
  for (int i = 1; i < r.size() - 1; i++) {
    int res = 0;
    if (c[i] == 'O' && c[i - 1] == 'J' && c[i + 1] == 'I') {
      if (r[i - 1] >= r[i] && r[i] <= r[i + 1])
        res = r[i];
    }
    ans = max(ans, res);
  }
  cout << ans << endl;
  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef pair<int, int> P;
typedef long long ll;
typedef long long ull;
typedef vector<int> vi;
typedef vector<ll> vll;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-9
#define INF 2000000000
#define sz(x) ((int)(x).size())
#define fi first
#define sec second
#define SORT(x) sort((x).begin(), (x).end())
#define all(x) (x).begin(), (x).end()
#define EQ(a, b) (abs((a) - (b)) < EPS)
const ull B = 100000007;
int sl;
string s;
bool C(int p) {
  string str;
  for (int i = 0; i < p; i++)
    str += 'J';
  for (int i = 0; i < p; i++)
    str += 'O';
  for (int i = 0; i < p; i++)
    str += 'I';
  int len = p * 3;
  if (len > sl)
    return false;
  ull t = 1;
  for (int i = 0; i < len; i++) {
    t *= B;
  }
  ull h = 0, sh = 0;
  for (int i = 0; i < len; i++) {
    h = h * B + str[i];
    sh = sh * B + s[i];
  }
  for (int i = 0; i + len <= sl; i++) {
    if (h == sh)
      return true;
    if (i + len < sl)
      sh = sh * B + s[i + len] - t * s[i];
  }
  return false;
}
int main() {
  cin >> s;
  sl = s.size();
  int st = sl / 3;
  for (; st > 0; st--) {
    if (C(st))
      break;
  }
  cout << st << endl;
  return 0;
}
Problem p00494 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <cstdio>
#include <cstring>
using namespace std;
#define loop(i, a, b) for (int i = a; i < int(b); i++)
#define rep(i, b) loop(i, 0, b)

char s[1000100];
int l[1000100];
int main() {
  scanf("%s", s);
  int n = strlen(s);
  l[0] = 1;
  rep(i, n - 1) {
    if (s[i + 1] == s[i])
      l[i + 1] = l[i] + 1;
    else
      l[i + 1] = 1;
  }
  int ans = 0;
  loop(i, 1, n - 1) {
    if (s[i] == 'O' && s[i + 1] != 'O' && i + l[i] < n && i - l[i] >= 0 &&
        l[i + l[i]] >= l[i] && l[i - l[i]] >= l[i] && s[i + l[i]] == 'I' &&
        s[i - l[i]] == 'J') {
      ans = max(ans, l[i]);
    }
  }
  printf("%d\\n", ans);
}

Error: 0

Fixed submission:

#include <algorithm>
#include <cstdio>
#include <cstring>
using namespace std;
#define loop(i, a, b) for (int i = a; i < int(b); i++)
#define rep(i, b) loop(i, 0, b)

char s[100010];
int l[100010];
int main() {
  scanf("%s", s);
  int n = strlen(s);
  l[0] = 1;
  rep(i, n - 1) {
    if (s[i + 1] == s[i])
      l[i + 1] = l[i] + 1;
    else
      l[i + 1] = 1;
  }
  int ans = 0;
  loop(i, 1, n - 1) {
    if (s[i] == 'O' && s[i + 1] != 'O' && i + l[i] < n && i - l[i] >= 0 &&
        l[i + l[i]] >= l[i] && l[i - l[i]] >= l[i] && s[i + l[i]] == 'I' &&
        s[i - l[i]] == 'J') {
      ans = max(ans, l[i]);
    }
  }
  printf("%d\\n", ans);
}
Problem p00494 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
#include <string>

using namespace std;

void solve() {
  string s;
  cin >> s;
  int max_level = 0;
  for (int i = 0; i < s.size(); ++i) {
    if (s[i] == 'J') {
      int countJ = 1;
      int pos = i + 1;
      while (pos < s.size() && s[pos] == 'J') {
        ++pos;
        ++countJ;
      }
      if (countJ <= max_level) {
        i = pos - 1;
        continue;
      }
      int countO = 0;
      while (pos < s.size() && s[pos] == 'O') {
        ++pos;
        ++countO;
      }
      if (countJ < countO || countO <= max_level) {
        i = pos - 1;
        continue;
      }
      int countI = 0;
      while (pos < s.size() && s[pos] == 'I') {
        ++pos;
        ++countI;
      }
      i = pos - 1;
      if (countI >= countO) {
        max_level = countO;
      }
    }
  }
  cout << max_level << endl;
}

int main() {
  solve();
  return (0);
}

Error: TLE

Fixed submission:

#include <iostream>
#include <string>

using namespace std;

void solve() {
  string s;
  cin >> s;
  int max_level = 0;
  for (int i = 0; i < s.size(); ++i) {
    if (s[i] == 'O') {
      int level = 1;
      int pos = i + 1;
      while (s[pos] == 'O') {
        ++pos;
        ++level;
      }
      if (level <= max_level) {
        i = pos + 1;
        continue;
      }
      bool flag = true;
      int end = 0;
      for (int j = 0; j < level; ++j) {
        end = j + pos;
        if (j + pos >= s.size() || s[j + pos] != 'I') {
          flag = false;
          break;
        }
      }
      if (!flag) {
        continue;
      }
      pos = i - 1;
      for (int j = 0; j < level; ++j) {
        if (pos - j < 0 || s[pos - j] != 'J') {
          flag = false;
          break;
        }
      }
      i = end;
      if (flag) {
        if (max_level < level) {
          max_level = level;
        }
      }
    }
  }
  cout << max_level << endl;
}

int main() {
  solve();
  return (0);
}
Problem p00494 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cstdio>
#include <cstring>

using namespace std;

const int MAX_N = 1000000;

char S[MAX_N];

int main() {
  scanf("%s", S);
  int cnt_j = 0, cnt_o = 0, cnt_i = 0; // J????????°
  int ma = 0;
  int i = 0;
  int n = strlen(S);
  while (i < n) {
    while (i < n && S[i] != 'J')
      i++;
    cnt_j = 0;
    while (i < n && S[i] == 'J') {
      i++;
      cnt_j++;
    }
    if (cnt_j <= ma) {
      //??°?¨?????????´??°??§?????????????????????
      continue;
    }
    cnt_o = 0;
    while (i < n && S[i] == 'O') {
      cnt_o++;
      i++;
    }
    if (cnt_j < cnt_o) {
      continue;
    }
    cnt_i = 0;
    while (i < n && S[i] == 'I') {
      cnt_i++;
      i++;
    }
    if (cnt_i >= cnt_o) {
      ma = max(ma, cnt_o);
    }
  }
  printf("%d\\n", ma);
  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
using namespace std;
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <functional> //sort(A,A.end(),greater<int>());???????????????
#include <queue>
#include <stack>
#include <string>
#include <vector>

#define INF 10 << 10

int main() {
  string str;
  string J, O, I;
  string temp[3] = {"J", "O", "I"};
  bool flg = true;

  cin >> str;
  int k = str.size() / 3;
  for (int i2 = 0; i2 < k; ++i2) {
    J += temp[0];
    O += temp[1];
    I += temp[2];
  }
  for (k = str.size() / 3; k > 0; --k) {
    string JOI = J + O + I;
    if (str.find(JOI) != -1) {
      flg = false;
      cout << k << endl;
      break;
    }
    J.erase(J.begin() + J.size() - 1);
    O.erase(O.begin() + O.size() - 1);
    I.erase(I.begin() + I.size() - 1);
  }
  if (flg)
    cout << "0" << endl;

  return 0;
}
Problem p00494 (C++) — buggy submission, verdict: Time Limit Exceeded

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

char a[1000000];
int b;
int g = 0;
struct JOI {
  int J, O, I;
};
JOI c(int d) {
  JOI e;
  e.J = e.O = e.I = 0;
  int f;
  for (f = d; f < b; f++) {
    if (a[f] != 'J')
      break;
  }
  e.J = f - d;
  d = f;
  for (f = d; f < b; f++) {
    if (a[f] != 'O')
      break;
  }
  e.O = f - d;
  d = f;
  for (f = d; f < b; f++) {
    if (a[f] != 'I')
      break;
  }
  e.I = f - d;
  g = f - 1;
  return e;
}
int main() {
  scanf("%s", a);
  b = strlen(a);
  int MAX = 0;
  for (; g < b; g++) {
    if (a[g] == 'J') {
      JOI s = c(g);
      if (s.O <= s.I && s.O <= s.J)
        MAX = max(MAX, s.O);
    }
  }
  cout << MAX << endl;
}

Error: TLE

Fixed submission:

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

char a[1000000];
int b;
int g = 0;
struct JOI {
  int J, O, I;
};
JOI c(int d) {
  JOI e;
  e.J = e.O = e.I = 0;
  int f;
  for (f = d; f < b; f++) {
    if (a[f] != 'J')
      break;
  }
  e.J = f - d;
  d = f;
  for (f = d; f < b; f++) {
    if (a[f] != 'O')
      break;
  }
  e.O = f - d;
  d = f;
  for (f = d; f < b; f++) {
    if (a[f] != 'I')
      break;
  }
  e.I = f - d;
  return e;
}
int main() {
  scanf("%s", a);
  b = strlen(a);
  int MAX = 0;
  for (; g < b; g++) {
    if (a[g] == 'J') {
      JOI s = c(g);
      if (s.O <= s.I && s.O <= s.J)
        MAX = max(MAX, s.O);
    }
  }
  cout << MAX << endl;
}
Problem p00494 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <map>
#include <string>
#include <vector>
using namespace std;

const int MAX = 10000100;

#define loop(i, a, b) for (int i = a; i < b; i++)
#define rep(i, a) loop(i, 0, a)
#define all(a) (a).begin(), (a).end()
#define ll long long int
#define gcd(a, b) __gcd(a, b)

int GCD(int a, int b) {
  if (!b)
    return a;
  return gcd(b, a % b);
}
int lcm(int a, int b) { return a * b / gcd(a, b); }

int main(void) {
  string in;
  int res = 0;
  int J, O, I;
  cin >> in;
  rep(i, in.size()) {
    if (in[i] != 'J')
      continue;
    for (J = 0; in[i] == 'J'; i++)
      J++;
    for (O = 0; in[i] == 'O'; i++)
      O++;
    if (in[i] == 'J') {
      i--;
      continue;
    }
    for (I = 0; in[i] == 'I'; i++)
      I++;
    if (J >= O && I >= O)
      res = max(res, O);
    if (in[i] == 'J') {
      i--;
      continue;
    }
  }
  cout << res << endl;
}

Error: WA

Fixed submission:

#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <map>
#include <string>
#include <vector>
using namespace std;

const int MAX = 10000100;

#define loop(i, a, b) for (int i = a; i < b; i++)
#define rep(i, a) loop(i, 0, a)
#define all(a) (a).begin(), (a).end()
#define ll long long int
#define gcd(a, b) __gcd(a, b)

int GCD(int a, int b) {
  if (!b)
    return a;
  return gcd(b, a % b);
}
int lcm(int a, int b) { return a * b / gcd(a, b); }

int main(void) {
  string in;
  int res = 0;
  int J, O, I;
  cin >> in;
  rep(i, in.size()) {
    for (J = 0; in[i] != 'J'; i++)
      J++;
    for (O = 0; in[i] != 'O'; i++)
      O++;
    if (in[i] == 'J') {
      i--;
      continue;
    }
    for (I = 0; in[i] != 'I'; i++)
      I++;
    if (J >= O && O >= I) {
      res = max(res, I);
    }
    if (in[i]) {
      i--;
      continue;
    }
  }
}
Problem p00494 (C++) — buggy submission, verdict: Time Limit Exceeded

#include "stdio.h"
#include "string.h"

char s[1111111];

int main() {
  scanf("%s", s);
  char c = 'w';
  int k = 0;
  int nk = 0;
  char o;
  int n = 0;
  for (int i = 0; i < strlen(s); i++) {
    o = c;
    c = s[i];
    if (c == o) {
      n++;
    } else {
      if (c == 'J') {
        nk = 0;
        n = 1;
      }
      if (c == 'O') {
        if (o == 'J') {
          nk = n;
          n = 1;
        } else {
          nk = 0;
        }
      }
      if (c == 'I') {
        if (o == 'O' && nk >= n) {
          nk = n;
          n = 1;
        } else {
          nk = 0;
        }
      }
    }
    if (c == 'I' && nk <= n && k < nk) {
      k = nk;
    }
  }
  printf("%d\\n", k);
  return 0;
}

Error: TLE

Fixed submission:

#include "stdio.h"

int main() {
  char c = 'w';
  int k = 0;
  int nk = 0;
  char o;
  int n = 0;
  while (1) {
    o = c;
    c = getchar();
    if (c == '\\0') {
      break;
    }
    if (c == o) {
      n++;
    } else {
      if (c == 'J') {
        nk = 0;
        n = 1;
      }
      if (c == 'O') {
        if (o == 'J') {
          nk = n;
          n = 1;
        } else {
          nk = 0;
        }
      }
      if (c == 'I') {
        if (o == 'O' && nk >= n) {
          nk = n;
          n = 1;
        } else {
          nk = 0;
        }
      }
    }
    if (o == 'I' && nk >= n && k < nk) {
      k = nk;
    }
  }
  printf("%d\\n", k);
  return 0;
}
Problem p00494 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cstdio>
#include <cstring>
#include <string>
using namespace std;
char x[1000005];
int a = 0, b = 0, c = 0, d = 0, e, f, i, j, k, maxi = 0;
int main() {
  fill(x, x + 1000005, 'A');
  scanf("%s", x);
  int leng = strlen(x);
  while (1) {
    if (a == leng) {
      break;
    }
    if (x[a] != 'J') {
      a++;
    } else {
      while (1) {
        if (x[a] == 'J') {
          b++;
          a++;
        } else {
          break;
        }
      }
      while (1) {
        if (x[a] == 'O') {
          c++;
          a++;
        } else {
          break;
        }
      }
      while (1) {
        if (x[a] == 'I') {
          d++;
          a++;
        } else {
          break;
        }
      }
      if (b >= c && c <= d) {
        maxi = max(maxi, c);
      }
      b = 0;
      c = 0;
      d = 0;
    }
  }
  printf("%d\\n", maxi);
  scanf("%d", &a);
  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cstdio>
#include <cstring>
using namespace std;
char x[1000001];
int a = 0, b = 0, c = 0, d = 0, e, f, i, j, k, maxi = 0;
int main() {
  scanf("%s", x);
  while (1) {
    if (a == strlen(x)) {
      break;
    }
    if (x[a] == 'O' || x[a] == 'I') {
      a++;
      continue;
    }
    if (x[a] == 'J') {
      while (1) {
        if (x[a] == 'J') {
          b++;
          a++;
        } else {
          break;
        }
      }
      while (1) {
        if (x[a] == 'O') {
          c++;
          a++;
        } else {
          break;
        }
      }
      while (1) {
        if (x[a] == 'I') {
          d++;
          a++;
        } else {
          break;
        }
      }
      if (b >= c && c <= d) {
        maxi = max(maxi, c);
      }
      b = 0;
      c = 0;
      d = 0;
    }
  }
  printf("%d\\n", maxi);
  return 0;
}
Problem p00494 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <cstdio>
#include <cstring>
#include <vector>
using namespace std;
char str[1000005];
int main() {
  scanf("%s", &str);
  int leng = strlen(str);
  int ans = 0, i = 0;
  for (;;) {
    if (str[i] == 'J') {
      int a = 0, b = 0, c = 0;
      while (str[i] == 'J' && i < leng) {
        i++;
        a++;
      }
      while (str[i] == 'O' && i < leng) {
        i++;
        b++;
      }

      while (str[i] == 'I' && i < leng) {
        i++;
        c++;
      }
      if (b <= a && b <= c) {
        ans = max(ans, b);
      }
      if (i == leng)
        break;
    } else {
      i++;
      if (i == leng)
        break;
    }
  }

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

Error: 0

Fixed submission:

#include <algorithm>
#include <cstdio>
#include <cstring>
#include <vector>
using namespace std;
char str[1000005];
int main() {
  scanf("%s", &str);
  int leng = strlen(str);
  int ans = 0, i = 0;
  for (;;) {
    if (str[i] == 'J') {
      int a = 0, b = 0, c = 0;
      while (str[i] == 'J' && i < leng) {
        i++;
        a++;
      }
      while (str[i] == 'O' && i < leng) {
        i++;
        b++;
      }

      while (str[i] == 'I' && i < leng) {
        i++;
        c++;
      }
      if (b <= a && b <= c) {
        ans = max(ans, b);
      }
      if (i == leng)
        break;
    } else {
      i++;
    }
  }

  printf("%d\\n", ans);
  return 0;
}
Problem p00494 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <cstdio>
#include <iostream>
#include <string>

using namespace std;

string s;
int index = 0, ci = 0;
int ans = 0;
int c[2000000];

int main() {

  cin >> s;
  while (index < s.length()) {
    for (int i = 0; i < 3; i++) {
      char ct;
      if (i == 0)
        ct = 'J';
      else if (i == 1)
        ct = 'O';
      else if (i == 2)
        ct = 'I';
      int cnt;
      for (cnt = 0; ct == s[index + cnt]; cnt++)
        ;
      index += cnt;
      c[ci] = cnt;
      ci++;
    }
  }
  // Oを探索
  for (int i = 1; i < ci; i += 3) {
    int oi = c[i];
    int ji = c[i - 1];
    int ii = c[i + 1];
    if (oi > ji || oi > ii)
      continue;
    else if (ans < oi)
      ans = oi;
  }

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

Error: 0

Fixed submission:

#include <algorithm>
#include <cstdio>
#include <iostream>
#include <string>

using namespace std;

string s;
int index = 0, ci = 0;
int ans = 0;
int c[200001];

int main() {

  cin >> s;
  while (index < s.length()) {
    for (int i = 0; i < 3; i++) {
      char ct;
      if (i == 0)
        ct = 'J';
      else if (i == 1)
        ct = 'O';
      else if (i == 2)
        ct = 'I';
      int cnt;
      for (cnt = 0; ct == s[index + cnt]; cnt++)
        ;
      index += cnt;
      c[ci] = cnt;
      ci++;
    }
  }
  // Oを探索
  for (int i = 1; i < ci; i += 3) {
    int oi = c[i];
    int ji = c[i - 1];
    int ii = c[i + 1];
    if (oi > ji || oi > ii)
      continue;
    else if (ans < oi)
      ans = oi;
  }

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