#include<stdio.h>

int main(){
    int n;scanf("%d",&n);
    char s[n+1];scanf("%s",s);

    int r,g,b;r=g=b=0;
    for(int i=0;i<n;i++){
        if(s[i]=='R')r++;
        if(s[i]=='G')g++;
        if(s[i]=='B')b++;
    }
    int cnt=0;
    for(int i=1;i<n-1;i++){
        int dist=1;
        while(i-dist>=0&&i+dist<n){
            if(s[i-dist]!=s[i]&&s[i]!=s[i+dist]&&s[i-dist]!=s[i+dist])
                cnt++;
            dist++;
        }
    }
    long long ans;
    ans=r*g;
    ans*=b;
    ans-=cnt;
    printf("%lld\n",ans);
}