Language: C++

using namespace std;

void Main()
{
	int n;
	string s;
	int r, b, g;
	int i, j, k, ans;

	cin >> n >> s;

	r = b = g = 0;
	for (i = 0;i < n;++i)
	{
		if (s[i] == 'R')	++r;
		if (s[i] == 'B')	++b;
		if (s[i] == 'G')	++g;
	}

	ans = r * b * g;
	for (i = 0;i < n;++i)
	{
		for (j = i + 1;j < n;++j)
		{
			k = 2 * j - i;
			if (k < n)
			{
				if ((s[i] != s[j]) && (s[j] != s[k]) && (s[k] != s[i]))
				{
					--ans;
				}
			}
		}
	}

	cout << ans << endl;
}


int main()
{
	std::cin.tie(nullptr);
	std::ios_base::sync_with_stdio(false);
	std::cout << std::fixed << std::setprecision(15);
	Main();
}

Compiler output:
a.cc: In function 'void Main()':
a.cc:6:9: error: 'string' was not declared in this scope
    6 |         string s;
      |         ^~~~~~
a.cc:1:1: note: 'std::string' is defined in header '<string>'; this is probably fixable by adding '#include <string>'
  +++ |+#include <string>
    1 | using namespace std;
a.cc:10:9: error: 'cin' was not declared in this scope
   10 |         cin >> n >> s;
      |         ^~~
a.cc:1:1: note: 'std::cin' is defined in header '<iostream>'; this is probably fixable by adding '#include <iostream>'
  +++ |+#include <iostream>
    1 | using namespace std;
a.cc:10:21: error: 's' was not declared in this scope
   10 |         cin >> n >> s;
      |                     ^
a.cc:36:9: error: 'cout' was not declared in this scope
   36 |         cout << ans << endl;
      |         ^~~~
a.cc:36:9: note: 'std::cout' is defined in header '<iostream>'; this is probably fixable by adding '#include <iostream>'
a.cc:36:24: error: 'endl' was not declared in this scope
   36 |         cout << ans << endl;
      |                        ^~~~
a.cc:1:1: note: 'std::endl' is defined in header '<ostream>'; this is probably fixable by adding '#include <ostream>'
  +++ |+#include <ostream>
    1 | using namespace std;
a.cc: In function 'int main()':
a.cc:42:14: error: 'cin' is not a member of 'std'
   42 |         std::cin.tie(nullptr);
      |              ^~~
a.cc:42:14: note: 'std::cin' is defined in header '<iostream>'; this is probably fixable by adding '#include <iostream>'
a.cc:43:14: error: 'std::ios_base' has not been declared
   43 |         std::ios_base::sync_with_stdio(false);
      |              ^~~~~~~~
a.cc:44:14: error: 'cout' is not a member of 'std'
   44 |         std::cout << std::fixed << std::setprecision(15);
      |              ^~~~
a.cc:44:14: note: 'std::cout' is defined in header '<iostream>'; this is probably fixable by adding '#include <iostream>'
a.cc:44:27: error: 'fixed' is not a member of 'std'
   44 |         std::cout << std::fixed << std::setprecision(15);
      |                           ^~~~~
a.cc:1:1: note: 'std::fixed' is defined in header '<ios>'; this is probably fixable by adding '#include <ios>'
  +++ |+#include <ios>
    1 | using namespace std;
a.cc:44:41: error: 'setprecision' is not a member of 'std'
   44 |         std::cout << std::fixed << std::setprecision(15);
      |                                         ^~~~~~~~~~~~
a.cc:1:1: note: 'std::setprecision' is defined in header '<iomanip>'; this is probably fixable by adding '#include <iomanip>'
  +++ |+#include <iomanip>
    1 | using namespace std;