Language: C++

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <string>
#include <vector>
#include <algorithm>
#include <set>
#include <queue>
#include <deque>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;

#define rep(i, up) for (ll i = 0; i < up; ++i)
#define repp(i, up) for (ll i = 0; i <= up; ++i)
#define rrep(i, lo, up) for (ll i = lo; i < up; ++i)
#define rrepp(i, lo, up) for (ll i = lo; i <= up; ++i)

#define rdi(i) ll i; scanf("%lld", &i)
#define rds(s) string s; cin >> s
#define rdc(c) char c; cin >> c

#define INF 10000000000

ll calc(const vector<ll> & is, const vector<ll> & js, const vector<ll> & ks)
{
    ll result = 0;
    for (auto iti = is.begin(); iti != is.end(); ++iti) {
        for (auto itj = upper_bound(js.begin(), js.end(), *iti); itj != js.end(); ++itj) {
            auto itk = upper_bound(ks.begin(), ks.end(), *itj);
            if (itk == ks.end()) {
                continue;
            }
            auto tmp = *itj + (*itj - *iti);
            auto it = lower_bound(ks.begin(), ks.end(), tmp);
            if (it != ks.end() && *it == tmp) {
                result += max(0, ks.end() - itk - 1);
            } else {
                result += ks.end() - itk;
            }
        }
    }
    return result;
}

int main()
{
    ll n;
    string s;
    cin >> n >> s;
    vector<ll> rs, gs, bs;
    rep(i, n) {
        switch (s[i]) {
        case 'R':
            rs.push_back(i);
            break;
        case 'G':
            gs.push_back(i);
            break;
        case 'B':
            bs.push_back(i);
            break;
        }
    }
    ll result = 0;
    result += calc(rs, gs, bs);
    result += calc(gs, bs, rs);
    result += calc(bs, rs, gs);
    result += calc(rs, bs, gs);
    result += calc(gs, rs, bs);
    result += calc(bs, gs, rs);
    cout << result;
    return 0;
}

Compiler output:
a.cc: In function 'll calc(const std::vector<long long int>&, const std::vector<long long int>&, const std::vector<long long int>&)':
a.cc:39:30: error: no matching function for call to 'max(int, __gnu_cxx::__normal_iterator<const long long int*, std::vector<long long int> >::difference_type)'
   39 |                 result += max(0, ks.end() - itk - 1);
      |                           ~~~^~~~~~~~~~~~~~~~~~~~~~~
In file included from /usr/include/c++/14/string:51,
                 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:1:
/usr/include/c++/14/bits/stl_algobase.h:257:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::max(const _Tp&, const _Tp&)'
  257 |     max(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:257:5: note:   template argument deduction/substitution failed:
a.cc:39:30: note:   deduced conflicting types for parameter 'const _Tp' ('int' and '__gnu_cxx::__normal_iterator<const long long int*, std::vector<long long int> >::difference_type' {aka 'long int'})
   39 |                 result += max(0, ks.end() - itk - 1);
      |                           ~~~^~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:303:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::max(const _Tp&, const _Tp&, _Compare)'
  303 |     max(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:303:5: note:   candidate expects 3 arguments, 2 provided
In file included from /usr/include/c++/14/algorithm:61,
                 from a.cc:7:
/usr/include/c++/14/bits/stl_algo.h:5706:5: note: candidate: 'template<class _Tp> constexpr _Tp std::max(initializer_list<_Tp>)'
 5706 |     max(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5706:5: note:   candidate expects 1 argument, 2 provided
/usr/include/c++/14/bits/stl_algo.h:5716:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::max(initializer_list<_Tp>, _Compare)'
 5716 |     max(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5716:5: note:   template argument deduction/substitution failed:
a.cc:39:30: note:   mismatched types 'std::initializer_list<_Tp>' and 'int'
   39 |                 result += max(0, ks.end() - itk - 1);
      |                           ~~~^~~~~~~~~~~~~~~~~~~~~~~