#include <stdio.h>
#include <stdlib.h>
 
int main(){
    int N=0;
    scanf("%d",&N);
    char str[N+1];
    scanf("%s",str);
    long count = 0;
    long b=0;
    for(int i = 0;i < N;i++) if(str[i] == 'B') b++;
    for(int i = 0;i < N;i++){
        for(int k = i+1;k < N;k++){
            if((str[i] == 'R' && str[k] == 'G') || (str[i] == 'G' && str[k] == 'R')){
                if( (2*k-i)<N && str[2*k-i]=='B' )count--;//RGB,GRB
                if( str[(i+k)/2]=='B' && (i+k)%2==0 )count--;//RBG,GBR
                if( (2*i-k)>=0 && str[(2*i-k)]=='B' )count--;//BRG,BGR
                count+=b;
            }
        }
    }
    printf("%ld\n",count);
    return 0;
}