#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define INF (1LL<<50)
#define MOD 1000000007

int main(){
    int N;
    cin >> N;
    string S;
    cin >> S;
    vector<int> cR(N+1),cG(N+1),cB(N+1);
    for(int i=0;i<N;i++){
        if(S[i]=='R'){
            cR[i+1]=cR[i]+1;
            cG[i+1]=cG[i];
            cB[i+1]=cB[i];
        }
        if(S[i]=='G'){
            cR[i+1]=cR[i];
            cG[i+1]=cG[i]+1;
            cB[i+1]=cB[i];
        }
        if(S[i]=='B'){
            cR[i+1]=cR[i];
            cG[i+1]=cG[i];
            cB[i+1]=cB[i]+1;
        } 
    }
    ll ans = 0;
    for(int j=1;j<N-1;j++){
        if(S[j]=='R'){
            ans+=cG[j]*(cB[N]-cB[j+1]);
            ans+=cB[j]*(cG[N]-cG[j+1]);
            for(int l=1;(j-l>=0&&j+l<N);l++){
                if(S[j-l]=='G'&&S[j+l]=='B'){
                    ans--;
                }else if(S[j-l]=='B'&&S[j+l]=='G'){
                    ans--;
                }
            }
        }
        if(S[j]=='G'){
            ans+=cR[j]*(cB[N]-cB[j+1]);
            ans+=cB[j]*(cR[N]-cR[j+1]);
            for(int l=1;(j-l>=0&&j+l<N);l++){
                if(S[j-l]=='R'&&S[j+l]=='B'){
                    ans--;
                }else if(S[j-l]=='B'&&S[j+l]=='R'){
                    ans--;
                }
            }
        }
        if(S[j]=='B'){
            ans+=cR[j]*(cG[N]-cG[j+1]);
            ans+=cG[j]*(cR[N]-cR[j+1]);
            for(int l=1;(j-l>=0&&j+l<N);l++){
                if(S[j-l]=='R'&&S[j+l]=='G'){
                    ans--;
                }else if(S[j-l]=='G'&&S[j+l]=='R'){
                    ans--;
                }
            }
        }
    }
    cout << ans << endl;
    return 0;
}