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

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

#define rep(i, x, y) for (int i = (x); i < (y); ++i)
#define mp(a, b) make_pair((a), (b))
#define debug(x) #x << "=" << (x)

#ifdef DEBUG
#define _GLIBCXX_DEBUG
#define dump(x) std::cerr << debug(x) << " (L:" << __LINE__ << ")" << std::endl
#else
#define dump(x)
#endif

typedef long long int ll;
typedef pair<int, int> pii;
// template<typename T> using vec=std::vector<T>;

const int INF = 1 << 30;
const long long int INF_ = 1LL << 58;
const double EPS = 1e-9;
const int dx[] = {1, 0, -1, 0}, dy[] = {0, 1, 0, -1};

template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec) {
  os << "[";
  for (const auto &v : vec) {
    os << v << ",";
  }
  os << "]";
  return os;
}

struct Type {
  char ch;
  int len;
};

void Solve() {
  string s;
  cin >> s;

  vector<Type> cmp;
  char ch = s[0];
  int cnt = 1;
  rep(i, 1, s.size()) {
    if (s[i] != ch) {
      cmp.push_back(Type{ch, cnt});
      ch = s[i];
      cnt = 1;
    } else
      ++cnt;
  }
  cmp.push_back(Type{ch, cnt});

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

  cout << ans << endl;
}

int main() {
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);
  Solve();
  return 0;
}

Error: 0

Fixed submission:

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

#define rep(i, x, y) for (int i = (x); i < (y); ++i)
#define mp(a, b) make_pair((a), (b))
#define debug(x) #x << "=" << (x)

#ifdef DEBUG
#define _GLIBCXX_DEBUG
#define dump(x) std::cerr << debug(x) << " (L:" << __LINE__ << ")" << std::endl
#else
#define dump(x)
#endif

typedef long long int ll;
typedef pair<int, int> pii;
// template<typename T> using vec=std::vector<T>;

const int INF = 1 << 30;
const long long int INF_ = 1LL << 58;
const double EPS = 1e-9;
const int dx[] = {1, 0, -1, 0}, dy[] = {0, 1, 0, -1};

template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec) {
  os << "[";
  for (const auto &v : vec) {
    os << v << ",";
  }
  os << "]";
  return os;
}

struct Type {
  char ch;
  int len;
};

void Solve() {
  string s;
  cin >> s;

  vector<Type> cmp;
  char ch = s[0];
  int cnt = 1;
  rep(i, 1, s.size()) {
    if (s[i] != ch) {
      cmp.push_back(Type{ch, cnt});
      ch = s[i];
      cnt = 1;
    } else
      ++cnt;
  }
  cmp.push_back(Type{ch, cnt});

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

  cout << ans << endl;
}

