Language: C++

#pragma GCC optimize("Ofast")

//インクルード
#include<algorithm>//sort,二分探索,など
#include<bitset>//固定長bit集合
#include<cmath>//pow,logなど
#include<complex>//複素数
#include<deque>//両端アクセスのキュー
#include<functional>//sortのgreater
#include<iomanip>//setprecision(浮動小数点の出力の誤差)
#include<iostream>//入出力
#include<map>//map(辞書)
#include<numeric>//iota(整数列の生成),gcdとlcm(c++17)
#include<queue>//キュー
#include<set>//集合
#include<stack>//スタック
#include<string>//文字列
#include<unordered_map>//イテレータあるけど順序保持しないmap
#include<unordered_set>//イテレータあるけど順序保持しないset
#include<utility>//pair
#include<vector>//可変長配列

using namespace std;
typedef long long ll;

//マクロ
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=(a);i<=(b);i++)
#define FORD(i,a,b) for(ll i=(a);i>=(b);i--)
#define ALL(x) (x).begin(),(x).end() //sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size()) //sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x))
#define INF 1000000000000 //10^12
#define MOD 10000007 //10^9+7
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define MAXR 100000 //10^5:最大のrange(素数列挙などで使用)

int main() {
  // 高速化
    std::ios::sync_with_stdio(false);
    std::cin.tie(0);

    ll n;
    string s;

    cin >> n;
    cin >> s;
    ll ans = 0;

    ll g[n][2];
    ll b[n][2];
    ll r[n][2];

    ll rc, bc, gc = 0;
    FOR(i, 0, n-1){
      r[i][0] = false;
      r[i][1] = 0;
      g[i][0] = false;
      g[i][1] = 0;
      b[i][0] = false;
      b[i][1] = 0;
    }

    FORD(i, n-1, 0){
      if(s[i] == 'R'){
        r[i][0] = true;
        r[i][1] = rc;
        rc++;
      }else if(s[i] == 'G'){
        g[i][0] = true;
        g[i][1] = gc;
        gc++;
      }else{
        b[i][0] = true;
        b[i][1] = bc;
        bc++;
      }
    }


  FOR(x, 0, n-1){
    if(s[x] == 'R'){
      ll y =0;

      FOR(j, r[x]+1, n-1){
        if(g[j][0] ){
          y = g[j][0];
          break;
        }
      }
      FOR(z, y+1, n-1){
        if(b[z][0] ){
          ans+= b[z][1];
          if(abs(y-x) == abs(z-y)){
            ans--;
          }
          break;
        }
      }

      y =0;
      FOR(j, r[x]+1, n-1){
        if(b[j][0] ){
          y = b[j][0];
          break;
        }
      }
      FOR(z, y+1, n-1){
        if(g[z][0]){
          ans+= g[z][1];
          if(abs(y-x) == abs(z-y)){
            ans--;
          }
          break;
        }
      }


    }else if(s[i] == 'G'){
      FOR(j, g[x]+1, n-1){
        if(r[j][0]){
          y = r[j][0];
          break;
        }
      }
      FOR(z, y+1, n-1){
        if(b[z][0]){
          ans+= b[z][1];
          if(abs(y-x) == abs(z-y)){
            ans--;
          }
          break;
        }
      }

      y =0;
      FOR(j, r[x]+1, n-1){
        if(b[j][0]){
          y = b[j][0];
          break;
        }
      }
      FOR(z, y+1, n-1){
        if(r[z][0]){
          ans+= r[z][1];
          if(abs(y-x) == abs(z-y)){
            ans--;
          }
          break;
        }
      }
    }else{
      FOR(j, b[x]+1, n-1){
        if(r[j][0]){
          y = r[j][0];
          break;
        }
      }
      FOR(z, y+1, n-1){
        if(g[z][0]){
          ans+= g[z][1];
          if(abs(y-x) == abs(z-y)){
            ans--;
          }
          break;
        }
      }

      y =0;
      FOR(j, r[x]+1, n-1){
        if(g[j][0] == true;){
          y = g[j][0];
          break;
        }
      }
      FOR(z, y+1, n-1){
        if(r[z][0] == true;){
          ans+= r[z][1];
          if(abs(y-x) == abs(z-y)){
            ans--;
          }
          break;
        }
      }
    }
  }

    cout << ans << "\n"; 

    return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:89:18: error: invalid conversion from 'll*' {aka 'long long int*'} to 'll' {aka 'long long int'} [-fpermissive]
   89 |       FOR(j, r[x]+1, n-1){
      |                  ^
      |                  |
      |                  ll* {aka long long int*}
a.cc:29:30: note: in definition of macro 'FOR'
   29 | #define FOR(i,a,b) for(ll i=(a);i<=(b);i++)
      |                              ^
a.cc:106:18: error: invalid conversion from 'll*' {aka 'long long int*'} to 'll' {aka 'long long int'} [-fpermissive]
  106 |       FOR(j, r[x]+1, n-1){
      |                  ^
      |                  |
      |                  ll* {aka long long int*}
a.cc:29:30: note: in definition of macro 'FOR'
   29 | #define FOR(i,a,b) for(ll i=(a);i<=(b);i++)
      |                              ^
a.cc:123:16: error: 'i' was not declared in this scope
  123 |     }else if(s[i] == 'G'){
      |                ^
a.cc:124:18: error: invalid conversion from 'll*' {aka 'long long int*'} to 'll' {aka 'long long int'} [-fpermissive]
  124 |       FOR(j, g[x]+1, n-1){
      |                  ^
      |                  |
      |                  ll* {aka long long int*}
a.cc:29:30: note: in definition of macro 'FOR'
   29 | #define FOR(i,a,b) for(ll i=(a);i<=(b);i++)
      |                              ^
a.cc:126:11: error: 'y' was not declared in this scope
  126 |           y = r[j][0];
      |           ^
a.cc:130:14: error: 'y' was not declared in this scope
  130 |       FOR(z, y+1, n-1){
      |              ^
a.cc:29:30: note: in definition of macro 'FOR'
   29 | #define FOR(i,a,b) for(ll i=(a);i<=(b);i++)
      |                              ^
a.cc:140:7: error: 'y' was not declared in this scope
  140 |       y =0;
      |       ^
a.cc:141:18: error: invalid conversion from 'll*' {aka 'long long int*'} to 'll' {aka 'long long int'} [-fpermissive]
  141 |       FOR(j, r[x]+1, n-1){
      |                  ^
      |                  |
      |                  ll* {aka long long int*}
a.cc:29:30: note: in definition of macro 'FOR'
   29 | #define FOR(i,a,b) for(ll i=(a);i<=(b);i++)
      |                              ^
a.cc:157:18: error: invalid conversion from 'll*' {aka 'long long int*'} to 'll' {aka 'long long int'} [-fpermissive]
  157 |       FOR(j, b[x]+1, n-1){
      |                  ^
      |                  |
      |                  ll* {aka long long int*}
a.cc:29:30: note: in definition of macro 'FOR'
   29 | #define FOR(i,a,b) for(ll i=(a);i<=(b);i++)
      |                              ^
a.cc:159:11: error: 'y' was not declared in this scope
  159 |           y = r[j][0];
      |           ^
a.cc:163:14: error: 'y' was not declared in this scope
  163 |       FOR(z, y+1, n-1){
      |              ^
a.cc:29:30: note: in definition of macro 'FOR'
   29 | #define FOR(i,a,b) for(ll i=(a);i<=(b);i++)
      |                              ^
a.cc:173:7: error: 'y' was not declared in this scope
  173 |       y =0;
      |       ^
a.cc:174:18: error: invalid conversion from 'll*' {aka 'long long int*'} to 'll' {aka 'long long int'} [-fpermissive]
  174 |       FOR(j, r[x]+1, n-1){
      |                  ^
      |                  |
      |                  ll* {aka long long int*}
a.cc:29:30: note: in definition of macro 'FOR'
   29 | #define FOR(i,a,b) for(ll i=(a);i<=(b);i++)
      |                              ^
a.cc:175:28: error: expected primary-expression before ')' token
  175 |         if(g[j][0] == true;){
      |                            ^
a.cc:181:28: error: expected primary-expression before ')' token
  181 |         if(r[z][0] == true;){
      |                            ^