This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
#define rep(i,s,e)                  for (int i = s; i <= e; ++i)
#define rrep(i,s,e)                 for (int i = s; i >= e; --i)
#define pb                          push_back
#define pf                          push_front
#define fi                          first
#define se                          second
#define all(a)                      a.begin(), a.end()
#define len(a)                      (int)a.size()
typedef long long ll;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<ll> vll;
int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    int n; cin >> n;
    string s; cin >> s;
    vi v[2];
    rep (i,0,2*n-1) v[s[i]=='B'].pb(i);
    ll ans = 0;
    rep (k,0,n-1) {
        ll cur = 0;
        rep (i,0,n-1) {
            rep (j,i+1,n-1) {
                int x1 = min(v[0][i], v[1][(i+k)%n]);
                int y1 = max(v[0][i], v[1][(i+k)%n]);
                int x2 = min(v[0][j], v[1][(j+k)%n]);
                int y2 = max(v[0][j], v[1][(j+k)%n]);
                if (x1<y2 && x1>x2 && y1>y2) ++cur;
                if (y1<y2 && y1>x2 && x1<x2) ++cur;
            }
        }
        ans = max(ans, cur);
    }
    cout << ans << "\n";
    return 0;
}
| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... |