#include <iostream>
#include<bits/stdc++.h>

using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)

typedef long long ll;

int main(){
    int n;
    string rgb;
    cin >> n;
    cin >> rgb;
    vector<int> r,g,b;
    rep(i,n){
        if(rgb[i] == 'R') r.push_back(i);
        else if(rgb[i] == 'B') b.push_back(i);
        else if(rgb[i] == 'G') g.push_back(i);
    }
    int count = 0;
    int s,m,l;
    rep(i,r.size()){
        rep(j,b.size()){
            rep(k,g.size()){
                s = min(r[i],b[j]);
                s = min(s,g[k]);
                l = max(r[i],b[j]);
                l = max(l,g[k]);
                if(r[i] != s && r[i] != l) m = r[i];
                else if(b[j] != s && b[j] != l) m = b[j];
                else m = g[k];

                if ((l - m) != (m-s)) count += 1;
            }
        }
    }
    cout << count << endl;

    return 0;
}
