#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0; i<(n); i++)
#define REP2(i,x,n) for(int i=x; i<(n); i++)
#define ALL(n) begin(n),end(n)
#define sz(x) int(x.size())
using ll = long long;
const ll LLINF = numeric_limits<long long>::max();
const int mod = 1000000007;
const int INF = 1001001001;
 
 
 
int main()
{
    int N;
    string S;
    cin >> N >> S;
    int ans = 0;
    
    vector<int> r;
    vector<int> g;
    vector<int> b;
 
    for(int i=0;i<N;i++){
        if(S[i]=='R'){
            r.push_back(i+1);
        }
        else if(S[i]=='G'){
            g.push_back(i+1);
        }
        else if(S[i]=='B'){
            b.push_back(i+1);
        }
    }
 
    ans = r.size() * g.size() * b.size();
 
    for (int j=0;j<N;j++){
        for(int l=1;l<=N/2;l++){
            int i=j-l;
            int k=j+l;

            if(k>=N || i<0){
                continue;
            }
            if(S[i]!=S[j] && S[i]!=S[k] && S[j]!=S[k]){
                // cout << i << " " << j << " " << k << endl;
                ans--;
            }
        }
    }
    
    cout << ans<<endl;
    return 0;
}