Language: C++

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define sz(v) v.size()
#define INF 100000000000000 //10^14 100兆
// aよりもbが大きいならばaをbで更新する
// (更新されたならばtrueを返す)
template <typename T>
bool chmax(T &a, const T& b) {
  if (a < b) {
    a = b;  // aをbで更新
    return true;
  }
  return false;
}
// aよりもbが小さいならばaをbで更新する
// (更新されたならばtrueを返す)
template <typename T>
bool chmin(T &a, const T& b) {
  if (a > b) {
    a = b;  // aをbで更新
    return true;
  }
  return false;
}

unsigned euclidean_gcd(unsigned a, unsigned b) {
  if(a < b) return euclidean_gcd(b, a);
  unsigned r;
  while ((r=a%b)) {
    a = b;
    b = r;
  }
  return b;
}

int main(){
  ll N;
  string S;
  cin >> N >> S;
  vector<ll> R(N+1, 0), G(N+1, 0), B(N+1, 0);
  rep(i, N){
    if(S.at(i) == 'R'){
      R.at(i+1) = R.at(i)+1;
      G.at(i+1) = G.at(i);
      B.at(i+1) = B.at(i);
    }
    if(S.at(i) == 'G'){
      R.at(i+1) = R.at(i);
      G.at(i+1) = G.at(i)+1;
      B.at(i+1) = B.at(i);
    }
    if(S.at(i) == 'B'){
      R.at(i+1) = R.at(i);
      G.at(i+1) = G.at(i);
      B.at(i+1) = B.at(i)+1;
    }
  }
  ll ans = 0;
  rep2(i, 1, N-1){
    if(S.at(i) == 'R'){
      ll eq = 0;
      rep2(j, 1, min(i, N-i-1)+1){
        if(S.at(i-j) == 'G' && S.at(i+j) == 'B'){
          eq++;
        }
        if(S.at(i-j) == 'B' && S.at(i+j) == 'G'){
          eq++;
        }
      }
      ans += G.at(i) * (B.at(N) - B.at(i+1)) + B.at(i) * (G.at(N) - G.at(i+1)) - eq;
    }
    if(S.at(i) == 'G'){
      ll eq = 0;
      rep2(j, 1, min(i, N-i-1)+1){
        if(S.at(i-j) == 'B' && S.at(i+j) == 'R'){
          eq++;
        }
        if(S.at(i-j) == 'R' && S.at(i+j) == 'B'){
          eq++;
        }
      }
      ans += B.at(i) * (R.at(N) - R.at(i+1)) + R.at(i) * (B.at(N) - B.at(i+1)) - eq;
    }
    if(S.at(i) == 'B'){
      ll eq = 0;
      rep2(j, 1, min(i, N-i-1)+1){
        if(S.at(i-j) == 'R' && S.at(i+j) == 'G'){
          eq++;
        }
        if(S.at(i-j) == 'G' && S.at(i+j) == 'R'){
          eq++;
        }
      }
      ans += R.at(i) * (G.at(N) - G.at(i+1)) + G.at(i) * (R.at(N) - R.at(i+1)) - eq;
    }
  }
  cout << ans << endl;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:66:21: error: no matching function for call to 'min(int&, ll)'
   66 |       rep2(j, 1, min(i, N-i-1)+1){
      |                  ~~~^~~~~~~~~~
a.cc:5:51: note: in definition of macro 'rep2'
    5 | #define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
      |                                                   ^
In file included from /usr/include/c++/14/algorithm:60,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:51,
                 from a.cc:1:
/usr/include/c++/14/bits/stl_algobase.h:233:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::min(const _Tp&, const _Tp&)'
  233 |     min(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:233:5: note:   template argument deduction/substitution failed:
a.cc:66:21: note:   deduced conflicting types for parameter 'const _Tp' ('int' and 'll' {aka 'long long int'})
   66 |       rep2(j, 1, min(i, N-i-1)+1){
      |                  ~~~^~~~~~~~~~
a.cc:5:51: note: in definition of macro 'rep2'
    5 | #define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
      |                                                   ^
/usr/include/c++/14/bits/stl_algobase.h:281:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::min(const _Tp&, const _Tp&, _Compare)'
  281 |     min(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:281:5: note:   candidate expects 3 arguments, 2 provided
In file included from /usr/include/c++/14/algorithm:61:
/usr/include/c++/14/bits/stl_algo.h:5686:5: note: candidate: 'template<class _Tp> constexpr _Tp std::min(initializer_list<_Tp>)'
 5686 |     min(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5686:5: note:   candidate expects 1 argument, 2 provided
/usr/include/c++/14/bits/stl_algo.h:5696:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::min(initializer_list<_Tp>, _Compare)'
 5696 |     min(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5696:5: note:   template argument deduction/substitution failed:
a.cc:66:21: note:   mismatched types 'std::initializer_list<_Tp>' and 'int'
   66 |       rep2(j, 1, min(i, N-i-1)+1){
      |                  ~~~^~~~~~~~~~
a.cc:5:51: note: in definition of macro 'rep2'
    5 | #define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
      |                                                   ^
a.cc:78:21: error: no matching function for call to 'min(int&, ll)'
   78 |       rep2(j, 1, min(i, N-i-1)+1){
      |                  ~~~^~~~~~~~~~
a.cc:5:51: note: in definition of macro 'rep2'
    5 | #define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
      |                                                   ^
/usr/include/c++/14/bits/stl_algobase.h:233:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::min(const _Tp&, const _Tp&)'
  233 |     min(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:233:5: note:   template argument deduction/substitution failed:
a.cc:78:21: note:   deduced conflicting types for parameter 'const _Tp' ('int' and 'll' {aka 'long long int'})
   78 |       rep2(j, 1, min(i, N-i-1)+1){
      |                  ~~~^~~~~~~~~~
a.cc:5:51: note: in definition of macro 'rep2'
    5 | #define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
      |                                                   ^
/usr/include/c++/14/bits/stl_algobase.h:281:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::min(const _Tp&, const _Tp&, _Compare)'
  281 |     min(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:281:5: note:   candidate expects 3 arguments, 2 provided
/usr/include/c++/14/bits/stl_algo.h:5686:5: note: candidate: 'template<class _Tp> constexpr _Tp std::min(initializer_list<_Tp>)'
 5686 |     min(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5686:5: note:   candidate expects 1 argument, 2 provided
/usr/include/c++/14/bits/stl_algo.h:5696:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::min(initializer_list<_Tp>, _Compare)'
 5696 |     min(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5696:5: note:   template argument deduction/substitution failed:
a.cc:78:21: note:   mismatched types 'std::initializer_list<_Tp>' and 'int'
   78 |       rep2(j, 1, min(i, N-i-1)+1){
      |                  ~~~^~~~~~~~~~
a.cc:5:51: note: in definition of macro 'rep2'
    5 | #define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
      |                                                   ^
a.cc:90:21: error: no matching function for call to 'min(int&, ll)'
   90 |       rep2(j, 1, min(i, N-i-1)+1){
      |                  ~~~^~~~~~~~~~
a.cc:5:51: note: in definition of macro 'rep2'
    5 | #define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
      |                                                   ^
/usr/include/c++/14/bits/stl_algobase.h:233:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::min(const _Tp&, const _Tp&)'
  233 |     min(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:233:5: note:   template argument deduction/substitution failed:
a.cc:90:21: note:   deduced conflicting types for parameter 'const _Tp' ('int' and 'll' {aka 'long long int'})
   90 |       rep2(j, 1, min(i, N-i-1)+1){
      |                  ~~~^~~~~~~~~~
a.cc:5:51: note: in definition of macro 'rep2'
    5 | #define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
      |                                                   ^
/usr/include/c++/14/bits/stl_algobase.h:281:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::min(const _Tp&, const _Tp&, _Compare)'
  281 |     min(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:281:5: note:   candidate expects 3 arguments, 2 provided
/usr/include/c++/14/bits/stl_algo.h:5686:5: note: candidate: 'template<class _Tp> constexpr _Tp std::min(initializer_list<_Tp>)'
 5686 |     min(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5686:5: note:   candidate expects 1 argument, 2 provided
/usr/include/c++/14/bits/stl_algo.h:5696:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::min(initializer_list<_Tp>, _Compare)'
 5696 |     min(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5696:5: note:   template argument deduction/substitution failed:
a.cc:90:21: note:   mismatched types 'std::initializer_list<_Tp>' and 'int'
   90 |       rep2(j, 1, min(i, N-i-1)+1){
      |                  ~~~^~~~~~~~~~
a.cc:5:51: note: in definition of macro 'rep2'
    5 | #define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
      |                                                   ^