#include<stdio.h>
int n,i,j;
long r=0,g=0,b=0,q;
char s[4001];
int main(){
    scanf("%d%s",&n,s);
    for(i=0;i<n;i++)s[i]=='R'?r++:s[i]=='G'?g++:b++;
    q=r*g*b;
    for(i=0;i<n;i++){
        for(j=1;i+2*j<n;j++){
            if(s[i]!=s[i+j]&&s[i]!=s[i+2*j]&&s[i+2*j]!=s[i+j])q--;
        }
    }
    printf("%ld",q);
    return 0;
}