#include <bits/stdc++.h>
using namespace std;
long long n,ans,pref[4001][3],vals[4001];
string s;

int main(){
    cin >> n >> s;
    for(int i = 0 ; i < n ; i += 1){
        if(s[i] == 'R'){
            vals[i] = 0;
        }else if(s[i] == 'G'){
            vals[i] = 1;
        }else{
            vals[i] = 2;
        }
    }
    for(int i = n-1 ; i >= 0 ; i -= 1){
        for(int j = 0 ; j < 3 ; j += 1){
            pref[i][j] = pref[i+1][j];
        }
        pref[i][vals[i]] += 1;
    }
    for(int i = 0 ; i+1 < n ; i += 1){
        for(int j = i+1 ; j < n ; j += 1){
            if(vals[j] == vals[i]){
                continue;
            }
            ans += pref[j][3-vals[i]-vals[j]];
            if(2*j-i < n && vals[2*j-i] == 3-vals[i]-vals[j]){
                ans -= 1;
            }
        }
    }
    cout << ans << endl;
}