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