#include<bits/stdc++.h>
#define rep(i,N) for(int i=0;i<(N);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
using namespace std;
const long long MOD = 1e9 + 7;
const long long INF = 1e12;
const int inf = 1e9;
typedef long long ll;
typedef pair<ll,int> P;
typedef set<int> S;
ll n;
int main(){
    cin>>n;
    string s;
    cin>>s;
    int r=0,g=0,b=0;
    int ans=0;
    for(int i=s.size()-1;i>=0;i--){
        if(s[i]=='R') r++;
        else if(s[i]=='G') g++;
        else b++;
        //cout<<r<<" "<<g<<" "<<b<<endl;
        if(r>0 && g>0 && b>0){
            /*cout<<"kasan"<<endl;
            cout<<i<<endl;
            cout<<r<<" "<<g<<" "<<b<<endl;*/
            if(s[i]=='R'){
                ans+=g*b;
            }
            else if(s[i]=='G'){
                ans+=b*r;
            }
            else{
                ans+=r*g;
            }
        }
    }
    //cout<<ans<<endl;
    int out=0;
    for(int j=0;j<s.size();j++){
        for(int dis=1;dis<s.size()+10;dis++){
            int i = j-dis;
            int k = j+dis;
            if(i>=0 && k<s.size()){
                if(s[i]!=s[j] && s[i]!=s[k] && s[k]!=s[j]) out++;
            }
        }
    }
    //cout<<out<<endl;
    cout<<ans-out<<endl;
    return 0;
}