#include<bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i, n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
template<class T> istream& operator >> (istream& s, vector<T>& v)
{ for (T& x: v) { s >> x; } return s;}
void yes(){ cout << "Yes" << endl; }
void no(){ cout << "No" << endl; }

int main(){
    int n; cin >> n;
    string s; cin >> s;
    ll ans = 0;
    string m = s;
    reverse(m.begin(), m.end());
    bool r=false, g=false, b=false;
    int num = 0;
    rep(i,n){
        if(m[i] == 'R') r = true;
        else if(m[i] == 'G') g = true;
        else if(m[i] == 'B') b = true;
        if(r && g && b){
            num = n-i;
            break;
        }
    }
    
    vector<int> R,G,B;
    rep(i,n){
        if(s[i] == 'R') R.push_back(i);
        else if(s[i] == 'G') G.push_back(i);
        else if(s[i] == 'B') B.push_back(i);
    }
    vector<int> RG,RB,GB;
    RG = R; RG.insert(RG.end(), G.begin(), G.end());
    RB = R; RB.insert(RB.end(), B.begin(), B.end());
    GB = G; GB.insert(GB.end(), B.begin(), B.end());
    sort(RG.begin(), RG.end());
    sort(RB.begin(), RB.end());
    sort(GB.begin(), GB.end());

    rep(i,num){
        if(s[i] == 'R'){
            int j = distance(GB.begin(), upper_bound(GB.begin(), GB.end(), i));
            for(j; j < GB.size(); j++){
                if(s[GB[j]] == 'G'){
                    int k = distance(B.begin(), upper_bound(B.begin(), B.end(), GB[j]));
                    for(k; k < B.size(); k++){
                        if(B[k]-GB[j] == GB[j]-i) continue;
                        ans++;
                    }
                }
                if(s[GB[j]] == 'B'){
                    int k = distance(G.begin(), upper_bound(G.begin(), G.end(), GB[j]));
                    for(k; k < G.size(); k++){
                        if(G[k]-GB[j] == GB[j]-i) continue;
                        ans++;
                    }
                }
            }
        } else if(s[i] == 'G'){
            int j = distance(RB.begin(), upper_bound(RB.begin(), RB.end(), i));
            for(j; j < RB.size(); j++){
                if(s[RB[j]] == 'R'){
                    int k = distance(B.begin(), upper_bound(B.begin(), B.end(), RB[j]));
                    for(k; k < B.size(); k++){
                        if(B[k]-RB[j] == RB[j]-i) continue;
                        ans++;
                    }
                }
                if(s[RB[j]] == 'B'){
                    int k = distance(R.begin(), upper_bound(R.begin(), R.end(), RB[j]));
                    for(k; k < R.size(); k++){
                        if(R[k]-RB[j] == RB[j]-i) continue;
                        ans++;
                    }
                }
            }
        } else if(s[i] == 'B'){
            int j = distance(RG.begin(), upper_bound(RG.begin(), RG.end(), i));
            for(j; j < RG.size(); j++){
                if(s[RG[j]] == 'R'){
                    int k = distance(G.begin(), upper_bound(G.begin(), G.end(), RG[j]));
                    for(k; k < G.size(); k++){
                        if(G[k]-RG[j] == RG[j]-i) continue;
                        ans++;
                    }
                }
                if(s[RG[j]] == 'G'){
                    int k = distance(R.begin(), upper_bound(R.begin(), R.end(), RG[j]));
                    for(k; k < R.size(); k++){
                        if(R[k]-RG[j] == RG[j]-i) continue;
                        ans++;
                    }
                }
            }
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3676