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

#include <algorithm>
#include <climits>
#include <cstdio>
#include <iostream>
#include <string>
using namespace std;
void init(int *cnt) {
  for (int i = 0; i < 3; i++)
    cnt[i] = 0;
}
int me(int *cnt) {
  int res = INT_MAX;
  for (int i = 0; i < 3; i++)
    res = min(res, cnt[i]);
  return res;
}
bool isok(int *cnt) {
  if (cnt[0] >= cnt[1] && cnt[1] <= cnt[2])
    return true;
  return false;
}
int cnt[3];
int main() {
  string in;
  cin >> in;
  int res = 0;
  char flag = '*';
  for (int i = 0; i < in.length(); i++) {
    if (flag == '*' && in[i] == 'J') { // J task start
      init(cnt);
      flag = 'J';
      cnt[0]++;
    } else if (flag == 'I' && in[i] == 'J') {
      if (isok(cnt))
        res = max(res, me(cnt));
      flag = 'J';
      init(cnt);
      cnt[0]++;
    } else if (flag == 'J' && in[i] == 'J') {
      flag = 'J';
      cnt[0]++;
    } else if (flag == 'O' && in[i] == 'J') { // J task end
      flag = 'J';
      init(cnt);
      cnt[0]++;
    } else if (flag == 'J' && in[i] == 'O') { // O task start
      flag = 'O';
      cnt[1]++;
    } else if (flag == 'O' && in[i] == 'O') {
      flag = 'O';
      cnt[1]++;
    } else if (flag == 'I' && in[i] == 'O') { // O task end
      if (isok(cnt))
        res = max(res, me(cnt));
      flag = '*';
    } else if (flag == 'O' && in[i] == 'I') { // I task start
      flag = 'I';
      cnt[2]++;
    } else if (flag == 'I' && in[i] == 'I') {
      flag = 'I';
      cnt[2]++;
    } else if (flag == 'J' && in[i] == 'I') { // I task end
      flag = '*';
    }
    // for (int j=0; j<3; j++) printf("%d%c",cnt[j],j==2?'\\n':' ');
  }
  if (flag == 'I' && isok(cnt))
    res = max(res, me(cnt));
  printf("%d\\n", res);
}

Error: 0

Fixed submission:

#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <vector>
using namespace std;
int main() {
  string str;
  cin >> str;
  vector<pair<char, int>> res;
  char bef = '*';
  int cnt = 0;
  for (int i = 0; i < str.length(); i++) {
    if (bef == str[i]) {
      cnt++;
    } else {
      if (bef != '*')
        res.push_back(make_pair(bef, cnt));
      bef = str[i];
      cnt = 1;
    }
  }
  if (bef != '*')
    res.push_back(make_pair(bef, cnt));
  int rnum = 0;
  for (int i = 0; i < res.size() - 2; i++) {
    // cout<<res[i].first<<endl;
    if (res[i].first = 'J') {
      if (res[i + 1].first == 'O' && res[i + 2].first == 'I' &&
          res[i].second >= res[i + 1].second &&
          res[i + 1].second <= res[i + 2].second) {
        rnum = max(rnum, res[i + 1].second);
      }
    }
  }
  printf("%d\\n", rnum);
}
Problem p00494 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <iostream>
#include <vector>

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

using namespace std;

typedef pair<char, int> P;

string s;
vector<P> x;

