#include <bits/stdc++.h>
using namespace std;
#define ll                      long long int
#define pb                      push_back
#define MOD                     1000000007
#define inf                     3e18
#define ld                      long double
//#define mp                      make_pair
#define vpll                    vector<pair<ll,ll>>
#define sll                     set<ll>
#define usll                    unordered_set<ll>
#define vll                     vector<ll>
#define vld                     vector<ld>
#define vvll                    vector<vector<ll>>
#define vvld                    vector<vector<ld>>
#define pll                     pair<ll,ll>
#define vvpll                   vector<vector<pair<ll,ll>>>
#define pqll                    priority_queue<ll>
#define mll                     map<ll,ll>
#define mlc                     map<ll,char>
#define um                      unordered_map
#define umll                    um<ll,ll>
#define umlc                    um<ll,char>
#define umcl                    um<char,ll>
#define all(x)                  x.begin(),x.end()
#define fi                      first
#define se                      second
#define test                    ll Testcases;cin>>Testcases;while(Testcases--)
#define fastIO                  ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define db(...)                 __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) { cerr << " "<< name << " : " << arg1 <<'\n'; }
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
    const char* comma = strchr(names + 1, ',');
    cerr.write(names, comma - names) << " : " << arg1 << " | "; __f(comma + 1, args...);
}

void inp_out()
{
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    freopen("debug.txt", "w", stderr);
    #endif
}

int main()
{
	fastIO
//	inp_out();
	ll n;
	cin>>n;
	string s;
	cin>>s;
	vvll sum(3,vll(n,0));
	ll ans=n*(n-1)*(n-2);
	ans/=6;

	if(s[0]=='R')
	{
		sum[0][0]=1;
	}
	else if(s[0]=='G')
	{
		sum[1][0]=1;
	}
	else
	{
		sum[2][0]=1;
	}

	for(ll i=1;i<n;++i)
	{
		for(ll j=0;j<3;++j)
		{
			sum[j][i]=sum[j][i-1];
		}

		if(s[i]=='R')
		{
			sum[0][i]++;
		}
		else if(s[i]=='G')
		{
			sum[1][i]++;
		}
		else
		{
			sum[2][i]++;
		}
	}

	for(ll i=0;i<n;++i)
	{
		for(ll j=i+1;j<n;++j)
		{
			if(s[i]==s[j])
			{
				ans-=(n-j-1);
			}
			else
			{
				ll cnt=0;
				if((s[i]=='R')&&(s[j]=='G'))
				{
					cnt=sum[2][n-1];
					cnt-=sum[2][j];
				}

				if((s[i]=='G')&&(s[j]=='R'))
				{
					cnt=sum[2][n-1];
					cnt-=sum[2][j];
				}

				if((s[i]=='R')&&(s[j]=='B'))
				{
					cnt=sum[1][n-1];
					cnt-=sum[1][j];
				}

				if((s[i]=='B')&&(s[j]=='R'))
				{
					cnt=sum[1][n-1];
					cnt-=sum[1][j];
				}

				if((s[i]=='B')&&(s[j]=='G'))
				{
					cnt=sum[0][n-1];
					cnt-=sum[0][j];
				}

				if((s[i]=='G')&&(s[j]=='B'))
				{
					cnt=sum[0][n-1];
					cnt-=sum[0][j];
				}

				ans-=(n-j-1-cnt);
				if(j+j-i<n)
				{
					char ch=s[j+j-i];
					if((s[i]!=ch)&&(s[j]!=ch))
						--ans;
				}
			}	
		}
	}

	cout<<ans;
	return 0;
}



Measured memory_bytes: 3716