Language: C++

char s[10004];
int main()
{
 int n;
 cin>>n;
 cin>>s;
 ll ans=0;
 int r[10004],g[10004],b[10004];
 int ri=0,gi=0,bi=0;
 for(int i=0;i<n;i++)
 {
  if(s[i]=='G')
  g[gi++]=i;
  else if(s[i]=='B')
  b[bi++]=i;
  else 
  r[ri++]=i;
 }
 for(int i=0;i<n;i++)
 {
  char x1=s[i];
  char x2,x3;
  for(int j=i+1;j<n;j++)
  {
   if(s[j]!=x1)
   {
    x2=s[j];
    if(x1!='G'&&x2!='G')
    {
     int y1=upper_bound(g,g+gi,j+j-i)-g;
     ans+=(ll)(gi-y1);
    }
    else if(x1!='R'&&x2!='R')
    {
     int y2=upper_bound(r,r+ri,j+j-i)-r;
     ans+=(ll)(ri-y2);
    }
    else if(x1!='B'&&x2!='B')
    {
     int y3=upper_bound(b,b+bi,j+j-i)-b;
     ans+=(ll)(bi-y3);
    }
   }
  }
 }
 char ss[10004];
 for(int i=0;i<n;i++)
 ss[i]=s[n-i-1];
 ri=0,gi=0,bi=0;
 for(int i=0;i<n;i++)
 {
  if(ss[i]=='G')
  g[gi++]=i;
  else if(ss[i]=='B')
  b[bi++]=i;
  else 
  r[ri++]=i;
 }
 for(int i=0;i<n;i++)
 {
  char x1=ss[i];
  char x2,x3;
  for(int j=i+1;j<n;j++)
  {
   if(ss[j]!=x1)
   {
    x2=ss[j];
    if(x1!='G'&&x2!='G')
    {
     int y1=upper_bound(g,g+gi,j+j-i)-g;
     ans+=(ll)(gi-y1);
    }
    else if(x1!='R'&&x2!='R')
    {
     int y2=upper_bound(r,r+ri,j+j-i)-r;
     ans+=(ll)(ri-y2);
    }
    else if(x1!='B'&&x2!='B')
    {
     int y3=upper_bound(b,b+bi,j+j-i)-b;
     ans+=(ll)(bi-y3);
    }
   }
  }
 }
 cout<<ans<<endl;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:5:2: error: 'cin' was not declared in this scope
    5 |  cin>>n;
      |  ^~~
a.cc:7:2: error: 'll' was not declared in this scope
    7 |  ll ans=0;
      |  ^~
a.cc:30:13: error: 'upper_bound' was not declared in this scope
   30 |      int y1=upper_bound(g,g+gi,j+j-i)-g;
      |             ^~~~~~~~~~~
a.cc:31:6: error: 'ans' was not declared in this scope
   31 |      ans+=(ll)(gi-y1);
      |      ^~~
a.cc:35:13: error: 'upper_bound' was not declared in this scope
   35 |      int y2=upper_bound(r,r+ri,j+j-i)-r;
      |             ^~~~~~~~~~~
a.cc:36:6: error: 'ans' was not declared in this scope
   36 |      ans+=(ll)(ri-y2);
      |      ^~~
a.cc:40:13: error: 'upper_bound' was not declared in this scope
   40 |      int y3=upper_bound(b,b+bi,j+j-i)-b;
      |             ^~~~~~~~~~~
a.cc:41:6: error: 'ans' was not declared in this scope
   41 |      ans+=(ll)(bi-y3);
      |      ^~~
a.cc:70:13: error: 'upper_bound' was not declared in this scope
   70 |      int y1=upper_bound(g,g+gi,j+j-i)-g;
      |             ^~~~~~~~~~~
a.cc:71:6: error: 'ans' was not declared in this scope
   71 |      ans+=(ll)(gi-y1);
      |      ^~~
a.cc:75:13: error: 'upper_bound' was not declared in this scope
   75 |      int y2=upper_bound(r,r+ri,j+j-i)-r;
      |             ^~~~~~~~~~~
a.cc:76:6: error: 'ans' was not declared in this scope
   76 |      ans+=(ll)(ri-y2);
      |      ^~~
a.cc:80:13: error: 'upper_bound' was not declared in this scope
   80 |      int y3=upper_bound(b,b+bi,j+j-i)-b;
      |             ^~~~~~~~~~~
a.cc:81:6: error: 'ans' was not declared in this scope
   81 |      ans+=(ll)(bi-y3);
      |      ^~~
a.cc:86:2: error: 'cout' was not declared in this scope
   86 |  cout<<ans<<endl;
      |  ^~~~
a.cc:86:8: error: 'ans' was not declared in this scope
   86 |  cout<<ans<<endl;
      |        ^~~
a.cc:86:13: error: 'endl' was not declared in this scope
   86 |  cout<<ans<<endl;
      |             ^~~~