int main() {
  cin >> s;
  rep(i, s.size()) {
    if (x.empty() || x.back().first != s[i]) {
      x.push_back(P(s[i], 1));
    } else {
      ++x.back().second;
    }
  }
  int ans = 0;
  rep(i, (int)x.size() - 2) {
    P &a = x[i];
    P &b = x[i + 1];
    P &c = x[i + 2];
    if (a.first == 'J' && b.first == 'O' && c.first == 'I') {
      if (a.second >= b.second && c.second >= b.second) {
        ans = max(b.second, ans);
      }
    }
  }
  cout << ans << endl;
  return 0;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <iostream>
#include <vector>

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

using namespace std;

typedef pair<char, int> P;

string s;
vector<P> x;

int main() {
  cin >> s;
  rep(i, s.size()) {
    if (x.empty() || x.back().first != s[i]) {
      x.push_back(P(s[i], 1));
    } else {
      ++x.back().second;
    }
  }
  int ans = 0;
  rep(i, x.size() - 2) {
    if (x[i].first == 'J' && x[i + 1].first == 'O' && x[i + 2].first == 'I') {
      ans = max(min(x[i].second, min(x[i + 1].second, x[i + 2].second)), ans);
    }
  }
  cout << ans << endl;
  return 0;
}
Problem p00494 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <iostream>
#include <string>
#include <vector>

using namespace std;

int main() {
  string str;
  int ret = 0;
  vector<pair<char, int>> v;
  cin >> str;

  int cnt = 1;
  char tmp = str[0];
  for (int i = 1; i < str.size(); ++i) {
    if (str[i] == tmp) {
      cnt++;
    } else {
      v.push_back(make_pair(tmp, cnt));
      cnt = 1;
      tmp = str[i];
    }
  }
  v.push_back(make_pair(tmp, cnt));
  for (int i = 0; v.size() >= 3 && i < v.size() - 2; ++i) {
    if (v[i].first == 'J' && v[i + 1].first == 'O' && v[i + 2].first == 'I') {
      if (v[i].second >= v[i + 1].second &&
          v[i + 2].second >= v[i + 1].second) {
        ret = max(ret, min(v[i].second, min(v[i + 1].second, v[i + 2].second)));
      }
    }
  }
  cout << ret << endl;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <iostream>
#include <string>
#include <vector>

using namespace std;

int main() {
  string str;
  int ret = 0;
  vector<pair<char, int>> v;
  cin >> str;

  int cnt = 1;
  char tmp = str[0];
  for (int i = 1; i < str.size(); ++i) {
    if (str[i] == tmp) {
      cnt++;
    } else {
      v.push_back(make_pair(tmp, cnt));
      cnt = 1;
      tmp = str[i];
    }
  }
  v.push_back(make_pair(tmp, cnt));
  for (int i = 0; i < v.size() - 2; ++i) {
    if (v[i].first == 'J' && v[i + 1].first == 'O' && v[i + 2].first == 'I') {
      ret = max(ret, min(v[i].second, min(v[i + 1].second, v[i + 2].second)));
    }
  }
  cout << ret << endl;
}
Problem p00494 (C++) — buggy submission, verdict: Time Limit Exceeded

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

using namespace std;

int main(void) {
  char s[2000000];
  int l = 0, len, n = 0, f;
  scanf("%s", s);
  len = strlen(s);
  for (int i = 0; i < len; i++) {
    if (s[i] == 'O') {
      f = 1;
      int j = 1, m = n;
      for (; j < n; j++) {
        if (s[j + i] != 'O') {
          m = j;
          break;
        }
      }
      // printf("n=%d j=%d i=%d m=%d\\n",n,j,i,m);
      i += max(--j, 0);
      for (j = 1; j <= m; j++) {
        if (s[j + i] != 'I') {
          f = 0;
          break;
        }
      }
      // puts("r");
      // printf("n=%d k=%d i=%d f=%d\\n",n,k,i,f);
      if (f > 0) {
        i += max(j - 1, 0);
        l = max(l, m);
      }
    }
    if (s[i] == 'J') {
      n++;
    } else
      n = 0;
  }
  printf("%d\\n", l);
  return 0;
}

Error: TLE

Fixed submission:

#include <cstdio>
#include <cstring>

using namespace std;

int main(void) {
  char s[1000001];
  char joi[1000001];
  char d[4] = "JOI";
  int l = 0, len;
  scanf("%s", s);
  len = strlen(s) / 3;
  for (int i = 1; i <= len; i++) {
    int n = 0;
    for (int j = 0; j < 3; j++) {
      for (int k = 0; k < i; k++)
        joi[n++] = d[j];
    }
    if (strstr(s, joi) != NULL)
      l = i;
  }
  printf("%d\\n", l);
  return 0;
}
Problem p00494 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
#define rep(i, a, n) for (int i = a; i < n; i++)
#define repb(i, a, b) for (int i = a; i >= b; i--)
#define all(a) a.begin(), a.end()
#define o(a) cout << a << endl
// #define int long long
#define fi first
#define se second
using namespace std;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> pii;

signed main() {
  string s, t = "JOI";
  cin >> s;
  s += 'X';
  int ans = 0, f = -1, now = 0, pre = 0;
  rep(i, 0, s.size()) {
    if (s[i] == t[f]) {
      now++;
    } else if (f == 0 && s[i] == t[1]) {
      pre = now;
      now = 1;
      f = 1;
    } else if (f == 1 && s[i] == t[2]) {
      if (pre < now) {
        f = -1;
      } else {
        f++;
        pre = now;
        now = 1;
      }
    } else if (f == 2 && s[i] != t[2]) {
      if (pre <= now)
        ans = max(ans, pre);
      f = -1;
    } else {
      f = -1;
    }
    if (f == -1 && s[i] == 'J') {
      f = 0;
      now = 1;
    }
  }
  cout << ans << endl;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define rep(i, a, n) for (int i = a; i < n; i++)
#define repb(i, a, b) for (int i = a; i >= b; i--)
#define all(a) a.begin(), a.end()
#define o(a) cout << a << endl
// #define int long long
#define fi first
#define se second
using namespace std;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> pii;

string s, J, O, I;

bool check(int m, string t) {
  if (s.size() < t.size())
    return false;
  if (s.find(t) != string::npos)
    return true;
  return false;
}

signed main() {
  cin >> s;
  int ans = 0;
  rep(i, 1, (int)(s.size()) / 3 + 2) {
    string t;
    J += 'J';
    O += 'O';
    I += 'I';
    t = J + O + I;
    // o(t);
    if (check(i, t)) {
      ans = i;
    }
  }
  cout << ans << endl;
}
Problem p00494 (C++) — buggy submission, verdict: Time Limit Exceeded

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

using namespace std;

string S;

int main() {
  cin >> S;
  int res = 0;
  for (int i = 0; i < S.size(); i++) {
    if (S[i] != 'J')
      continue;
    int jc, oc, ic;
    jc = oc = ic = 0;
    int j;
    for (j = i; j < S.size(); j++) {
      if (S[j] != 'J')
        break;
      jc++;
    }
    //    if(S[j]!='O') continue;
    for (; j < S.size(); j++) {
      if (S[j] != 'O')
        break;
      oc++;
    }
    for (; j < S.size(); j++) {
      if (S[j] != 'I')
        break;
      ic++;
    }
    //    res = max(res, min(jc, min(oc,ic)));
    if (oc <= ic && oc <= jc)
      res = max(res, oc);
    i = j - 1;
  }

  cout << res << endl;
}

Error: TLE

Fixed submission:

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

using namespace std;

string S;

int main() {
  cin >> S;
  int res = 0;
  for (int i = 0; i < S.size(); i++) {
    if (S[i] != 'J')
      continue;
    int jc, oc, ic;
    jc = oc = ic = 0;
    int j;
    for (j = i; j < S.size(); j++) {
      if (S[j] != 'J')
        break;
      jc++;
    }
    //    if(S[j]!='O') continue;
    for (; j < S.size(); j++) {
      if (S[j] != 'O')
        break;
      oc++;
    }
    for (; j < S.size(); j++) {
      if (S[j] != 'I')
        break;
      ic++;
    }
    //    res = max(res, min(jc, min(oc,ic)));
    if (oc <= ic && oc <= jc)
      res = max(res, oc);
  }

  cout << res << endl;
}
Problem p00494 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

using namespace std;

#define rep(i, j) REP((i), 0, (j))
#define REP(i, j, k) for (i = (j); (i) < (k); ++i)
#define BW(a, x, b) ((a) <= (x) && (x) <= (b))
#define ALL(v) (v).begin(), (v).end()
#define LENGTHOF(x) (sizeof(x) / sizeof(*(x)))
#define AFILL(a, b) fill((int *)a, (int *)(a + LENGTHOF(a)), b)
#define MP make_pair
#define PB push_back
#define F first
#define S second
#define INF 1 << 30
#define EPS 1e-10

typedef pair<int, int> pi;
typedef pair<int, pi> pii;
typedef vector<int> vi;
typedef queue<int> qi;
typedef long long ll;

char s[1000001];

int main() {

  fgets(s, sizeof(s), stdin);
  int res = 0, oc, ic, jc;
  int i, j, k, l;
  int slen = strlen(s);
  jc = oc = ic = 0;
  rep(i, slen) {
    if (ic == 0 && oc == 0 && s[i] == 'J')
      jc++;
    else if (jc && ic == 0 && s[i] == 'O')
      oc++;
    else if (jc && oc && s[i] == 'I')
      ic++;
    else {
      if (jc >= oc && ic >= oc)
        res = max(res, oc);
      jc = oc = ic = 0;
      if (s[i] == 'J')
        jc++;
    }
  }

  if (jc >= oc && ic >= oc)
    res = max(res, oc);
  printf("%d\\n", res);
  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

using namespace std;

#define rep(i, j) REP((i), 0, (j))
#define REP(i, j, k) for (i = (j); (i) < (k); ++i)
#define BW(a, x, b) ((a) <= (x) && (x) <= (b))
#define ALL(v) (v).begin(), (v).end()
#define LENGTHOF(x) (sizeof(x) / sizeof(*(x)))
#define AFILL(a, b) fill((int *)a, (int *)(a + LENGTHOF(a)), b)
#define MP make_pair
#define PB push_back
#define F first
#define S second
#define INF 1 << 30
#define EPS 1e-10

typedef pair<int, int> pi;
typedef pair<int, pi> pii;
typedef vector<int> vi;
typedef queue<int> qi;
typedef long long ll;

char s[1000001];

int main() {

  fgets(s, sizeof(s), stdin);
  int res = 0, oc, ic, jc;
  int i, j, k, l;
  int slen = strlen(s);
  jc = oc = ic = 0;
  rep(i, slen) {
    if (ic == 0 && oc == 0 && s[i] == 'J')
      jc++;
    else if (jc && ic == 0 && s[i] == 'O')
      oc++;
    else if (jc && oc && s[i] == 'I')
      ic++;
    else {
      if (jc >= oc && ic >= oc)
        res = max(res, oc);
      jc = oc = ic = 0;
      i--;
    }
  }

  if (jc >= oc && ic >= oc)
    res = max(res, oc);
  printf("%d\\n", res);
  return 0;
}
Problem p00494 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <cstring>
#include <iostream>
#include <vector>
using namespace std;

typedef pair<int, int> pii;

int main() {
  char s[1000001];
  vector<pii> v;
  cin >> s;
  int l = strlen(s);
  int cnt = 0;
  int x;
  for (int i = 0; i < l; i++) {
    if (i > 0 && s[i] != s[i - 1]) {
      v.push_back(pii(x, cnt));
      cnt = 0;
    }
    switch (s[i]) {
    case 'J':
      x = 0;
      break;
    case 'O':
      x = 1;
      break;
    case 'I':
      x = 2;
      break;
    }
    cnt++;
  }
  v.push_back(pii(x, cnt));
  int ans = 0;
  for (int i = 0; i < (int)v.size() - 2; i++) {
    if (i < (int)v.size() - 2 && v[i].first == 0 && v[i + 1].first == 1 &&
        v[i + 2].first == 2 && v[i].second >= v[i + 1].second &&
        v[i + 1].second <= v[i + 2].second) {
      ans = max(ans, v[i + 1].second);
    }
  }
  cout << ans << endl;
  return 0;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <cstring>
#include <iostream>
#include <vector>
using namespace std;

typedef pair<int, int> pii;

int main() {
  char s[1000001];
  vector<pii> v;
  cin >> s;
  int l = strlen(s);
  int cnt = 0;
  int x;
  for (int i = 0; i < l; i++) {
    if (i > 0 && s[i] != s[i - 1]) {
      v.push_back(pii(x, cnt));
      cnt = 0;
    }
    switch (s[i]) {
    case 'J':
      x = 0;
      break;
    case 'O':
      x = 1;
      break;
    case 'I':
      x = 2;
      break;
    }
    cnt++;
  }
  v.push_back(pii(x, cnt));
  int ans = 0;
  for (int i = 0; i < v.size() - 2; i++) {
    if (v[i].first == 0 && v[i + 1].first == 1 && v[i + 2].first == 2 &&
        v[i].second >= v[i + 1].second && v[i + 1].second <= v[i + 2].second) {
      ans = max(ans, v[i + 1].second);
    }
  }
  cout << ans << endl;
  return 0;
}
Problem p00494 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
#define range(i, a, b) for (int i = (a); i < (b); i++)
#define rep(i, a) range(i, 0, a)
using namespace std;

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

  vector<pair<char, int>> ci;
  rep(i, s.size()) {
    if ((i == 0) || (i != 0 && s[i] != s[i - 1]))
      ci.emplace_back(s[i], 1);
    else
      ci.back().second++;
  }

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

  return 0;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>
#define range(i, a, b) for (int i = (a); i < (b); i++)
#define rep(i, a) range(i, 0, a)
using namespace std;

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

  vector<pair<char, int>> ci;
  rep(i, s.size()) {
    if ((i == 0) || (i != 0 && s[i] != s[i - 1]))
      ci.emplace_back(s[i], 1);
    else
      ci.back().second++;
  }

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

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

#include <algorithm>
#include <iostream>
#include <string>
using namespace std;
int J = 0, O = 0, I = 0;
void res() {
  J = 0;
  O = 0;
  I = 0;
}
int main() {
  string a;
  cin >> a;
  int ans = 0;

  for (int i = 0; i < a.size(); i++) {
    switch (a[i]) {
    case 'J':
      if (O != 0 || I != 0) {
        res();
        J++;
      } else {
        J++;
      }
      break;
    case 'O':
      if (J == 0 || I != 0) {
        res();
        continue;
      } else {
        O++;
        if (O > J) {
          res();
        }
      }

      break;
    case 'I':
      I++;
      if (O < I || J < I) {
        res();
      }
      if (I == O)
        ans = max(ans, I);
      break;
    }
    //	cout << ans << endl;
  }
  cout << ans << endl;
}

Error: TLE

Fixed submission:

#include <iostream>
#include <string>
using namespace std;

int main() {
  string a;
  cin >> a;
  string j, o, i;
  j.append(a.size() / 3 + 1, 'J');
  o.append(a.size() / 3 + 1, 'O');
  i.append(a.size() / 3 + 1, 'I');
  string joi;
  int ans = a.size() / 3 + 1;
  while (!j.empty()) {
    joi = j + o + i;
    if (a.find(joi) != string::npos) {
      cout << ans << endl;
      return 0;
    };
    j.erase(j.size() - 1);
    i.erase(i.size() - 1);
    o.erase(o.size() - 1);
    ans--;
  }
  //	cout << ans<<endl;
  cout << "0" << endl;
}
Problem p00494 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
#include <string.h>
using namespace std;
int main() {
  char joi[1000001];
  int ans = 0;
  cin >> joi;
  for (char *p = joi; *p != 0;) {
    char joi_c[3] = {'J', 'O', 'I'};
    int cnt[3] = {0};
    for (int j = 0; j < 3; j++) {
      while (*p == joi_c[j] && *p != 0) {
        cnt[j]++;
        *p++;
      }
    }
    if (cnt[0] >= cnt[1] && cnt[1] <= cnt[2])
      ans = max(cnt[1], ans);
  }
  cout << ans << endl;
  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
#include <string.h>
using namespace std;
int main() {
  char joi[1000001];
  int ans = 0;
  cin >> joi;
  for (int i = 0;; i++) {
    if (i >= strlen(joi))
      break;
    if (joi[i] == 'J') {
      char joi_c[3] = {'J', 'O', 'I'};
      int cnt[3] = {0};
      for (int j = 0; j < 3; j++) {
        while (joi[i] == joi_c[j] && i <= strlen(joi)) {
          cnt[j]++;
          i++;
        }
        if (cnt[0] < cnt[1])
          break;
      }
      i--;
      if (cnt[0] >= cnt[1] && cnt[1] <= cnt[2])
        ans = max(cnt[1], ans);
    }
  }
  cout << ans << 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 <iostream>
#include <map>
#include <sstream>
#include <string>
#include <vector>
using namespace std;
struct Data {
  char c;
  int n;
};

Data a[1000020];

int dp[1000020];
int main(void) {

  string str;
  cin >> str;

  char ch = 'A';
  int num = 1;
  int t = -1;
  for (int i = 0; i < str.size(); i++) {
    if (ch == str[i]) {
      a[t].n++;
    } else {
      ch = str[i];
      t++;
      a[t].c = ch;
      a[t].n = 1;
    }
  }
  t++;
  int ans = 0;
  for (int i = 0; i < t; i++) {
    switch (a[i].c) {
    case 'J':
      dp[i] = a[i].n;
      break;
    case 'O':
      if (i > 0) {
        if (a[i - 1].c == 'J' && a[i - 1].n >= a[i].n)
          dp[i] = a[i].n;
      }
      break;
    case 'I':
      if (i > 0) {
        if (a[i - 1].c == 'O' && dp[i - 1] <= a[i].n)
          dp[i] = dp[i - 1], ans = max(ans, dp[i]);
      }
      break;
    }
  }
  cout << ans << endl;
  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
using namespace std;
int main(void) {
  int n = 0;
  int m;

  string s;
  cin >> s;
  int q = s.size();
  string j = "J";
  string a, b, c;
  string o = "O";
  string i = "I";
  string joi;
  a = j, b = o;
  c = i;
  joi = a + b + c;
  for (n = q / 3; n > 0; n--) {
    a = j, b = o;
    c = i;
    joi = a + b + c;
    for (m = n; m > 1; m--) {
      a += j;
      b += o;
      c += i;
      joi = a + b + c;
    }
    // cout<<joi<<endl;
    if (s.find(joi) != string::npos)
      break;
  }

  cout << n << endl;

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

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <vector>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef double db;

#define fr first
#define sc second
#define pb push_back
#define rep(i, x) for (ll i = 0; i < x; i++)
#define rep1(i, x) for (ll i = 1; i <= x; i++)
#define rrep(i, x) for (ll i = x - 1; i >= 0; i--)
#define rrep1(i, x) for (ll i = x; i > 0; i--)

ll ans = 0;
ll n;
string s;
ll cnt = 0;
vector<P> p;
ll sz;
int main() {
  cin >> s;
  p.reserve(1000001);
  n = s.length();
  rep(i, n) {
    if (i == 0) {
      if (s[0] == 'J')
        p.pb(P(1, 0));
      else if (s[0] == 'O')
        p.pb(P(1, 1));
      else
        p.pb(P(1, 2));
    } else {
      if (s[i] != s[i - 1]) {
        if (s[i] == 'J')
          p.pb(P(1, 0));
        else if (s[i] == 'O')
          p.pb(P(1, 1));
        else
          p.pb(P(1, 2));
      } else {
        p[p.size() - 1].fr++;
      }
    }
  }
  for (ll i = 0; i + 2 < p.size(); i++) {
    if (p[i].sc == 0 && p[i + 1].sc == 1 && p[i + 2].sc == 2 &&
        p[i].fr >= p[i + 1].fr && p[i + 1].fr <= p[i + 2].fr) {
      ans = max(ans, p[i + 1].fr);
    }
  }
  cout << ans << endl;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <vector>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef double db;

#define fr first
#define sc second
#define pb push_back
#define rep(i, x) for (ll i = 0; i < x; i++)
#define rep1(i, x) for (ll i = 1; i <= x; i++)
#define rrep(i, x) for (ll i = x - 1; i >= 0; i--)
#define rrep1(i, x) for (ll i = x; i > 0; i--)

ll ans = 0;
ll n;
string s;
ll cnt = 0;
vector<P> p;
ll sz;
int main() {
  cin >> s;
  p.reserve(1000001);
  n = s.length();
  rep(i, n) {
    if (i == 0) {
      if (s[0] == 'J')
        p.pb(P(1, 0));
      else if (s[0] == 'O')
        p.pb(P(1, 1));
      else
        p.pb(P(1, 2));
    } else {
      if (s[i] != s[i - 1]) {
        if (s[i] == 'J')
          p.pb(P(1, 0));
        else if (s[i] == 'O')
          p.pb(P(1, 1));
        else
          p.pb(P(1, 2));
      } else {
        p[p.size() - 1].fr++;
      }
    }
  }
  rep(i, p.size() - 2) {
    if (p[i].sc == 0 && p[i + 1].sc == 1 && p[i + 2].sc == 2 &&
        p[i].fr >= p[i + 1].fr && p[i + 1].fr <= p[i + 2].fr) {
      ans = max(ans, p[i + 1].fr);
    }
  }
  cout << ans << endl;
}