Language: C++

#include <bits/stdc++.h>
using namespace std;
#define ll              long long
#define pb              push_back
#define mp              make_pair
#define ff              first
#define ss              second
#define SQ(x)           ((x)*(x))
#define LCM(x,y)        (((x)/gcd((x),(y)))*(y))
#define PI              acos(-1)
#define SZ(x)           x.size() - 1
#define waa             printf("Ripon\n")
#define mem(a,b)        memset(a,b,sizeof(a))
#define rep(i,a,n)      for(int i=(int)(a);i<=(int)(n);i++)
#define per(i,n,a)      for(int i=(int)(n);i>=(int)(a);i--)
#define all(v)          v.begin(), v.end()
#define allr(v)         v.rbegin(), v.rend()
int dx[] = { 0, 1, 0, -1, -1, 1, 1, -1 };
int dy[] = { 1, 0, -1, 0, -1, -1, 1, 1 };
int kx[] = { -2, -2, -1, 1, 2, 2, 1, -1 };
int ky[] = { -1, 1, 2, 2, 1, -1, -2, -2 };
int overlap(int rs,int re,int qs,int qe){ if(rs>qe or re<qs) return 0; else if(qs<=rs and re<=qe) return 1; else return 2;} // 0 no, 1 total, 2 partial
void pvec(auto v){for(auto x:v){cout<<x<<" ";}cout<<'\n';}
//*************useless stuff*************//
#define TC 0
#define mod 10000007
#define N 1000000

vector<int> pos[100];
int isg[4010];
map<pair<int,int>,bool> visit;

void solve(int T) {
    string str;
    int ln;
    cin>>ln;
    cin>>str;
    str = "$"+str;

    int red = 0,grn =0, blu = 0;

    rep(i,1,ln){
        char ch = str[i];
        if(ch=='R'){
            red++;
        }else if(ch=='B'){
            blu++;
        }else if(ch=='G'){
            grn++;
            isg[i] = 1;
        }
        pos[ch].pb(i);
    }

    ll ans = red*grn*blu;

    rep(i,0,SZ(pos['R'])){
        rep(j,0,SZ(pos['B'])){

            int arr[] = {pos['R'][i],pos['B'][j]};
            sort(arr,arr+2);

            int posA = arr[0];
            int posB = arr[1];
            if(visit[mp(posA,posB)]) continue;

            visit[mp(posA,posB)] = 1;


            int disG = posB - posA;
            //cout<<posA<<" "<<posB<<" "<<disG<<" "<<posA-disG<<" "<<posB+disG<<endl;

            if(posA - disG >=1 and isg[posA - disG]) ans--;
            if(posB + disG <=ln and isg[posB + disG]) ans--;


            int mid = (posA + posB) / 2;
            bool ismid = (posA + posB) % 2 == 0 and (posA + posB) / 2!=0;

            if(ismid and isg[mid]) ans--;

        }
    }

    cout<<ans<<endl;
    return;
}

int main(){
    ios_base::sync_with_stdio(0);cin.tie(nullptr);
    #ifdef LOCALDEF
        freopen("input.txt","r",stdin);
    #endif
    int T=1;
    if(TC) cin>>T;
    for(int t=1;t<=T;t++)   solve(t);
    return 0;
}



Compiler output:
a.cc:23:11: warning: use of 'auto' in parameter declaration only available with '-std=c++20' or '-fconcepts'
   23 | void pvec(auto v){for(auto x:v){cout<<x<<" ";}cout<<'\n';}
      |           ^~~~
a.cc: In function 'void solve(int)':
a.cc:65:16: error: reference to 'visit' is ambiguous
   65 |             if(visit[mp(posA,posB)]) continue;
      |                ^~~~~
In file included from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:80,
                 from a.cc:1:
/usr/include/c++/14/variant:1855:5: note: candidates are: 'template<class _Visitor, class ... _Variants> constexpr std::__detail::__variant::__visit_result_t<_Visitor, _Variants ...> std::visit(_Visitor&&, _Variants&& ...)'
 1855 |     visit(_Visitor&& __visitor, _Variants&&... __variants)
      |     ^~~~~
a.cc:31:25: note:                 'std::map<std::pair<int, int>, bool> visit'
   31 | map<pair<int,int>,bool> visit;
      |                         ^~~~~
a.cc:67:13: error: reference to 'visit' is ambiguous
   67 |             visit[mp(posA,posB)] = 1;
      |             ^~~~~
/usr/include/c++/14/variant:1855:5: note: candidates are: 'template<class _Visitor, class ... _Variants> constexpr std::__detail::__variant::__visit_result_t<_Visitor, _Variants ...> std::visit(_Visitor&&, _Variants&& ...)'
 1855 |     visit(_Visitor&& __visitor, _Variants&&... __variants)
      |     ^~~~~
a.cc:31:25: note:                 'std::map<std::pair<int, int>, bool> visit'
   31 | map<pair<int,int>,bool> visit;
      |                         ^~~~~