Language: C++

#include <bits/stdc++.h>
//#include <ext/pb_ds/tree_policy.hpp>
//#include <ext/pb_ds/assoc_container.hpp>

using namespace std;
//using namespace __gnu_pbds;

#define ll       long long
#define PR       pair<ll, ll>
#define READ(f)  freopen(f, "r", stdin)
#define WRITE(f) freopen(f, "w", stdout)

const int N = 3e5 + 5;
const int MOD = 1e9 + 7;
const double PI = 2 * acos(0.0);
//template<typename T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

string s;
vector<ll> index[5];

ll calc(int i, int x, int y, char X, char Y) {
    ll ans = 0;
    for (int j = 0; j < index[x].size(); j++) {
        if (index[x][j] < i) continue;
        int d = index[x][j] - i;
        int l = 0, r = index[y].size() - 1, got = -1;
        while (l <= r) {
            int m = l + r >> 1;
            if (index[y][m] > index[x][j]) {
                got = m;
                r = m - 1;
            } else {
                l = m + 1;
            }
        }
        if (got == -1) continue;
        int have = (int)index[y].size() - got;
        int bad = index[x][j] + d;
        if (bad < s.size() && s[bad] == X) {
            have--;
        }
        ans += have;
    }
    for (int j = 0; j < index[y].size(); j++) {
        if (index[y][j] < i) continue;
        int d = index[y][j] - i;
        int l = 0, r = index[x].size() - 1, got = -1;
        while (l <= r) {
            int m = l + r >> 1;
            if (index[x][m] > index[y][j]) {
                got = m;
                r = m - 1;
            } else {
                l = m + 1;
            }
        }
        if (got == -1) continue;
        int have = (int)index[x].size() - got;
        int bad = index[y][j] + d;
        if (bad < s.size() && s[bad] == Y) {
            have--;
        }
        ans += have;
    }
    return ans;
}

int main() {
//    ios::sync_with_stdio(false);
//    cin.tie(0);
    int n;
    cin >> n >> s;
    for (int i = 0; i < s.size(); i++) {
        if (s[i] == 'R') {
            index[0].push_back(i);
        } else if (s[i] == 'G') {
            index[1].push_back(i);
        } else {
            index[2].push_back(i);
        }
    }
    ll ans = 0;
    for (int i = 0; i < s.size(); i++) {
        if (s[i] == 'R') {
            ans += calc(i, 1, 2, 'B', 'G');
        } else if (s[i] == 'G') {
            ans += calc(i, 0, 2, 'B', 'R');
        } else {
            ans += calc(i, 0, 1, 'G', 'R');
        }
    }
    cout << ans << '\n';
    return 0;
}


Compiler output:
a.cc:19:19: error: 'std::vector<long long int> index [5]' redeclared as different kind of entity
   19 | vector<ll> index[5];
      |                   ^
In file included from /usr/include/string.h:462,
                 from /usr/include/c++/14/cstring:43,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:121,
                 from a.cc:1:
/usr/include/strings.h:50:20: note: previous declaration 'const char* index(const char*, int)'
   50 | extern const char *index (const char *__s, int __c)
      |                    ^~~~~
a.cc: In function 'long long int calc(int, int, int, char, char)':
a.cc:23:30: error: invalid types '<unresolved overloaded function type>[int]' for array subscript
   23 |     for (int j = 0; j < index[x].size(); j++) {
      |                              ^
a.cc:24:18: error: invalid types '<unresolved overloaded function type>[int]' for array subscript
   24 |         if (index[x][j] < i) continue;
      |                  ^
a.cc:25:22: error: invalid types '<unresolved overloaded function type>[int]' for array subscript
   25 |         int d = index[x][j] - i;
      |                      ^
a.cc:26:29: error: invalid types '<unresolved overloaded function type>[int]' for array subscript
   26 |         int l = 0, r = index[y].size() - 1, got = -1;
      |                             ^
a.cc:29:22: error: invalid types '<unresolved overloaded function type>[int]' for array subscript
   29 |             if (index[y][m] > index[x][j]) {
      |                      ^
a.cc:29:36: error: invalid types '<unresolved overloaded function type>[int]' for array subscript
   29 |             if (index[y][m] > index[x][j]) {
      |                                    ^
a.cc:30:17: error: 'got' was not declared in this scope
   30 |                 got = m;
      |                 ^~~
a.cc:36:13: error: 'got' was not declared in this scope
   36 |         if (got == -1) continue;
      |             ^~~
a.cc:37:30: error: invalid types '<unresolved overloaded function type>[int]' for array subscript
   37 |         int have = (int)index[y].size() - got;
      |                              ^
a.cc:37:43: error: 'got' was not declared in this scope
   37 |         int have = (int)index[y].size() - got;
      |                                           ^~~
a.cc:38:24: error: invalid types '<unresolved overloaded function type>[int]' for array subscript
   38 |         int bad = index[x][j] + d;
      |                        ^
a.cc:44:30: error: invalid types '<unresolved overloaded function type>[int]' for array subscript
   44 |     for (int j = 0; j < index[y].size(); j++) {
      |                              ^
a.cc:45:18: error: invalid types '<unresolved overloaded function type>[int]' for array subscript
   45 |         if (index[y][j] < i) continue;
      |                  ^
a.cc:46:22: error: invalid types '<unresolved overloaded function type>[int]' for array subscript
   46 |         int d = index[y][j] - i;
      |                      ^
a.cc:47:29: error: invalid types '<unresolved overloaded function type>[int]' for array subscript
   47 |         int l = 0, r = index[x].size() - 1, got = -1;
      |                             ^
a.cc:50:22: error: invalid types '<unresolved overloaded function type>[int]' for array subscript
   50 |             if (index[x][m] > index[y][j]) {
      |                      ^
a.cc:50:36: error: invalid types '<unresolved overloaded function type>[int]' for array subscript
   50 |             if (index[x][m] > index[y][j]) {
      |                                    ^
a.cc:51:17: error: 'got' was not declared in this scope
   51 |                 got = m;
      |                 ^~~
a.cc:57:13: error: 'got' was not declared in this scope
   57 |         if (got == -1) continue;
      |             ^~~
a.cc:58:30: error: invalid types '<unresolved overloaded function type>[int]' for array subscript
   58 |         int have = (int)index[x].size() - got;
      |                              ^
a.cc:58:43: error: 'got' was not declared in this scope
   58 |         int have = (int)index[x].size() - got;
      |                                           ^~~
a.cc:59:24: error: invalid types '<unresolved overloaded function type>[int]' for array subscript
   59 |         int bad = index[y][j] + d;
      |                        ^
a.cc: In function 'int main()':
a.cc:75:18: error: invalid types '<unresolved overloaded function type>[int]' for array subscript
   75 |             index[0].push_back(i);
      |                  ^
a.cc:77:18: error: invalid types '<unresolved overloaded function type>[int]' for array subscript
   77 |             index[1].push_back(i);
      |                  ^
a.cc:79:18: error: invalid types '<unresolved overloaded function type>[int]' for array subscript
   79 |             index[2].push_back(i);
      |                  ^