#include<iostream>
#include<string>

using namespace std;

int main(){
    int n,i,j,ans = 0;
    int r=0,g=0,b=0;
    string s;
    cin >> n;
    cin >> s;
    for(i=0;i<n;i++){
        if(s[i] == 'R') r++;
        if(s[i] == 'G') g++;
        if(s[i] == 'B') b++;
    }

    ans = r*g*b;

    for(i=0;i<n;i++){
        for(j=i+1;j<n;j++){
            int k = 2*j -i;
            if(k>=n) break;
            if(s[i] != s[j] && s[j] != s[k] && s[k] != s[i]) ans--;
        }
    }


    cout << ans << endl;

}