#include <bits/stdc++.h>
typedef long long ll;
using namespace std;

const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<(n);++i)
#define REPR(i,n) for(int i=n;i>=0;i--)
#define ALL(v) (v.begin(),v.end())
#define COUT(x) cout<<(x)<<endl

int main(){
    int n;string s;
    cin >> n >> s;
    ll r=0,g=0,b=0;
    for(char t:s){
        if(t=='R')r++;
        else if(t=='G')g++;
        else b++;
    }
    //条件1を満たす組の数
    ll ans1 = r*g*b;
    ll ans2 = 0;
    REP(i,n-2){
        FOR(j,i+1,n-1){
            if (s[i]==s[j]) continue;
            int k = 2*j-i;
            if(k>=n||s[i]==s[k]||s[j]==s[k])continue;
            ans2++;
        }
    }
    COUT(ans1-ans2);
    return 0;
}
    