#include <bits/stdc++.h>
#define rep(i,a,b) for(int i = a; i < b; ++i)
#define all(c) c.begin(), c.end()
#define gmax(x,y) x=max(x,y)
#define gmin(x,y) x=min(x,y)
#define gadd(x,y) x=add(x,y)
#define gmul(x,y) x=mul(x,y)
using namespace std;

typedef pair<int,int> pii;
typedef long long ll;

int rcnt[3];

int fix(char c){
	if(c == 'R')return 0;
	if(c == 'G')return 1;
	else return 2;
}

int main(){
	cin.tie(0);
	cout.tie(0);
	ios_base::sync_with_stdio(0);
	int n;
	string s;
	cin >> n >> s;
	ll ans = 0;
	rep(i,0,n){
		int dual = 1;
		int cur = fix(s[i]);
		rep(j,0,3)if(j != cur)dual *= rcnt[j];

		rep(len,0,i){
			if(i - 2 * len < 0){
				break;
			}
			int x = i - 2*len;
			int y = i - len;
			if(s[x] != s[y] && s[y] != s[i] && s[i] != s[x]){
				--dual;
			}
		}
		ans += dual;
		++rcnt[cur];
	}
	cout << ans << '\n';
}