int main() {
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);
  Solve();
  return 0;
}
Problem p00494 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <map>
#include <set>
#include <string>
#include <utility>
#include <vector>
#define loop(i, a, b) for (int i = a; i < b; i++)
#define rep(i, a) loop(i, 0, a)
#define pb push_back
#define mp make_pair
#define it ::iterator
#define all(in) in.begin(), in.end()
const double PI = acos(-1);
const double ESP = 1e-10;
using namespace std;
int main() {
  string s;
  cin >> s;
  vector<char> ch;
  vector<int> co;
  int c = 0;
  rep(i, s.size()) {
    c++;
    if (i == s.size() - 1 || s[i] != s[i + 1]) {
      co.pb(c);
      ch.pb(s[i]);
      c = 0;
    }
  }
  int out = 0;
  if (ch.size() > 2) {
    rep(i, ch.size() - 2) {
      if (ch[i] == 'J' && ch[i + 1] == 'O' && ch[i + 2] == 'I')
        if (co[i + 1] <= co[i] && co[i + 1] <= co[i + 2])
          out = max(out, co[i + 1]);
    }
  }
  cout << out << endl;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <map>
#include <set>
#include <string>
#include <utility>
#include <vector>
#define loop(i, a, b) for (int i = a; i < b; i++)
#define rep(i, a) loop(i, 0, a)
#define pb push_back
#define mp make_pair
#define it ::iterator
#define all(in) in.begin(), in.end()
const double PI = acos(-1);
const double ESP = 1e-10;
using namespace std;
int main() {
  string s;
  cin >> s;
  vector<char> ch;
  vector<int> co;
  int c = 0;
  rep(i, s.size()) {
    c++;
    if (i == s.size() - 1 || s[i] != s[i + 1]) {
      co.pb(c);
      ch.pb(s[i]);
      c = 0;
    }
  }
  int out = 0;
  rep(i, ch.size() - 2) {
    if (ch[i] == 'J' && ch[i + 1] == 'O' && ch[i + 2] == 'I')
      out = max(out, min(co[i], min(co[i + 1], co[i + 2])));
  }
  cout << out << endl;
}
Problem p00494 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>

using namespace std;

char c[1000000 + 1];

int cnt(int a, char str) {
  int i = 0;
  while (c[a] == str) {
    i++;
    a++;
  }
  return i;
}

int main() {
  int ans = 0;
  cin >> c;
  for (int i = 0; c[i] != '\\0'; i++) {
    if (c[i] == 'J') {
      int p = i;
      int J = cnt(p, 'J');
      p += J;
      if (c[p] == 'O') {
        int O = cnt(p, 'O');
        p += O;
        if (c[p] == 'I' && J >= O) {
          int I = cnt(p, 'I');
          p += I;
          if (I >= O && O > ans) {
            ans = O;
          } else {
            i = p - 1;
          }
        } else {
          i = p - 1;
        }
      } else {
        i = p - 1;
      }
    }
  }
  cout << ans << endl;
  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>

using namespace std;

char c[1000000 + 1];

int cnt(int a, char str) {
  int i = 0;
  while (c[a] == str) {
    i++;
    a++;
  }
  return i;
}

int main() {
  int ans = 0;
  cin >> c;
  for (int i = 0; i < sizeof(c); i++) {
    if (c[i] == 'J') {
      int p = i;
      int J = cnt(p, 'J');
      p += J;
      if (c[p] == 'O') {
        int O = cnt(p, 'O');
        p += O;
        if (c[p] == 'I' && J >= O) {
          int I = cnt(p, 'I');
          if (I >= O && O > ans) {
            ans = O;
          }
        } else {
          i = p - 1;
        }
      } else {
        i = p - 1;
      }
    }
  }
  cout << ans << endl;
  return 0;
}
Problem p00494 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <cmath>
#include <iostream>
#include <string>

using namespace std;

int main() {
  string s;
  cin >> s;
  long long int cc = 0;
  long long int sz = s.size();
  for (long long int i = 0; i < sz; i++) {
    if (s[i] == 'J') {
      long long int jj = 1;
      for (long long int j = i + 1; j < sz; j++) {
        if (s[j] == 'J') {
          jj++;
          i++;
        } else {
          break;
        }
      }
      long long int oo = 0;
      for (long long int j = i + 1; j < sz; j++) {
        if (s[j] == 'O') {
          oo++;
          i++;
        } else {
          break;
        }
      }
      if (oo > 0 && jj >= oo) {
        long long int ii = 0;
        for (long long int j = i + 1; j < sz; j++) {
          if (s[j] == 'I') {
            ii++;
            i++;
          } else {
            break;
          }
        }
        if (ii > 0 && ii >= oo) {
          cc = max(cc, oo);
        }
      }
    }
  }
  cout << cc << endl;
  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
#include <string>

using namespace std;

int main() {
  string s;
  cin >> s;
  string abc = "JOI";
  long long int ss = s.size();
  ss /= 3;
  for (long long int i = ss; i >= 0; i--) {
    string joi = "";
    for (int j = 0; j < 3; j++) {
      for (long long int k = 0; k < i; k++) {
        joi += abc[j];
      }
    }
    if (s.find(joi) != string::npos) {
      cout << i << endl;
      break;
    }
  }
  return 0;
}
Problem p00494 (C++) — buggy submission, verdict: Time Limit Exceeded

#define _USE_MATH_DEFINES
#define INF 0x3f3f3f3f
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <iostream>
#include <limits>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>

using namespace std;

typedef long long ll;
typedef pair<int, int> P;
typedef pair<int, P> PP;

int tx[] = {0, 1, 0, -1};
int ty[] = {-1, 0, 1, 0};

static const double EPS = 1e-8;

struct Jinfo {
  int start;
  int len;
};

int main() {
  string str;
  while (cin >> str) {
    int res = 0;

    deque<char> jdeq;
    deque<char> odeq;
    deque<char> ideq;

    int onum = 0;
    for (int i = 0; i < str.size(); i++) {
      if (str[i] == 'J') {
        if (odeq.size() > 0 || ideq.size() > 0) {
          odeq.clear();
          ideq.clear();
          jdeq.clear();
        }

        jdeq.push_back(str[i]);
      }

      else if (str[i] == 'O') {
        if (ideq.size() > 0) {
          jdeq.clear();
          odeq.clear();
          ideq.clear();
        }
        odeq.push_back(str[i]);
      }

      else if (str[i] == 'I') {
        ideq.push_back(str[i]);
      }

      if (ideq.size() > 0 && odeq.size() > 0 && jdeq.size() > 0 &&
          jdeq.size() >= odeq.size() && ideq.size() >= odeq.size()) {
        res = max(res, (int)odeq.size());
        jdeq.clear();
        ideq.clear();
        odeq.clear();
      }
    }

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

Error: TLE

Fixed submission:

#define _USE_MATH_DEFINES
#define INF 0x3f3f3f3f
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <iostream>
#include <limits>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>

using namespace std;

typedef long long ll;
typedef pair<int, int> P;
typedef pair<int, P> PP;

int tx[] = {0, 1, 0, -1};
int ty[] = {-1, 0, 1, 0};

static const double EPS = 1e-8;

int main() {
  string str;
  while (cin >> str) {
    int res = 0;
    for (int i = str.size() / 3; i >= 0; i--) {
      for (int j = 0; j + i + i < str.size(); j++) {
        string J = str.substr(j, i);
        string O = str.substr(j + i, i);
        string I = str.substr(j + i + i, i);

        if (count(J.begin(), J.end(), 'J') == i &&
            count(O.begin(), O.end(), 'O') == i &&
            count(I.begin(), I.end(), 'I') == i) {
          res = i;
          goto found;
        }
      }
    }
  found:;
    printf("%d\\n", res);
  }
}
Problem p00494 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <cstdio>
#include <cstring>
#include <iostream>
#include <string.h>
using namespace std;
char str[1000000];
int main() {
  int ans, k, len, J, O, I;
  int a;
  // string str;

  while (scanf("%s", str) != EOF) {
    len = strlen(str);
    J = 0, O = 0, I = 0;
    ans = 0, k = 0;
    // cout << len << endl;
    for (int i = 0; i < len; i++) {
      if (str[i] != 'J')
        continue;

      if (str[i] == 'J') {
        if (str[i] != '#')
          a = i;
        while (str[a] == 'J') {
          str[a] = '#';
          a++;
          J++;
        }
        if (str[a] == 'O') {
          while (str[a] == 'O') {
            a++;
            O++;
          }
          if (str[a] == 'I') {
            while (str[a] == 'I') {
              a++;
              I++;
            }
          }
        }
      }
      // printf("J = %d, O = %d, I = %d\\n", J, O, I);
      if (O <= J && O <= I)
        k = min(J, min(O, I));
      // if(J == O && O == I /*|| J <= O && O >= I*/) k = min(J, min(O, I));
      // else J = 0; O = 0; I = 0;
      ans = max(k, ans);
      J = 0;
      O = 0;
      I = 0;
    }
    cout << ans << endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <cstdio>
#include <cstring>
#include <iostream>
#include <string.h>
using namespace std;
char str[1000000];
int main() {
  int ans, k, len, J, O, I;
  int a;
  // string str;

  while (scanf("%s", str) != EOF) {
    len = strlen(str);
    J = 0, O = 0, I = 0;
    ans = 0, k = 0;
    for (int i = 0; i < len; i++) {
      if (str[i] == 'J') {
        a = i;
        while (str[a] == 'J') {
          a++;
          J++;
        }
        if (str[a] == 'O') {
          while (str[a] == 'O') {
            a++;
            O++;
          }
          if (str[a] == 'I') {
            while (str[a] == 'I') {
              a++;
              I++;
            }
          }
        }
      }
      // printf("J = %d, O = %d, I = %d\\n", J, O, I);
      if (O <= J && O <= I)
        k = min(J, min(O, I));
      // if(J == O && O == I /*|| J <= O && O >= I*/) k = min(J, min(O, I));
      // else J = 0; O = 0; I = 0;
      ans = max(k, ans);
      J = 0;
      O = 0;
      I = 0;
    }
    cout << ans << endl;
  }
  return 0;
}
Problem p00494 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
#define foru(i, a, b) for (int i = int(a); i <= int(b); i++)
using namespace std;
string s;
char a[1000005];
int b[1000005];

int main() {
  ios_base::sync_with_stdio(0);
  // freopen("jjooii.inp","r",stdin);
  // freopen("jjooii.out","w",stdout);
  cin >> s;
  s = 'a' + s;
  s = s + 'a';
  // foru(i, 0, 1000000) a = s[i] + a;
  // cout << a << endl'
  int luu, n, res;
  res = 0;
  luu = 1;
  n = 0;
  foru(i, 1, s.size() - 1) if (s[i] != s[i - 1]) {
    // a=a+s[i];
    n++;
    a[n] = s[i];
    b[n - 1] = luu;
    luu = 1;
  }
  else luu++;
  // cout<<a<<endl;
  foru(i, 3, n) if (a[i] == 'I' && a[i - 1] == 'O' && a[i - 2] == 'J' &&
                    b[i] >= b[i - 1] && b[i - 2] >= b[i - 1]) res =
      max(res, b[i - 1]);
  cout << res << endl;
  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define foru(i, a, b) for (int i = int(a); i <= int(b); i++)
using namespace std;
string s, a;
int b[1000005];

int main() {
  // freopen("a.txt","r",stdin);
  // freopen("b.txt","w",stdout);
  cin >> s;
  s = 'a' + s;
  s = s + 'a';
  a = "";
  int luu, n, res;
  res = 0;
  luu = 1;
  n = 0;
  foru(i, 1, s.size() - 1) if (s[i] != s[i - 1]) {
    a = a + s[i];
    n++;
    b[n - 1] = luu;
    luu = 1;
  }
  else luu++;
  // cout<<a<<endl;
  a = 'a' + a;
  foru(i, 3, n) if (a[i] == 'I' && a[i - 1] == 'O' && a[i - 2] == 'J' &&
                    b[i] >= b[i - 1] && b[i - 2] >= b[i - 1]) res =
      max(res, b[i - 1]);
  cout << res << endl;
  return 0;
}
Problem p00494 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>

using namespace std;

int main() {
  string s;

  while (cin >> s) {
    int ret = 0;
    for (int i = 0; i < s.size(); i++) {
      if (s[i] == 'O') {
        int count = 1;
        while (s[i + count] == 'O')
          count++;
        bool is = true;
        for (int j = i + count; j < i + count + count; j++)
          if (s.size() <= j || s[j] != 'I') {
            is = false;
            break;
          }
        for (int j = i - count; j < i; j++)
          if (j < 0 || s[j] != 'J') {
            is = false;
            break;
          }
        if (is)
          ret = max(ret, count);
        i = i + count;
      }
    }
    cout << ret << endl;
  }
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>

using namespace std;

typedef vector<int> vi;
typedef vector<vi> vii;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<vb> vbb;
typedef pair<int, int> pii;
typedef long long ll;
typedef unsigned long long ull;

#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define pb push_back
#define mp make_pair

#define loop(i, a, b) for (int i = (a); i < ull(b); ++i)
#define rep(i, n) loop(i, 0, n)

const double eps = 1e-10;
const double pi = acos(-1.0);
const double inf = (int)1e8;

int main() {
  string s;
  cin >> s;
  int ret = 0;
  for (int i = 0; i < s.size(); i++) {
    if (s[i] == 'O') {
      int count = 1, fst = i;
      while (s[fst + count] == 'O')
        count++;
      bool is = true;
      for (int j = i + count; j < i + count + count - 1; j++)
        if (s[j] != 'I') {
          is = false;
          break;
        }
      for (int j = i - count; j < i; j++)
        if (s[j] != 'J') {
          is = false;
          break;
        }
      if (is)
        ret = max(ret, count);
      i = i + count;
    }
  }
  cout << ret << endl;
}
Problem p00494 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <cctype>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <vector>

using namespace std;

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

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

const int INF = 1001001001;

int main() {
  char str[1000100];
  scanf("%s", str);
  int n = strlen(str);

  vector<pair<char, int>> data;
  rep(i, n) {
    if (!data.empty() && data[data.size() - 1].first == str[i])
      data[data.size() - 1].second++;
    else
      data.push_back(make_pair(str[i], 1));
  }

  int ans = 0;
  rep(i, data.size() - 2) {
    if (data[i].first == 'J' && data[i + 1].first == 'O' &&
        data[i + 2].first == 'I') {
      int a = data[i].second;
      int b = data[i + 1].second;
      int c = data[i + 2].second;
      if (b <= a && b <= c)
        ans = max(ans, b);
    }
  }
  printf("%d\\n", ans);

  return 0;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <cctype>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <vector>

using namespace std;

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

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

const int INF = 1001001001;

int main() {
  char str[100010];
  scanf("%s", str);
  int n = strlen(str);

  vector<pair<char, int>> data;
  rep(i, n) {
    if (!data.empty() && data[data.size() - 1].first == str[i])
      data[data.size() - 1].second++;
    else
      data.push_back(make_pair(str[i], 1));
  }

  int ans = 0;
  rep(i, data.size() - 2) {
    if (data[i].first == 'J' && data[i + 1].first == 'O' &&
        data[i + 2].first == 'I') {
      int a = data[i].second;
      int b = data[i + 1].second;
      int c = data[i + 2].second;
      if (b <= a && b <= c)
        ans = max(ans, b);
    }
  }
  printf("%d\\n", ans);

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

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

#define INF (2 << 28)
#define fr first
#define sc second
using namespace std;

typedef long long ll;
typedef pair<int, int> iP;

int main() {

  string s;
  int kmax = 0;

  cin >> s;

  for (int i = 0; i < s.size(); i++) {
    bool j1, j2;
    int cnt = 0;
    if (s[i] == 'O') {
      j1 = false, j2 = false;
      cnt = 1;
      for (int j = i + 1; s[j] == 'O' && j < s.size(); j++)
        cnt++;
      for (int j = i - 1, c = 1; s[j] == 'J' && j >= 0; j--, c++) {
        if (c == cnt) {
          j1 = true;
          break;
        }
      }
      for (int j = i + cnt, c = 1; s[j] == 'I' && j < s.size(); j++, c++) {
        if (c == cnt) {
          j2 = true;
          break;
        }
      }
    }
    if (j1 && j2)
      kmax = max(kmax, cnt);
    i += cnt;
  }

  cout << kmax << endl;
}

Error: TLE

Fixed submission:

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

#define INF (2 << 28)
#define fr first
#define sc second
using namespace std;

typedef long long ll;
typedef pair<int, int> iP;

int main() {

  string s;
  int kmax = 0;

  cin >> s;

  for (int i = 0; i < s.size(); i++) {
    bool j1, j2;
    int cnt = 0;
    if (s[i] == 'O') {
      j1 = false, j2 = false;
      cnt = 1;
      for (int j = i + 1; s[j] == 'O' && j < s.size(); j++)
        cnt++;
      for (int j = i - 1, c = 1; s[j] == 'J' && j >= 0; j--, c++) {
        if (c == cnt) {
          j1 = true;
          break;
        }
      }
      for (int j = i + cnt, c = 1; s[j] == 'I' && j < s.size(); j++, c++) {
        if (c == cnt) {
          j2 = true;
          break;
        }
      }
    }
    if (j1 && j2)
      kmax = max(kmax, cnt);
  }

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

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

int main() {
  int cou = 0, ans = 0, j, i, o;
  char joi[1111111];
  string tmp;
  scanf("%s", joi);
  tmp = joi;
  int len = tmp.size();
  while (len > cou) {
    if (joi[cou] != 'J') {
      cou++;
      continue;
    }
    j = 0, o = 0, i = 0;
    while (joi[cou] == 'J' && len > cou) {
      cou++;
      j++;
    }
    while (joi[cou] == 'O' && len > cou) {
      cou++;
      o++;
    }
    while (joi[cou] == 'I' && len > cou) {
      cou++;
      i++;
    }
    if (j >= o && o <= i && ans < o) {
      ans = o;
    }
  }
  cout << ans << endl;
}

Error: TLE

Fixed submission:

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

int main() {
  int len, lentmp = 0, loc, level, ans = 0;
  string strjoi, strtmp, tmp1, tmp2, tmp3;
  cin >> strjoi;
  len = strjoi.size();
  while (len >= lentmp) {
    lentmp += 3;
  }
  while (lentmp != 0) {
    lentmp -= 3;
    level = lentmp / 3;
    strtmp = "";
    for (int i = 0; i < 3; i++) {
      string tmp1(level, 'J');
      string tmp2(level, 'O');
      string tmp3(level, 'I');
      strtmp = tmp1 + tmp2 + tmp3;
    }
    loc = strjoi.find(strtmp);
    if (loc != string::npos) {
      ans = level;
      break;
    }
  }
  cout << level << endl;
}