#include<stdio.h>
#include<stdlib.h>
#define ll long long
int min(int a,int b){return a<b?a:b;}
int max(int a,int b){return a>b?a:b;}
int r[4002] = {0};
int g[4002] = {0};
int b[4002] = {0};
int  main(){
    int n;
    scanf("%d",&n);
    char s[n + 1];
    scanf("%s",s);
    ll ans = 0, count = 0;
    for(int i = 1; i <= n; i++){
        if(s[i - 1] == 'R')
            r[i] = 1;
        if(s[i - 1] == 'G')
            g[i] = 1;
        if(s[i - 1] == 'B'){
            b[i] = 1;
            count ++;
        }
    }
    for(int i = 1; i <= n ; i++){
        for(int j = 1; j <= n ; j++){
            if(r[i] == 1 && g[j] == 1){
                ans += count;
                int p = abs(i - j);
                int m = max(i, j);
                int q = min(i, j);
                if(m + p <= n && b[m + p] == 1) ans --;
                if(q > p && b[q - p] == 1) ans --;
                if(p % 2 == 0 && b[p / 2 + q] == 1) ans --;
            }
        }
    }
    printf("%lld\n",ans);
    return 0;
}