#include<stdio.h>

int main(){
    int n;
    scanf("%d",&n);
    char s[n];
    scanf("%s",s);
    int ans=0;
    for(int k=0;k<n;k+=2){
        for(int j=0;j<k;j+=2){
            for(int i=0;i<j;i+=2){
                if(s[i]!=s[j]&&s[i]!=s[k]&&s[j]!=s[k]&&(j-i)!=(k-j))ans+=1;
                if((i+1)<j&&(j+1)<k&&(k+1)<n&&s[i+1]!=s[j+1]&&s[i+1]!=s[k+1]&&s[j+1]!=s[k+1]&&(j-i)!=(k-j))ans+=1;
            }
        }
    }
    printf("%d\n",ans);
    return 0;
}