#include <cstdio>
#include <stdio.h>
#include <stdbool.h>
#include <iostream>
#include <map>
#include <vector>
#include <climits>
#include <stack>
#include <string>
#include <queue>
#include <algorithm>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <cmath>
#include <cctype>
#include <bitset>
#include <iomanip>
#include <cstring>
#include <numeric>
#include <cassert>
#include <chrono>
using namespace std;
#define int long long
#define pii pair<int, int>
#define mp make_pair
#define pb push_back
#define fi first
#define se second
int calc(string s){
int j=0, o=0, i=0;
for (auto a:s){
if (a=='J')++j;
else if (a=='O')o+=j;
else i+=o;
}
return i;
}
int32_t main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int n, mx=0, j=0, i=0;
string s;
cin>>n>>s;
for (auto a:s)if (a=='I')++i;
for (auto a:s){
if (a=='J')++j;
else if (a=='I')--i;
mx=max(mx, j*i);
}
cout<<max({mx+calc(s), calc("J"+s), calc(s+"I")});
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |