/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author yosiiii
 */


#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(long long int i=0;i<(n);++i)
typedef long long int ll;

class DRGBTriplets {
public:
	void solve(std::istream& in, std::ostream& out) {
        int n;
        in >> n;
        string s;
        in >> s;
        vector<int> r(n,0),g(n,0),b(n,0);
        rep(i,n){
            if(s[i]=='R') {
                r[i]++;
            }
            if(s[i]=='G') {
                g[i]++;
            }
            if(s[i]=='B') {
                b[i]++;
            }
        }
        rep(i,n-1){
            r[i+1]+=r[i];
            g[i+1]+=g[i];
            b[i+1]+=b[i];
        }
        ll cnt = 0L;
        for(int j=1;j<n-1;j++){
            if(s[j]=='R'){
                cnt+=g[j]*(b.back()-b[j])+b[j]*(g.back()-g[j]);
            }
            if(s[j]=='G'){
                cnt+=b[j]*(r.back()-r[j])+r[j]*(b.back()-b[j]);
            }
            if(s[j]=='B'){
                cnt+=r[j]*(g.back()-g[j])+g[j]*(r.back()-r[j]);
            }
            int t = min(n-j-1,j);
            for(int i=1;i<=t;i++){
                if(s[j]!=s[j-i]&&s[j]!=s[j+i]&&s[j-i]!=s[j+i]){
                    cnt--;
                }
            }
        }
        out << cnt << endl;
	}
};


int main() {
	DRGBTriplets solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}
