Language: C

#pragma GCC optimize(3, "Ofast", "inline")
#include <bits/stdc++.h>
#if __cplusplus >= 201103L
#include <chrono>
using namespace std::chrono;
#endif
using namespace std;
#define ll long long
#define ull unsigned long long
#define pii pair<int, int>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define CASET int ___T; scanf("%d", &___T); for(int cs=1;cs<=___T;cs++)
#ifdef LOCAL
#define prln(x) (cout << #x << ' ' << x << endl)
#define pr(x) (cout << #x << ' ' << x << ' ' )
#define prv(x) (cout << x << ' ')
#else
#define prln(x) 
#define pr(x)
#define prv(x)
#endif
#define clr(x) memset((x), 0, sizeof((x)))
#define clr1(x) memset((x), -1, sizeof((x)))
#define endl "\n"
#define pi acos(-1)
#define rep(i, st, ed) for (int i = (st); i <= (ed); ++i)
#define rep0(i, st, ed) for (int i = (st); i < (ed); ++i)
#define per0(i, st, ed) for (int i = (st); i > ed; --i)
#define per(i, st, ed) for (int i = (st); i >= ed; --i)
#define chmin(a, b) (a = a > b ? b : a)
#define chmax(a, b) (a = a < b ? b : a)
template<class T> void _sf(T &x) {cin >> x;}
void _sf(int &x) {scanf("%d", &x);}
void _sf(ll &x) {scanf("%lld", &x);}
void _sf(double &x) {scanf("%lf", &x);}
void _sf(char &x) {scanf(" %c", &x);}
void _sf(char *x) {scanf("%s", x);}
void sf() {}
template <class T, class...U> void sf(T & head, U&... tail) { _sf(head); sf(tail...);}
template<class T> void _out(const T &x) { cout << x; }
void _out(const int &x) { printf("%d", x); }
void _out(const ll &x) { printf("%lld", x); }
void _out(const double &x) { printf("%.16f", x); }
void _out(const char &x) { putchar(x); }
void _out(const char *x) { printf("%s", x); }
template<class T,class U> void _out(const pair<T,U> &x) {_out(x.F); putchar(' '); _out(x.S);}
template<class T> void _out(const vector<T> &x) { for (auto i = x.begin(); i != x.end(); _out(*i++)) if (i != x.cbegin()) putchar(' '); }
void out() {}
template<class T, class... U> void out(const T &head, const U &... tail) { _out(head); putchar(sizeof...(tail) ? ' ' : '\n'); out(tail...); }
const int mod = 1e9 + 7;
const int INF = 0x3f3f3f3f;

int read() {
    int x = 0, f = 1;
    char ch = getchar();
    while (ch < '0' || ch > '9') {
        if (ch == '-') f = -1;
        ch = getchar();
    }
    while (ch >= '0' && ch <= '9') {
        x = x * 10 + ch - '0';
        ch = getchar();
    }
    return x * f;
}
const int maxn = 4e3 + 5;
int a[maxn][2], b[maxn][2], c[maxn][2];
char s[maxn];
int main(){
    #ifdef LOCAL
        freopen("in.txt", "r", stdin);
        freopen("out.txt", "w", stdout);
    #endif
    int n = read();
    scanf("%s", s + 1);
    for (int i = 1; i <= n; ++i) {
        a[i][0] = a[i - 1][0];
        b[i][0] = b[i - 1][0];
        c[i][0] = c[i - 1][0];
        if (s[i] == 'R') a[i][0] +=  + 1;
        else if (s[i] == 'G') b[i][0] +=  + 1;
        else if (s[i] == 'B') c[i][0] +=  + 1;
    }

    for (int i = n; i >= 1; --i) {
        a[i][1] = a[i + 1][1];
        b[i][1] = b[i + 1][1];
        c[i][1] = c[i + 1][1];
        if (s[i] == 'R') a[i][1] +=   1;
        else if (s[i] == 'G') b[i][1] +=  + 1;
        else c[i][1] += + 1;
    }
    ll ans = 0;
    rep(i, 1, n) {
        pr(a[i][0]);prln(a[i + 1][1]);
    }
    for (int i = 2; i < n; ++i) {
        if (s[i] == 'R') {
            ans += 1ll * b[i - 1][0] * c[i + 1][1] + 1ll * c[i - 1][0] * b[i + 1][1];
        }else if (s[i] == 'G') {
            ans += 1ll * a[i - 1][0] * c[i + 1][1] + 1ll * c[i - 1][0] * a[i + 1][1];
        }else {
            ans += 1ll * a[i - 1][0] * b[i + 1][1] + 1ll * b[i - 1][0] * a[i + 1][1];
        }
    }
    prln(ans);
    for (int i = 2; i < n; ++i) {
        // prln(min(i - 1, n - i));
        for (int len = 1; len <= min(i - 1, n - i); ++len) {
            // pr(len);
            if (s[i] == 'R') {
                if (s[i - len] == 'G' && s[i + len] == 'B') --ans;
                if (s[i - len] == 'B' && s[i + len] == 'G') --ans;
            }else if (s[i] == 'G') {
                if (s[i - len] == 'R' && s[i + len] == 'B') --ans;
                if (s[i - len] == 'B' && s[i + len] == 'R') --ans;
            }else {
                if (s[i - len] == 'R' && s[i + len] == 'G') --ans;
                if (s[i - len] == 'G' && s[i + len] == 'R') --ans;
            }
        }
    }
    cout << ans << endl;
    return 0;
}

Compiler output:
main.c:2:10: fatal error: bits/stdc++.h: No such file or directory
    2 | #include <bits/stdc++.h>
      |          ^~~~~~~~~~~~~~~
compilation terminated.