#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define MOD 1000000007
#define test int t; cin>>t; while(t--)
#define init(arr,val) memset(arr,val,sizeof(arr))
#define loop(i,a,b) for(int i=a;i<b;i++)
#define loopr(i,a,b) for(int i=a;i>=b;i--)
#define loops(i,a,b,step) for(int i=a;i<b;i+=step)
#define looprs(i,a,b,step) for(int i=a;i>=b;i-=step)
#define ull unsigned long long int
#define ll long long int
#define P pair
#define PLL pair<long long, long long>
#define PII pair<int, int>
#define PUU pair<unsigned long long int, unsigned long long int>
#define L list
#define V vector
#define D deque
#define ST set
#define MS multiset
#define M map
#define UM unordered_map
#define mp make_pair
#define pb emplace_back
#define pf push_front
#define MM multimap
#define F first
#define S second
#define IT iterator
#define RIT reverse_iterator
#define FAST ios_base::sync_with_stdio(false);cin.tie();cout.tie();
#define FILE_READ_IN freopen("input.txt","r",stdin);
#define FILE_READ_OUT freopen("output.txt","w",stdout);
#define all(a) a.begin(),a.end()
#define ld long double
#define random_init mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define shuffle_random(a) random_shuffle(all(a),rng);
using namespace std;
// pair operation
template<class T, class U>istream& operator>>(istream& in, pair<T,U> &rhs){in >> rhs.first;in >> rhs.second;return in;}
template<class T, class U>ostream& operator>>(ostream& out,const pair<T,U> &rhs){out << rhs.first;out << " ";out << rhs.second;return out;}
template<class T, class U>pair<T,U> operator+(pair<T,U> &a, pair<T,U> &b){return pair<T,U>(a.first+b.first,a.second+b.second);}
template<class T, class U>pair<T,U> operator-(pair<T,U> &a, pair<T,U> &b){return pair<T,U>(a.first-b.first,a.second-b.second);}
// Linear STL
// VECTOR
template<class T>istream& operator>>(istream& in, vector<T> &a){for(auto &i: a)cin >> i;return in;}
template<class T>ostream& operator<<(ostream& out, const vector<T> &a){for(auto &i: a)cout << i << " ";return out;}
// SET
template<class T>ostream& operator<<(ostream& out, const set<T> &a){for(auto &i: a)cout << i << " ";return out;}
template<class T>ostream& operator<<(ostream& out, const unordered_set<T> &a){for(auto &i: a)cout << i << " ";return out;}
template<class T>ostream& operator<<(ostream& out, const multiset<T> &a){for(auto &i: a)cout << i << " ";return out;}
// MAP
template<class T,class U>ostream& operator<<(ostream& out, const map<T,U> &a){for(auto &i: a)cout << "(" << i.first << ", " << i.second << "(\n";return out;}
template<class T,class U>ostream& operator<<(ostream& out, const unordered_map<T,U> &a){for(auto &i: a)cout << "(" << i.first << ", " << i.second << "(\n";return out;}

// For ordered_set
using namespace __gnu_pbds;
template <typename T>
using ord_set = tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;

// Constants
const ll N = 1e5 + 100;
const ll inf = 1e9;
const double pi = acos(-1);

void solve(int test_case){
	int n;
	cin >> n;
	string a;
	cin >> a;
	ll ans = 0;
	V<ll> r(n,0);
	V<ll> rr(n,0);
	V<ll> g(n,0);
	V<ll> gr(n,0);
	V<ll> b(n,0);
	V<ll> br(n,0);
	r[0] = (a[0]=='R');
	b[0] = (a[0]=='B');
	g[0] = (a[0]=='G');
	rr[n-1] = (a[n-1]=='R');
	br[n-1] = (a[n-1]=='B');
	gr[n-1] = (a[n-1]=='G');
	for(int i = 1; i < n; ++i){
		r[i] = r[i-1]+(a[i]=='R');
		b[i] = b[i-1]+(a[i]=='B');
		g[i] = g[i-1]+(a[i]=='G');
		rr[n-i-1] = rr[n-i]+(a[n-1-i]=='R');
		br[n-i-1] = br[n-i]+(a[n-1-i]=='B');
		gr[n-i-1] = gr[n-i]+(a[n-1-i]=='G');
	}
	// cout << "RR";
	// for(auto i: rr)cout << i << " ";
	// cout << endl;
	// cout << "GR";
	// for(auto i: gr)cout << i << " ";
	// cout << endl;
	// cout << "BR";
	// for(auto i: br)cout << i << " ";
	// cout << endl;
	for(int j = 1; j+1 < n; ++j){
		if(a[j] == 'R'){
			ans+=br[j+1]*g[j-1];
			ans+=gr[j+1]*b[j-1];
			for(int i = j-1,k=j+1; i >= 0 && k < n; ++k,--i){
				if(a[i] == 'B' && a[k] == 'G')ans--;
				if(a[i] == 'G' && a[k] == 'B')ans--;
			}
		}
		if(a[j] == 'G'){
			ans+=br[j+1]*r[j-1];
			ans+=rr[j+1]*b[j-1];
			for(int i = j-1,k=j+1; i >= 0 && k < n; ++k,--i){
				if(a[i] == 'R' && a[k] == 'B')ans--;
				if(a[i] == 'B' && a[k] == 'R')ans--;
			}
		}
		if(a[j] == 'B'){
			ans+=gr[j+1]*r[j-1];
			ans+=rr[j+1]*g[j-1];
			for(int i = j-1,k=j+1; i >= 0 && k < n; ++k,--i){
				if(a[i] == 'R' && a[k] == 'G')ans--;
				if(a[i] == 'G' && a[k] == 'R')ans--;
			}
		}
	}
	cout << ans << "\n";
}

int main(){
	FAST
	int t = 1;
	//cin >> t;
	loop(i,1,t+1)solve(i);
}


Measured memory_bytes: 3700