#include<iostream>
#include<algorithm>
#include<string>
#include<cstring>
#include<queue>
#include<stack>
#include<deque>
#include<map>
#include<unordered_map>
#include<set>
#include<cmath>
#include<random>
using namespace std;
 
#define pb push_back
#define ff first
#define ss second
#define endl '\n'
#define fast ios::sync_with_stdio(false); cin.tie(NULL);
const double eps = 1e-6;



/////////////////////////////////////////////

void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif

////////////////////////////////

#define int long long

int getL(vector<int> &a , int x){

	int l = 0;
	int r = a.size()-1;
	int ans = r+1;
	while(l <= r){

		int mid = (l+r)/2;

		if(a[mid] >= x){

			ans = mid;
			r = mid - 1;
		}
		else l = mid + 1;
	}

	return ans;
}

bool exist(vector<int> &a , int x , int l , int r){

	while(l <= r){

		int mid = (l+r)/2;

		if(a[mid]==x)
			return true;
		else if(a[mid] > x){

			r = mid -1 ;
		}
		else l = mid + 1;
	}

	return false;
}

int getAns(vector<int> &r , vector<int> &g , vector<int> &b){

	int ans  = 0;
	int k = b.size();
	for(int i : r){

		for(int j : g){

			if(j < i)
				continue;
			int x = j - i;

			int id = getL(b , j);
			if(id==k)
				continue;
			bool ok = exist(b , j + x , id , k-1);
			// cerr<<ok<<endl;
			// cerr<<"id "<<id<<endl;
			// cerr<<"j+x "<<j+x<<endl;
			ans += (k);
			ans-=ok;
		}

	}

	return ans;
}

void solve(){

	int n;
	cin>>n;

	string s;
	cin>>s;

	vector<int> b(n+10,0) , r(n+10,0) , g(n+10,0);

	for(int i = n - 1 ; i >= 0 ; --i){

		b[i] = b[i+1];
		r[i] = r[i+1];
		g[i] = g[i+1];

		b[i]+=(s[i]=='B');
		r[i]+=(s[i]=='R');
		g[i]+=(s[i]=='G');
	}
	int ans = 0;

	for(int i = 0 ; i < n ; ++i){

		for(int j = i+1 ; j < n ; ++j){

			if(s[i]==s[j])
				continue;

			if(s[i]=='R' && s[j]=='B'){

				int x = j - i;
				x+=j;

				ans += g[j+1];
				if(x >= n)
					continue;

				if(g[x] > g[x+1])
					--ans;
			}
			else if(s[i]=='R' && s[j]=='G'){

				int x = j - i;
				x+=j;

				ans += b[j+1];
				if(x >= n)
					continue;
				if(b[x] > b[x+1])
					--ans;
			}
			else if(s[i]=='G' && s[j]=='B') {

				int x = j - i;
				x+=j;

				ans += r[j+1];
				if(x >= n)
					continue;
				if(r[x] > r[x+1])
					--ans;
			}
			else if(s[i]=='G' && s[j]=='R'){

				int x = j - i;
				x+=j;

				ans += b[j+1];
				if(x >= n)
					continue;
				if(b[x] > b[x+1])
					--ans;
			}
			else if(s[i]=='B' && s[j]=='G'){

				int x = j - i;
				x+=j;

				ans += r[j+1];
				if(x >= n)
					continue;
				if(r[x] > r[x+1])
					--ans;
			}
			else if(s[i]=='B' && s[j]=='R'){

				int x = j - i;
				x+=j;

				ans += g[j+1];
				if(x >= n)
					continue;
				if(g[x] > g[x+1])
					--ans;
			}
		}
	}

	cout<<ans<<endl;


}

signed main(){

    fast;
    int t = 1;
    //cin>>t;
    for(int i = 1 ; i <= t ; ++i){

    	solve();
    	
    	//cout<<"Case #"<<i<<": ";
    }
}


Measured memory_bytes: 3728