Language: C++

#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,sse4.1,sse4.2,popcnt,abm,mmx,avx,tune=native")
// #pragma comment(linker, "/stack:200000000"]
 
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <unordered_set>
#include <unordered_map>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <bitset>
#include <stack>
#include <random>
#include <fstream>
#include <sstream>
#include <chrono>

#define fi first
#define se second
#define pb push_back
#define ll long long
#define ld long double
#define hm unordered_map 
#define pii pair<int, int>
#define sz(a) (int)a.size()
#define all(a) a.begin(), a.end()
#define cinv(v) for (auto& x: v) cin >> x
#define fr(i, n) for (int i = 0; i < n; ++i)
#define fl(i, l, n) for (int i = l; i < n; ++i)

#define int ll

using namespace std;

#ifdef __LOCAL
	#define dbg(x) cerr << #x << " : " << x << '\n'
	const int maxn = 20;
#else 
	#define dbg(x)
	const int maxn = 2e5 + 20;
#endif

//tg: @galebickosikasa
 
const ll inf = (ll) 2e9;
const ld pi = asin (1) * 2;
const ld eps = 1e-8;
const ll mod = (ll)1e9 + 7;
const ll ns = 97;

mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());



signed main () {
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);
	int n;
	string s;
	cin >> n >> s;
	vector<int> _a (n), _b (n), _c (n), a (n), b (n), c (n);
	int ans = 0;
	fr (i, n) {
		if (s[i] == 'R') _a[i] = 1;
		else if (s[i] == 'G') _b[i] = 1;
		else _c[i] = 1;
	}
	reverse (all (_a)), reverse (all (_b)), reverse (all (_c));
	partial_sum (all (_a), a.begin ()), partial_sum (all (_b), b.begin ()), partial_sum (all (_c), c.begin ());
	reverse (all (a)), reverse (all (b)), reverse (all (c));
	fr (i, n) {
		fl (j, i + 1, n) {
			map <char, int> kek;
			kek[s[i]] = kek[s[j]] = 1;
			if (sz (kek) != 2) continue;
			if (!kek.count ('R')) {
				ans += a[j];
				if (2 * j - i < n && s[2 * j - i] == 'R') --ans;
			}
			if (!kek.count ('G')) {
				ans += b[j];
				if (2 * j - i < n && s[2 * j - i] == 'G') --ans;
			}
			if (!kek.count ('B')) {
				ans += c[j];
				if (2 * j - i < n && s[2 * j - i] == 'B') --ans;
			}
		}
	}
	cout << ans;







}

Compiler output:
In file included from /usr/include/c++/14/string:43,
                 from /usr/include/c++/14/bits/locale_classes.h:40,
                 from /usr/include/c++/14/bits/ios_base.h:41,
                 from /usr/include/c++/14/ios:44,
                 from /usr/include/c++/14/ostream:40,
                 from /usr/include/c++/14/iostream:41,
                 from a.cc:5:
/usr/include/c++/14/bits/allocator.h: In destructor 'std::__cxx11::basic_string<char>::_Alloc_hider::~_Alloc_hider()':
/usr/include/c++/14/bits/allocator.h:182:7: error: inlining failed in call to 'always_inline' 'std::allocator< <template-parameter-1-1> >::~allocator() noexcept [with _Tp = char]': target specific option mismatch
  182 |       ~allocator() _GLIBCXX_NOTHROW { }
      |       ^
In file included from /usr/include/c++/14/string:54:
/usr/include/c++/14/bits/basic_string.h:186:14: note: called from here
  186 |       struct _Alloc_hider : allocator_type // TODO check __is_final
      |              ^~~~~~~~~~~~