/*
.   Bismillahir Rahmanir Rahim
.   Author - Marajul islam
.   created- Sun Apr 12 18:23:23 2020

*/ 
#include<bits/stdc++.h>
using namespace std;


 
int sc1() {int x; scanf("%d", &x); return x;}
long long sc2() {long long x; scanf("%lld", &x); return x;}

const int mod= 1e9 + 7;
inline int add(int a, int b) {a += b; return a >= mod ? a - mod : a;}
inline int sub(int a, int b) {a -= b; return a < 0 ? a + mod : a;}
inline int mul(int a, int b) {return (long long)a * b % mod;}
 
#define F               first
#define S               second 
#define mp              make_pair
#define pb              push_back
#define pf              push_front
#define speed_up        ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define sz(x)           (int)x.size()
#define all(x)          x.begin(), x.end()
#define debug           cerr << "OK\n";
#define ub              upper_bound
#define lb              lower_bound
#define gcd(a,b)        __gcd(a,b)
#define lcm(a,b)        (a*b)/gcd(a,b)
#define Int             sc1()
#define LL              sc2()
#define For(n)          for(int i=0;i<n;i++)
#define Forj(n)         for(int j=0;j<n;j++)
#define Fork(n)         for(int k=0;k<n;k++)
#define For1(n)         for(int i=1;i<=n;i++)

typedef long long       ll;
typedef vector<int>     vi;
typedef vector<ll>      vll;
typedef pair<int, int>  pii;
typedef pair<ll, ll>    pll;
typedef vector<pii>     vpii;
typedef set <int>       si;
typedef set <ll>        sll;
typedef multiset <int>  msi;
typedef multiset <ll>   msll;
typedef map <int, int>  mi;
typedef map <ll, ll>    mll;

#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
void err(istream_iterator<string> it) {cout << endl;}
template<typename T, typename... Args> void err(istream_iterator<string> it, T a, Args... args) {
    cerr << *it << " = " << a << ", ";
    err(++it, args...);
}
  
const int inf           = (int)2e9 + 5;
const ll  Inf           = (ll)1e18 + 5;
const int N             = 5e6 + 5;
 
 
int solve() {
 	int n;
 	cin>>n;
	string s;
	cin>>s;

	ll ans=0;
	for(int i=1;i<sz(s)-1;i++){
		if(s[i]=='R'){
			int cnt =0;
			for(int j=i-1,k=i+1;;j--,k++){
				if(j<0 || k>=sz(s)) break;
				if((s[j]=='G' && s[k] =='B') || (s[j]=='B' && s[k] =='G')) cnt++;
			}
			ll g1=0,b1=0,g2=0,b2=0;
			for(int j = i-1;j>=0;j--) {
				if(s[j]=='G') g1++;
				if(s[j]=='B') b1++;
			}
			for(int j = i+1;j<sz(s);j++) {
				if(s[j]=='G') g2++;
				if(s[j]=='B') b2++;
			}
			ll pk=(g1*b2)+(g2*b1);
			pk-=cnt;
			ans+=pk;
		}
		else if(s[i]=='G'){
			int cnt =0;
			for(int j=i-1,k=i+1;;j--,k++){
				if(j<0 || k>=sz(s)) break;
				if((s[j]=='R' && s[k] =='B') || (s[j]=='B' && s[k] =='R')) cnt++;
			}
			ll g1=0,b1=0,g2=0,b2=0;
			for(int j = i-1;j>=0;j--) {
				if(s[j]=='R') g1++;
				if(s[j]=='B') b1++;
			}
			for(int j = i+1;j<sz(s);j++) {
				if(s[j]=='R') g2++;
				if(s[j]=='B') b2++;
			}
			// cout<<g1<<" "<<b1<<" "<<g2<<" "<<b2<<endl;
			ll pk=(g1*b2)+(g2*b1);
			pk-=cnt;
			ans+=pk;
		}
		else{
			int cnt =0;
			for(int j=i-1,k=i+1;;j--,k++){
				if(j<0 || k>=sz(s)) break;
				if((s[j]=='G' && s[k] =='R') || (s[j]=='R' && s[k] =='G')) cnt++;
			}
			ll g1=0,b1=0,g2=0,b2=0;
			for(int j = i-1;j>=0;j--) {
				if(s[j]=='G') g1++;
				if(s[j]=='R') b1++;
			}
			for(int j = i+1;j<sz(s);j++) {
				if(s[j]=='G') g2++;
				if(s[j]=='R') b2++;
			}
			ll pk=(g1*b2)+(g2*b1);
			pk-=cnt;
			ans+=pk;
		}
	}

	cout<<ans<<endl;
	

 
	return 0;
}
 
 
 
 
int main()
{
	speed_up;
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
 
	int test = 1, tc = 0;
	//scanf("%d", &test);
	//cin >> test;
	while (test--) {
		//printf("Case %d: ", ++tc);
		solve();
	}
 
	return 0;
 
 
 
 
}




Measured memory_bytes: 3656