Language: C++

#include<stdio.h>
#include<stdlib.h>
#include<iostream>
#include<string>
#include<vector>
#include<math.h>
#include<queue>
#include <algorithm>
#include<functional>
#include<cstdlib>
#include<cmath>


#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define CI cin >>
#define CO cout <<
#define E << endl;

using namespace std;

typedef pair<int, int> P;
typedef pair<long, long> LP;
typedef pair<int, P> PP;
typedef pair<long, LP> LPP;



int dy[] = { 0, 0, 1, -1, 0 };
int dx[] = { 1, -1, 0, 0, 0 };

int A = 0, B = 0, K = 0, T = 0, W = 0, N = 0, H = 0;
double V = 0;
int n = 0;
double L = 0;
double S = 0;
double ar = 0, br = 0, cr = 0;
int answer = 0;


string sA, strB;
vector<vector<char>> map;
vector<double> num;
//vector<string> str;

int sum = 0;

vector<int> value;
vector<int> weight;

int dp[110][10010];

int data_[210][2] = { -2 };

const long long int III = 1000010;

char str[III];

void input(void) {
	scanf("%s",str);
	return;
}


int main(void) {
	input();
	long long int f_j = 0;
	long long int f_o = 0;
	long long int f_i = 0;

	long long int max_k = 0;

	for (int i = 0; i < strlen(str); i++) {
		if (str[i] == 'J') {
			if (f_o == 0 && f_i == 0) {
				f_j++;
			}
			if (f_o != 0 || f_i != 0) {
				f_j = 1;
				f_o = 0;
				f_i = 0;
			}
		}
		else {
			if (f_j > 0 && f_o != f_j && str[i] == 'O') {
				f_o++;
			}
			else {
				if (f_o > 0 && f_i != f_o && str[i] == 'I') {
					f_i++;
					if (f_j >= f_o && f_o == f_i) {
						if (f_o > max_k) {
							max_k = f_o;
						}
						f_j = 0;
						f_o = 0;
						f_i = 0;
					}
				}
				else {
					
					f_j = 0;
					f_o = 0;
					f_i = 0;
					
				}
			}
		}
	}

	CO max_k E


	return 0;
}

/*#include<stdio.h>
#include<string.h>
int n, m;
int k;
int len;
int flgj = 0, flgo = 0, flg;
int j = 0, o = 0, i = 0;
int max = 0;
int temp;
char s[1000010];
int main(void) {
	scanf_s("%s", s, 1000010);
	len = strlen(s);
	for (k = 0; k<len; k++) {
		flg = 0;
		if (s[k] == 'J' && flgo == 0) {
			j++;
			flgj = 1;
			if (s[k + 1] == 'I') {
				flg = 1;
			}
		}
		else if (s[k] == 'O' && flgj == 1) {
			o++;
			flgo = 1;
			if (s[k + 1] == 'J') {
				flg = 1;
			}
		}
		else if (s[k] == 'I' && flgo == 1) {
			i++;
			if (s[k + 1] != 'I') {
				flg = 2;
			}
			if (k == len - 1) {
				flg = 2;
			}
		}
		if (flg == 1) {
			j = 0;
			o = 0;
			flgj = 0;
			flgo = 0;
		}
		if (flg == 2) {
			//printf("%d %d %d\n",j,o,i);
			if (j<o || i<o) {
			}
			else {
				temp = j;
				if (temp>o) {
					temp = o;
				}
				if (temp>i) {
					temp = i;
				}
			}
			if (max<temp) {
				max = temp;
			}
			j = 0;
			o = 0;
			i = 0;
			flgj = 0;
			flgo = 0;
		}
	}
	printf("%d\n", max);
	return 0;
}
*/

Compiler output:
a.cc: In function 'int main()':
a.cc:75:29: error: 'strlen' was not declared in this scope
   75 |         for (int i = 0; i < strlen(str); i++) {
      |                             ^~~~~~
a.cc:12:1: note: 'strlen' is defined in header '<cstring>'; this is probably fixable by adding '#include <cstring>'
   11 | #include<cmath>
  +++ |+#include <cstring>
   12 |