Language: C

/*
    WRITER:kakitamasziru/OxOmisosiru
*/
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <iomanip>
#include <limits>//setprecision
//#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <math.h>//pow,,,
#include <cmath>//abs,,,
//#include <unordered_map> // unordered_map
//#include <unordered_set> // unordered_set
#include <bitset> // bitset
//#include <cctype> // isupper, islower, isdigit, toupper, tolower
//It is so troublesome that I include bits/stdc++.h !
using namespace std;

template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
const int INF = 1001001000;
const int MOD = 1000000007;
typedef pair<long,long> P;
//NのM乗を求める(繰り返し二乗法)
long long mod_pow(long long N, long long M) {
    if (M == 0) return 1;
    long long res = mod_pow((N * N) % MOD, M / 2);
    //最下位ビット(*N)が1の時は単独でNをかける
    if (M & 1) res = (res * N) % MOD;

    return res %= MOD;
}
long long nCr(long long n, long long r) {
    long long A = 1, B = 1;
    //Aが分子Bが1/r!
    //n!はi = 1;i<=nでする
    for (long long i = n-r+1; i <= n; i++) {
        A = A * i % MOD;
    }
    for (long long i = 1; i <= r; i++) {
        B = B * i % MOD;
    }
    B = mod_pow(B, MOD - 2);
    B %= MOD;
    //Bは割るのではなく掛ける
    return (A * B) % MOD;
}

long long gcd(long long a, long long b) {
    if (b == 0) return a;
    else return gcd(b, a % b);
}
long long lcm(long long a, long long b) {
    return a * b / gcd(a, b);
}

int ruiR[4005],ruiG[4005],ruiB[4005];

int main() {
    int N;cin >> N;
    string S;cin >> S;
    int count = 0;
    for(int i = 0;i<N;i++){
        if(S.at(i) == 'R'){
            ruiR[i+1] = ruiR[i]+1;
            ruiG[i+1] = ruiG[i];
            ruiB[i+1] = ruiB[i];
        }
        if(S.at(i) == 'G'){
            ruiG[i+1] = ruiG[i]+1;
            ruiR[i+1] = ruiR[i];
            ruiB[i+1] = ruiB[i];
        }
        if(S.at(i) == 'B'){
            ruiB[i+1] = ruiB[i]+1;
            ruiG[i+1] = ruiG[i];
            ruiR[i+1] = ruiR[i];
        }
    }
    /*for(int i = 0;i<N;i++) cout << ruiR[i];
    for(int i = 0;i<N;i++) cout << ruiG[i];
    for(int i = 0;i<N;i++) cout << ruiB[i];*/
    int ans = 0;
    bool ok = true;
    for(int i = 0;i<N;i++){
        for(int j = i;j<N;j++){
            ok = true;
            if(i == j) continue;
            if(j == N-1) continue;
            char a = S.at(i);
            char b = S.at(j);
            char c;
            int sa = j-i;
            if(sa+j >= N) ok = false;
            //if(j+sa ) continue;
            if(a == b) continue;
            if(a == 'R' && b == 'G'){
                c = 'B';
                ans += ruiB[N]-ruiB[j];
                if(!ok) continue;
                if(S.at(j+sa) == 'B')ans--;
                
            }
            if(a == 'R' && b == 'B') {
                c = 'G';
                ans += ruiG[N]-ruiG[j];
                if(!ok) continue;
                if(S.at(j+sa) == 'G')ans--;
                
            }
            if(a == 'B' && b == 'R'){
                c = 'G';
                ans += ruiG[N]-ruiG[j];
                if(!ok) continue;
                if(S.at(j+sa) == 'G')ans--;
                
            } 
            if(a == 'G' && b == 'R'){
                c = 'B';
                ans += ruiB[N]-ruiB[j];
                if(!ok) continue;
                if(S.at(j+sa) == 'B')ans--;
               
            }
            if(a == 'G' && b == 'B') {
                c = 'R';
                ans += ruiR[N]-ruiR[j];
                if(!ok) continue;
                if(S.at(j+sa) == 'R')ans--;
                
            }
            if(a == 'B' && b == 'G'){
                c = 'R';
                ans += ruiR[N]-ruiR[j];
                if(!ok) continue;
                if(S.at(j+sa) == 'R')ans--;
                
            } 
        }
    }

    cout << ans << endl;
}

Compiler output:
main.c:4:10: fatal error: iostream: No such file or directory
    4 | #include <iostream> // cout, endl, cin
      |          ^~~~~~~~~~
compilation terminated.