#include <bits/stdc++.h>
#define rep(i,n) for (int i=0; i<(n); ++i)
using namespace std;
using ll=long long;
int main(){
    int n; string s;
    cin>>n>>s;
    int x=s.size();
    int sum=1;
    int r=0,g=0,b=0;
    rep(i,n){
        if(s[i]=='R')r++;
        if(s[i]=='G')g++;
        if(s[i]=='B')b++;
    }
    sum=r*g*b;
    for(int i=0; i<x-2; ++i){
        for(int j=i+1; j<x-1; ++j){
            int k=j*2-i;
            if(k>=x)continue;
            else{
                if(s[i]!=s[j]&&s[j]!=s[k]&&s[k]!=s[i]){
                    sum--;
                }
            }
        }
    }
    cout<<sum<<endl;
}