#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define db double
#define pii pair<int,int>
#define pli pair<ll,int>
#define pil pair<int,ll>
#define pll pair<ll,ll>
const int inf = 1 << 30;
const ll linf = 1e18;
template<class T> void chmin(T& x, T y){if(x > y) x = y;}
template<class T> void chmax(T& x, T y){if(x < y) x = y;}

int N;
ll ans = 0;
string S;
set<int> R, G, B;
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin >> N >> S;
    for(int i = 0; i < N; i++){
        if(S[i] == 'R') R.insert(i);
        if(S[i] == 'G') G.insert(i);
        if(S[i] == 'B') B.insert(i);
    }
    for(auto u : R){
        for(auto v : G){
            int x = max(u, v);
            int y = min(u, v);
            ans += B.size();
            int d = x - y;
            if(B.find(x + d) != B.end()) ans--;
            if(d % 2 == 0 && B.find(y + (d / 2)) != B.end()) ans--;
            if(B.find(y - d) != B.end()) ans--;
        }
    }
    cout << ans << endl;
    return 0;
}