Language: C++

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
int cnt;
int a[4005][3];
int main(){
	int n;
	string s;
	cin>>n;//字符的个数 
	cin>>s;//s是字符串 
	
	for(int i=0;i<n;i++)
		//a[i][0]从第i个数到结尾总共有多少个R（包含第i个数） 
		for(int j=i; j<n;j++)
		{
			if(s[j]=='R') a[i][0]++; //'R'
			else if(s[j]=='G') a[i][1]++;//'G'
			else if(s[j]=='B') a[i][2]++;	//'B'
		}
	
	int i,j,k;
	for(i=0;i<n-2;i++)
	{
		for(j=i+1;j<n-1;j++)
		{//k从j+1 
			if(s[j]!=s[i]){
				//判断剩下的应该是什么颜色 
				char re;//第三种颜色字符 
				if(s[i]!='R' && s[j]!='R') re='R';
				else if(s[i]!='G' && s[j]!='G') re='G';	
				else if(s[i]!='B' && s[j]!='B') re='B';
				//如果第三种颜色是R则加上从j+1到结尾总共还有多少个R 
				if(re=='R') cnt+=a[j+1][0];
				else if(re=='G') cnt+=a[j+1][1];
				else if(re=='B') cnt+=a[j+1][2];
				//如果j+(j-i)的位置恰好是第三种颜色则数值减去1 
				if(2j-i<n && s[2j-i]==re) cnt--;
			}
		}
	}
	cout<<cnt<<endl;
	return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:38:40: error: invalid operands of types '__complex__ int' and 'int' to binary 'operator<'
   38 |                                 if(2j-i<n && s[2j-i]==re) cnt--;
      |                                    ~~~~^~
      |                                      |  |
      |                                      |  int
      |                                      __complex__ int
a.cc:38:47: error: no match for 'operator[]' (operand types are 'std::string' {aka 'std::__cxx11::basic_string<char>'} and '__complex__ int')
   38 |                                 if(2j-i<n && s[2j-i]==re) cnt--;
      |                                               ^
In file included from /usr/include/c++/14/string:54,
                 from /usr/include/c++/14/bitset:52,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:52,
                 from a.cc:1:
/usr/include/c++/14/bits/basic_string.h:1247:7: note: candidate: 'std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::const_reference std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::operator[](size_type) const [with _CharT = char; _Traits = std::char_traits<char>; _Alloc = std::allocator<char>; const_reference = const char&; size_type = long unsigned int]'
 1247 |       operator[] (size_type __pos) const _GLIBCXX_NOEXCEPT
      |       ^~~~~~~~
/usr/include/c++/14/bits/basic_string.h:1247:29: note:   no known conversion for argument 1 from '__complex__ int' to 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'}
 1247 |       operator[] (size_type __pos) const _GLIBCXX_NOEXCEPT
      |                   ~~~~~~~~~~^~~~~
/usr/include/c++/14/bits/basic_string.h:1265:7: note: candidate: 'std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::reference std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::operator[](size_type) [with _CharT = char; _Traits = std::char_traits<char>; _Alloc = std::allocator<char>; reference = char&; size_type = long unsigned int]'
 1265 |       operator[](size_type __pos)
      |       ^~~~~~~~
/usr/include/c++/14/bits/basic_string.h:1265:28: note:   no known conversion for argument 1 from '__complex__ int' to 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'}
 1265 |       operator[](size_type __pos)
      |                  ~~~~~~~~~~^~~~~