Language: C++

#include<iostream>
#include<stdio.h>
#include <string>
using namespace std;
int stringcount(string s, char c) {
    return count(s.cbegin(), s.cend(), c);
}
int main(){
	int a;
	cin >> a;
	//文字列入力
	string s;
	cin >> s;
	char temp[2];
	long long int sum=0;
	char R[2] = "R",G[2] = "G",B[2] = "B";
	string substr;
	//三項gcdの総和を返す
	for(int i = 0; i < a-1; i++){
		for(int j = i+1; j <a-1; j++){
			if(s[i] == s[j])continue;
			//kは文字数を数えた方がいい。
			//j-i+j == kだったら一ひく
			//s[k]以降のtempの数を数えて欲しい
			if(strncmp(&s[i],R,1) == 0){
				if(strncmp(&s[j],G,1) == 0) strcpy(temp,B);
				else strcpy(temp,G);

			}else if(strncmp(&s[i],B,1) == 0){
				if(strncmp(&s[j],G,1) == 0) strcpy(temp,R);
				else strcpy(temp,G);

			}else{
				if(strncmp(&s[j],R,1) == 0) strcpy(temp,B);
				else strcpy(temp,R);
			}
			//等間隔だったら一個減らす
			if(2*j-i < a && strncmp(&s[2*j-i],temp,1) == 0){
				//cout << "!" << endl;
				sum -= 1;
			}
			//それ以降の文字数を数える
			//cout <<"s[i],s[j]="<< s[i] << s[j] << endl;
			substr = s.substr(j+1);
			//cout << substr << endl;
			//cout << stringcount(substr,temp[0]) << endl;
			sum += stringcount(substr,temp[0]);
		}
	}

	cout << sum << endl;
	return 0;
}

Compiler output:
a.cc: In function 'int stringcount(std::string, char)':
a.cc:6:12: error: 'count' was not declared in this scope
    6 |     return count(s.cbegin(), s.cend(), c);
      |            ^~~~~
a.cc: In function 'int main()':
a.cc:25:28: error: 'strncmp' was not declared in this scope
   25 |                         if(strncmp(&s[i],R,1) == 0){
      |                            ^~~~~~~
a.cc:2:1: note: 'strncmp' is defined in header '<cstring>'; this is probably fixable by adding '#include <cstring>'
    1 | #include<iostream>
  +++ |+#include <cstring>
    2 | #include<stdio.h>
a.cc:26:61: error: 'strcpy' was not declared in this scope
   26 |                                 if(strncmp(&s[j],G,1) == 0) strcpy(temp,B);
      |                                                             ^~~~~~
a.cc:26:61: note: 'strcpy' is defined in header '<cstring>'; this is probably fixable by adding '#include <cstring>'
a.cc:27:38: error: 'strcpy' was not declared in this scope
   27 |                                 else strcpy(temp,G);
      |                                      ^~~~~~
a.cc:27:38: note: 'strcpy' is defined in header '<cstring>'; this is probably fixable by adding '#include <cstring>'
a.cc:30:61: error: 'strcpy' was not declared in this scope
   30 |                                 if(strncmp(&s[j],G,1) == 0) strcpy(temp,R);
      |                                                             ^~~~~~
a.cc:30:61: note: 'strcpy' is defined in header '<cstring>'; this is probably fixable by adding '#include <cstring>'
a.cc:31:38: error: 'strcpy' was not declared in this scope
   31 |                                 else strcpy(temp,G);
      |                                      ^~~~~~
a.cc:31:38: note: 'strcpy' is defined in header '<cstring>'; this is probably fixable by adding '#include <cstring>'
a.cc:34:61: error: 'strcpy' was not declared in this scope
   34 |                                 if(strncmp(&s[j],R,1) == 0) strcpy(temp,B);
      |                                                             ^~~~~~
a.cc:34:61: note: 'strcpy' is defined in header '<cstring>'; this is probably fixable by adding '#include <cstring>'
a.cc:35:38: error: 'strcpy' was not declared in this scope
   35 |                                 else strcpy(temp,R);
      |                                      ^~~~~~
a.cc:35:38: note: 'strcpy' is defined in header '<cstring>'; this is probably fixable by adding '#include <cstring>'
a.cc:38:41: error: 'strncmp' was not declared in this scope
   38 |                         if(2*j-i < a && strncmp(&s[2*j-i],temp,1) == 0){
      |                                         ^~~~~~~
a.cc:38:41: note: 'strncmp' is defined in header '<cstring>'; this is probably fixable by adding '#include <cstring>'