#include"bits/stdc++.h"

using namespace std;

#define rep(i,n) for(int i=0;i<(int)(n);i++)
void sort2array(double *a,long *b,long n){
    for(int i=0;i<n;i++){
        b[i]=i;
    }
    sort(b,b+n,[a](long i,long j)->bool {return a[i]<a[j];} );
}
int wtover(int a,int b){
    if(a%b>0)return (a/b)+1;
    else return a/b;
}
int INF=100000001;


int main(){
    int i,j,n,c[3]={0},a;
    char t[3]={'R','G','B'};
    cin>>n;
    char s[n+1];
    rep(i,n){
        cin>>s[i];
        if(s[i]=='R')c[0]+=1;
        else if (s[i]=='G')c[1]+=1;
        else c[2]+=1;
    }
    //入力
    //処理
    int count=0,l[3]={0},k[3]={0},x,y;
    if(s[0]=='R')l[0]+=1;        
    else if (s[i]=='G')l[1]+=1;
    else l[2]+=1;
    bool sei=false;
    rep(i,n-2){
        rep(a,3){
            if(s[i]==t[a])l[a]+=1;
        }
        rep(a,3){
            k[a]=l[a];
        }
        for(j=i+1;j<n-1;j++){
            rep(a,3){
                if(s[j]==t[a])k[a]+=1;
            }
            if(s[i]==s[j]){
                
                break;
            }else {
                rep(a,3){
                    if(s[i]==t[a])x=a;
                    if(s[j]==t[a])y=a;
                }
                if(2*j-i<n){
                    if(s[2*j-i]!=s[j]&&s[2*j-i]!=s[i])sei=true;
                }
                count+=c[6-x-y]-k[6-x-y];
                if(sei)count-=1;
            }
        }
    }
    //出力
    cout<<count<<endl;
}