/*input
4
RRGB
*/
#include <bits/stdc++.h>
using namespace std; 
#define int long long int
#define max(x, y) ((x) > (y) ? (x) :(y))
#define pii pair< int , int> 
#define vi vector<int>
#define REP( i , st , en ) for ( int i =st; i < (int)en; i++)
#define REPD( i , en , st ) for ( int i =en; i >= (int)st; i--)
#define SZ(a) (int)a.size()
#define all(v) v.begin() , v.end()
#define pb push_back
#define F first
#define S second
#define bitch_i_m_on_fiyaah_yeahhhh ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
// const int mod = 998244353;
const int mod = 1e9+7;
ostream& operator << ( ostream&  o, vector<int> s){for ( int i = 0;  i < (int)s.size() ; i++)o << s[i] << " ";o << "\n";return o;}
void  add( int &a, int b){a = a + b;if ( a< 0 ) a += mod; if ( a> mod ) a-= mod;}
void sub( int &a, int b){a = a - b;if ( a < 0) a += mod;}
int mul( int a , int b){return ((a %mod) * (b %mod) ) %mod;}
int exp( int a , int pow){ return (pow == 0 ? 1 : ( pow & 1  ? mul ( a ,exp( mul(a, a) , pow /2) ) : exp(mul(a ,a) , pow/2)));}
int gcd(int a, int b) { return b ? gcd(b, a%b) : a; }
// const int inf = 1e18;
const int maxn = 6e5 +5;
void solve(int test ) 
{	
	int n;
	cin >> n;
	vector<int> v;
	string s;
	cin >> s;
	int r =0 , g =0  , b = 0;
	for ( int i = 0 ; i < n ; i++) {
		if ( s[i] == 'R') v.push_back(1) , r++;
		else if ( s[i] == 'G') v.push_back(2) , g++;
		else v.push_back( 3) , b++;
	}
	int ans = r * g  * b ;
	for ( int i = 0 ;i < n ; i++) {
		for ( int j = i +1 ; j < n ; j++){
			int dif = j - i;
			int k = j + dif;
			if ( k < n && (v[i] ^ v[j] ^ v[k]) == 0) ans--;
		}
	}
	cout << ans;

}
signed main(){
	bitch_i_m_on_fiyaah_yeahhhh
	int t =1; 
	// cin >> t;
	auto start = chrono::steady_clock::now();
	for ( int i = 0 ; i < t; i++)
	solve(i+1 );
	auto end = chrono::steady_clock::now();
	auto diff = end - start;
	// cout <<  (chrono::duration <double, milli> (diff).count()  / 1000 .0 )<< " s" << endl;
}