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;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int n;
    cin >> n;
    string s;
    cin >> s;
    vector<int> p(0);
    vector<int> q(0);
    for(int i = 0; i < 2*n; i++) {
        if(s[i] == 'B') {
            p.push_back(i);
        }
        else {
            q.push_back(i);
        }
    }
    int ans = 0;
    for(int i = 0; i < n; i++) {
        int br = 0;
        for(int j = 0; j < n; j++) {
            for(int k = j+1; k < n; k++) {
                int a = p[j],b = q[j],c = p[k],d = q[k];
                if(c > d) {
                    swap(c,d);
                }
                if(a > b) {
                    swap(a,b);
                }
                if(c < a) {
                    swap(a,c);
                    swap(b,d);
                }
                if(c > a && c < b && d > b) {
                    br++;
                }
            }
        }
        ans = max(ans,br);
        for(int j = 0; j < n-1; j++) {
            swap(q[j],q[j+1]);
        }
    }
    cout << ans;
    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... |