Language: C++

#include <bits/stdc++.h>
using namespace std;
#pragma GCC target("avx")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#define endl '\n'
#define lli long long int
#define rep(i, s, e) for (int i = s; i < e; i++)

int main()
{
    int N;
    cin >> N;
    string S;
    cin >> S;
    vector<int> R, G, B;
    rep(i, 0, N)
    {
        switch (S[i])
        {
        case 'R':
            R.push_back(i);
            break;
        case 'G':
            G.push_back(i);
            break;
        case 'B':
            B.push_back(i);
            break;
        default:
            break;
        }
    }
    constexpr int res = R.size() * G.size() * B.size();
    unsigned int even = 0;
    for (int r : R)
    {
        constexpr int rr = 2 * r;
        for (int g : G)
        {
            constexpr int gg = 2 * g;
            int rg = r + g;
            for (int b : B)
            {
                constexpr int bb = 2 * b;
                constexpr int br = b + r;
                constexpr int bg = b + g;
                // r<g<b
                if (gg == br)
                    even++;
                // r<b<g
                else if (bb == rg)
                    even++;
                // b<r<g
                else if (rr == bg)
                    even++;
            }
        }
    }
    cout << res - even << endl;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:34:31: error: call to non-'constexpr' function 'std::vector<_Tp, _Alloc>::size_type std::vector<_Tp, _Alloc>::size() const [with _Tp = int; _Alloc = std::allocator<int>; size_type = long unsigned int]'
   34 |     constexpr int res = R.size() * G.size() * B.size();
      |                         ~~~~~~^~
In file included from /usr/include/c++/14/vector:66,
                 from /usr/include/c++/14/functional:64,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:53,
                 from a.cc:1:
/usr/include/c++/14/bits/stl_vector.h:992:7: note: 'std::vector<_Tp, _Alloc>::size_type std::vector<_Tp, _Alloc>::size() const [with _Tp = int; _Alloc = std::allocator<int>; size_type = long unsigned int]' declared here
  992 |       size() const _GLIBCXX_NOEXCEPT
      |       ^~~~
a.cc:38:32: error: the value of 'r' is not usable in a constant expression
   38 |         constexpr int rr = 2 * r;
      |                                ^
a.cc:36:14: note: 'int r' is not const
   36 |     for (int r : R)
      |              ^
a.cc:41:36: error: the value of 'g' is not usable in a constant expression
   41 |             constexpr int gg = 2 * g;
      |                                    ^
a.cc:39:18: note: 'int g' is not const
   39 |         for (int g : G)
      |                  ^
a.cc:45:40: error: the value of 'b' is not usable in a constant expression
   45 |                 constexpr int bb = 2 * b;
      |                                        ^
a.cc:43:22: note: 'int b' is not const
   43 |             for (int b : B)
      |                      ^
a.cc:46:36: error: the value of 'b' is not usable in a constant expression
   46 |                 constexpr int br = b + r;
      |                                    ^
a.cc:43:22: note: 'int b' is not const
   43 |             for (int b : B)
      |                      ^
a.cc:47:36: error: the value of 'b' is not usable in a constant expression
   47 |                 constexpr int bg = b + g;
      |                                    ^
a.cc:43:22: note: 'int b' is not const
   43 |             for (int b : B)
      |                      ^