#include<bits/stdc++.h> 
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp> 
#define mod 1000000007
#define mod2 998244353
#define int long long
#define endl "\n"
#define p_b push_back
#define m_p make_pair
#define fastIO ios_base::sync_with_stdio(false),cin.tie(NULL)
using namespace std;
using namespace __gnu_pbds;
template <class T> 
using _ost = tree<
		T, 
		null_type, 
		less<T>, 
		rb_tree_tag, 
        tree_order_statistics_node_update>;


int32_t main(){
 	fastIO;
	int n;cin>>n;
	string s;cin>>s;
	map<char,vector<int>> pos;
	for(int i=0;i<n;i++){
		pos[s[i]].p_b(i);
	}
	int ans=0;
	for(int i=0;i<n;i++){
		if(s[i]=='R'){
			for(int j=0;j<pos['G'].size();j++){
				if(pos['G'][j]>i){
					int diff=pos['G'][j]-i;
					ans+=pos['B'].end()-upper_bound(pos['B'].begin(),pos['B'].end(),pos['G'][j]);
					int idx=2*pos['G'][j]-i;
					if(idx<n&&s[idx]=='B')
						ans--;
					// for(int k=0;k<pos['B'].size();k++){
					// 	if(pos['B'][k]>pos['G'][j]){
					// 		if(pos['B'][k]-pos['G'][j]!=diff)
					// 			ans++;
					// 	}
					// }
				}
			}
			for(int j=0;j<pos['B'].size();j++){
				if(pos['B'][j]>i){
					int diff=pos['B'][j]-i;
					ans+=pos['G'].end()-upper_bound(pos['G'].begin(),pos['G'].end(),pos['B'][j]);
					int idx=2*pos['B'][j]-i;
					if(idx<n&&s[idx]=='G')
						ans--;					
					// for(int k=0;k<pos['G'].size();k++){
					// 	if(pos['G'][k]>pos['B'][j]){
					// 		if(pos['G'][k]-pos['B'][j]!=diff)
					// 			ans++;
					// 	}
					// }
				}
			}
		}
		else if(s[i]=='G'){
			for(int j=0;j<pos['R'].size();j++){
				if(pos['R'][j]>i){
					int diff=pos['R'][j]-i;
					ans+=pos['B'].end()-upper_bound(pos['B'].begin(),pos['B'].end(),pos['R'][j]);
					int idx=2*pos['R'][j]-i;
					if(idx<n&&s[idx]=='B')
						ans--;
					// for(int k=0;k<pos['B'].size();k++){
					// 	if(pos['B'][k]>pos['R'][j]){
					// 		if(pos['B'][k]-pos['R'][j]!=diff)
					// 			ans++;
					// 	}
					// }
				}
			}
			for(int j=0;j<pos['B'].size();j++){
				if(pos['B'][j]>i){
					int diff=pos['B'][j]-i;
					ans+=pos['R'].end()-upper_bound(pos['R'].begin(),pos['R'].end(),pos['B'][j]);
					int idx=2*pos['B'][j]-i;
					if(idx<n&&s[idx]=='R')
						ans--;
					// for(int k=0;k<pos['R'].size();k++){
					// 	if(pos['R'][k]>pos['B'][j]){
					// 		if(pos['R'][k]-pos['B'][j]!=diff)
					// 			ans++;
					// 	}
					// }
				}
			}
		}
		else if(s[i]=='B'){
			for(int j=0;j<pos['G'].size();j++){
				if(pos['G'][j]>i){
					int diff=pos['G'][j]-i;
					ans+=pos['R'].end()-upper_bound(pos['R'].begin(),pos['R'].end(),pos['G'][j]);
					int idx=2*pos['G'][j]-i;
					if(idx<n&&s[idx]=='R')
						ans--;
					// for(int k=0;k<pos['R'].size();k++){
					// 	if(pos['R'][k]>pos['G'][j]){
					// 		if(pos['R'][k]-pos['G'][j]!=diff)
					// 			ans++;
					// 	}
					// }
				}
			}
			for(int j=0;j<pos['R'].size();j++){
				if(pos['R'][j]>i){
					int diff=pos['R'][j]-i;
					ans+=pos['G'].end()-upper_bound(pos['G'].begin(),pos['G'].end(),pos['R'][j]);
					int idx=2*pos['R'][j]-i;
					if(idx<n&&s[idx]=='G')
						ans--;
					// for(int k=0;k<pos['G'].size();k++){
					// 	if(pos['G'][k]>pos['R'][j]){
					// 		if(pos['G'][k]-pos['R'][j]!=diff)
					// 			ans++;
					// 	}
					// }
				}
			}
		}
	}
	cout<<ans<<endl;
}	

Measured memory_bytes: 3696