Language: C++

#define _USE_MATH_DEFINES
#define INF 0x3f3f3f3f
#include <cstdio>
#include <iostream>
#include <sstream>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <queue>
#include <stack>
#include <limits>
#include <map>
#include <string>
#include <cstring>
#include <set>
#include <deque>
#include <bitset>
#include <list>
#include <cctype>
#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> que;
		int c = 0;
		
		for(int i=0;i<str.size();i++){
			if(str[i]=='J'){
				if(que.size() == 0){
					res = max(c,res);
				}
				que.push_back(str[i]);
			}

			else if(str[i]=='O'){
				if(que.size() > 0 && que.back() == 'J'){
					que.pop_back();
					que.push_front(str[i]);
				}
				else{
					c = 0;
					que.clear();
				}
			}

			else if(str[i]=='I'){
				if(que.size() > 0 && que.front() == 'O'){
					que.push_back(str[i]);
					que.pop_front();
					c++;
				}
				else{
					res = max(res,count(que.begin(),que.end(),'I'));
					c = 0;
					que.clear();
				}
			}

		}

		res = max(res,count(que.begin(),que.end(),'I'));
		printf("%d\n",res);

	}
}

Compiler output:
a.cc: In function 'int main()':
a.cc:72:50: error: no matching function for call to 'max(int&, std::__iterator_traits<std::_Deque_iterator<char, char&, char*>, void>::difference_type)'
   72 |                                         res = max(res,count(que.begin(),que.end(),'I'));
      |                                               ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from /usr/include/c++/14/string:51,
                 from /usr/include/c++/14/bits/locale_classes.h:40,
                 from /usr/include/c++/14/bits/ios_base.h:41,
                 from /usr/include/c++/14/ios:44,
                 from /usr/include/c++/14/ostream:40,
                 from /usr/include/c++/14/iostream:41,
                 from a.cc:4:
/usr/include/c++/14/bits/stl_algobase.h:257:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::max(const _Tp&, const _Tp&)'
  257 |     max(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:257:5: note:   template argument deduction/substitution failed:
a.cc:72:50: note:   deduced conflicting types for parameter 'const _Tp' ('int' and 'std::__iterator_traits<std::_Deque_iterator<char, char&, char*>, void>::difference_type' {aka 'long int'})
   72 |                                         res = max(res,count(que.begin(),que.end(),'I'));
      |                                               ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:303:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::max(const _Tp&, const _Tp&, _Compare)'
  303 |     max(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:303:5: note:   candidate expects 3 arguments, 2 provided
In file included from /usr/include/c++/14/algorithm:61,
                 from a.cc:8:
/usr/include/c++/14/bits/stl_algo.h:5706:5: note: candidate: 'template<class _Tp> constexpr _Tp std::max(initializer_list<_Tp>)'
 5706 |     max(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5706:5: note:   candidate expects 1 argument, 2 provided
/usr/include/c++/14/bits/stl_algo.h:5716:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::max(initializer_list<_Tp>, _Compare)'
 5716 |     max(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5716:5: note:   template argument deduction/substitution failed:
a.cc:72:50: note:   mismatched types 'std::initializer_list<_Tp>' and 'int'
   72 |                                         res = max(res,count(que.begin(),que.end(),'I'));
      |                                               ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
a.cc:80:26: error: no matching function for call to 'max(int&, std::__iterator_traits<std::_Deque_iterator<char, char&, char*>, void>::difference_type)'
   80 |                 res = max(res,count(que.begin(),que.end(),'I'));
      |                       ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:257:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::max(const _Tp&, const _Tp&)'
  257 |     max(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:257:5: note:   template argument deduction/substitution failed:
a.cc:80:26: note:   deduced conflicting types for parameter 'const _Tp' ('int' and 'std::__iterator_traits<std::_Deque_iterator<char, char&, char*>, void>::difference_type' {aka 'long int'})
   80 |                 res = max(res,count(que.begin(),que.end(),'I'));
      |                       ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:303:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::max(const _Tp&, const _Tp&, _Compare)'
  303 |     max(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:303:5: note:   candidate expects 3 arguments, 2 provided
/usr/include/c++/14/bits/stl_algo.h:5706:5: note: candidate: 'template<class _Tp> constexpr _Tp std::max(initializer_list<_Tp>)'
 5706 |     max(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5706:5: note:   candidate expects 1 argument, 2 provided
/usr/include/c++/14/bits/stl_algo.h:5716:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::max(initializer_list<_Tp>, _Compare)'
 5716 |     max(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5716:5: note:   template argument deduction/substitution failed:
a.cc:80:26: note:   mismatched types 'std::initializer_list<_Tp>' and 'int'
   80 |                 res = max(res,count(que.begin(),que.end(),'I'));
      |                       ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~