#include<bits/stdc++.h> 

using namespace std;

typedef short sho;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef double db;
typedef string str; 
 
typedef pair<int,int> pii;
typedef pair<ll,ll> pll; 
typedef pair<ld,ld> pld;
 
typedef vector<int> vi; 
typedef vector<ll> vl; 
typedef vector<ld> vd;
typedef vector<str> vs;
typedef vector<pii> vpi;
typedef vector<pll> vpl;
typedef vector<pld> vpd;

#define LOCAL
#define MP make_pair 
#define FF first
#define SS second
#define sz(x) (int)x.size()
#define begin(x) (x).begin() 
#define end(x) (x).end()
#define rbegin(x) (x).rbegin()
#define rend(x) (x).rend()
#define all(x) begin(x), end(x)
#define rall(x) rbegin(x), rend(x)
#define rsz resize
#define ins insert
#define ft front()
#define bk back()
#define PF push_front 
#define PB push_back
#define PP push
#define lb lower_bound 
#define ub upper_bound
#define lowbit(x) x&(-x)
#define testbit(x,i) x&(1<<i)

inline void checkmin(int &x,int y){x=min(x,y);}
inline void checkmax(int &x,int y){x=max(x,y);}

int n;
str s;

int type[4010];
vi pos[3];
ll ans = 0;

int main() 
{
	#ifndef LOCAL
		freopen("input.txt","r",stdin);
		freopen("output.txt","w",stdout);
	#endif
	ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    /* start code */
    cin>>n>>s;
    for(int i = 0; i < n; i++)
    {
    	if(s[i] == 'R') pos[0].PB(i);
    	else if(s[i] == 'G') pos[1].PB(i);
    	else pos[2].PB(i);
	}
	for(int i = 0; i < n; i++)
	{
		if(s[i] == 'R') type[i] = 0;
		else if(s[i] == 'G') type[i] = 1;
		else type[i] = 2; 
	}
	for(int i = 0; i < n; i++) for(int k = i + 2; k < n; k++)
	{
		if(type[i] == type[k]) continue; 
		int type_j = 3 - type[i] - type[k];
		int low_pos = lower_bound(all(pos[type_j]), i) - begin(pos[type_j]);
		int high_pos = lower_bound(all(pos[type_j]), k) - begin(pos[type_j]);
		if(high_pos)
		{
			ans += high_pos - low_pos;
			if((k - i) % 2 == 0 && type[(k + i) / 2] == type_j) ans--;
		}
	}
	cout<<ans<<endl;
    /* end code */
	return 0;
}