#include <bits/stdc++.h>
using namespace std;
int main(void){
    // Your code here
    int N; stirng S;
    int i;
    int r=0,g=0,b=0;
    int x,y,z;

    cin << N << S;

    for(i=0;i<N;i++){
        if(S.at(i)=='R')r++;
        if(S.at(i)=='G')g++;
        if(S.at(i)=='B')b++;   
    }

    int all = r*g*b;

    int sub = 0;

    for(x=0;x<N-3;x++){
        for(y=0;y<N-1;y++){
            if(x+y%2==0){
                z = (x+y)/2;
                if(S.at(x)==S.at(z)||S.at(y)==S.at(z)){

                }else{
                    sub++;
                }
            }
        }
    }


    cout << all - sub << endl;
}
