Language: C

#include <bits/stdc++.h>
#include <regex>
#ifdef _DEBUG
#include "debug.h"
#endif
#define int ll
#define FOR(i, s, e) for (int i = int(s); i < int(e); ++i)
#define REP(i, e) FOR(i, 0, e)
#define all(v) (v).begin(),(v).end()
#define mkpr make_pair
#define mktp make_tuple
#define tv(tp, i) get<(i)>(tp)
#define CLEAR(obj) obj = decltype(obj)()
#define var auto
#define OUT(type) type &
#define IN(type) const type &
#define self (*this)
#define in :
#define True true
#define False false
using namespace std; using int32 = int32_t; using str = string; using cstr = const str;
using ll = long long; using ull = unsigned long long; using cint = const int; using cll = const ll;
using vi = vector<int>; using vvi = vector<vi>; using vl = vector<ll>; using vvl = vector<vl>;
using vb = vector<bool>; using vvb = vector<vb>; using vd = vector<double>; using vvd = vector<vd>;
using vc = vector<char>; using vvc = vector<vc>; using vs = vector<string>;
using pii = pair<int, int>; using pll = pair<ll, ll>; using pdd = pair<double, double>; using psl = pair<string, ll>;
using tiii = tuple<int, int, int>; using tlll = tuple<ll, ll, ll>;
static const int MGN = 10; static const int ARYSZ_MAX = (int)1e7;
static const ll LINF = LLONG_MAX/2;
#ifdef int
static const int INF = LINF;
#else
static const int INF = INT_MAX/2;
#endif
static double EPS = 1e-9;
#define FASTCIN() cin.tie(0);ios::sync_with_stdio(false);
#ifdef IMPORT_SAMPLE
#define DEBUG_IMPORT(file) vs args(argv, argv+argc);str sample = make_sample(args, file);ifstream ifs(sample); cin.rdbuf(ifs.rdbuf());
#else
#define DEBUG_IMPORT(file)
#endif
static inline bool DBLEQ(double a, double b) {return abs(a - b) < EPS;}
static inline void EPR(str msg) {cerr << msg << endl;}
static inline void AST(bool exp, str msg) {if(!exp){EPR(msg);} assert(exp);}
static inline void TAST(bool exp, str msg) {if(!exp){EPR(msg);} while(!exp){}}

struct CumSum {
    vi csum;
    int N;
    CumSum(IN(vi) A) {
        self.N = A.size();
        self.csum = vi(self.N+1, 0);
        FOR(i, 1, N+1)
            self.csum[i] = self.csum[i-1] + A[i-1];
    }
    int sum(int l, int r) {
        r = min(r, self.N);
        l = max(l, (int)0);
        if (l >= r) return 0;
        return csum[r] - csum[l];
    }
};


int32 main(int32 argc, char* argv[]) {
    FASTCIN();
    DEBUG_IMPORT("sample-1");


    int N; cin>>N;
    string S; cin>>S;
    vi R(N,0), G(N,0), B(N,0);
    REP(i, N) {
        if (S[i] == 'R') {
            R[i] = 1;
        } else if (S[i] == 'G') {
            G[i] = 1;
        } else if (S[i] == 'B') {
            B[i] = 1;
        } else {
            AST(false, "来ない1");
        }
    }

    var csumr = CumSum(R);
    var csumg = CumSum(G);
    var csumb = CumSum(B);

    int ans = 0;
    REP(i,N-2) {
        FOR(j,i+1, N-1){
            if (S[j] == S[i])
                continue;

            AST(S[j] != S[i], "S[j] != S[i");
            int dist1 = j - i;
            AST(dist1>0, "dist1>0");
            if ((S[i] == 'R' and S[j] =='G') or
                (S[i] == 'G' and S[j] =='R')) {
                ans += csumb.sum(j+1, j+dist1) + csumb.sum(j+dist1+1, N); // [j+1, j+dist1) [j+dist1+1, N) の B を足す
            } else if ((S[i] == 'G' and S[j] =='B') or
                       (S[i] == 'B' and S[j] =='G')) {
                ans += csumr.sum(j+1, j+dist1) + csumr.sum(j+dist1+1, N); // [j+1, j+dist1) [j+dist1+1, N) の R を足す
            } else if ((S[i] == 'B' and S[j] =='R') or
                       (S[i] == 'R' and S[j] =='B')) {
                ans += csumg.sum(j+1, j+dist1) + csumg.sum(j+dist1+1, N); // [j+1, j+dist1) [j+dist1+1, N) の G を足す
            } else {
                AST(false, "来ない2");
            }
        }
    }

    cout << ans << endl;


    return 0;
}


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