#include <bits/stdc++.h>
#define int long long
using namespace std;
signed main() {
ios::sync_with_stdio(false);
cin.tie(0);
int n;
cin >> n;
vector<char> a(n + 1);
for(int i = 1; i <= n; i++) {
cin >> a[i];
}
int f = 0;
vector<int> prefj(n + 1, 0);
vector<int> sufi(n + 3, 0);
for(int i = 1; i <= n; i++) {
prefj[i] = prefj[i - 1] + (a[i] == 'J');
}
for(int i = n; i >= 1; i--) {
sufi[i] = sufi[i + 1] + (a[i] == 'I');
}
for(int i = 1; i <= n; i++) {
if(a[i] != 'J') {
continue;
}
for(int j = i + 1; j <= n; j++) {
if(a[j] == 'O') {
f += sufi[j + 1];
}
}
}
int ans = 0;
for(int i = 1; i <= n + 1; i++) {
int ansj = f;
int anso = f;
int ansi = f;
for(int j = i + 1; j <= n; j++) {
if(a[j] == 'O') {
ansj += sufi[j + 1];
}
}
anso += prefj[i - 1] * sufi[i + 1];
for(int j = i - 1; j >= 1; j--) {
if(a[j] == 'O') {
ansi += prefj[j - 1];
}
}
ans = max({ans, ansj, ansi, anso});
}
cout << ans;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |