#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0 ; i < (n) ; i++ )
using ll = long long;

using namespace std;
int main(){
    int n;cin>>n;
    string s;cin>>s;
    vector<int> cnt(3);
    rep(i,n){
        if(s[i]=='R') cnt[0]++;
        else if(s[i]=='G') cnt[1]++;
        else cnt[2]++;
    }

    ll ans =cnt[0]*cnt[1]*cnt[2];
    rep(j,n){
        rep(i,j){
            int k=2*j-i;
            if(k<n){
                if(s[i]==s[j]) continue;
                if(s[j]==s[k]) continue;
                if(s[i]==s[k]) continue;
                ans--;
            }
        }
    }
    cout << ans <<endl;

    return 0;
}
