//----------------------------------------------------------------------
#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)   FOR(i,0,n)
//----------------------------------------------------------------------

using namespace std;
using ll = long long;
using P = pair<int,int>;
using Graph = vector<vector<int>>;

bool med3(int a, int b, int c) {
    int _min, _max;
    _min = _max = a;
    _min = min(_min,b);
    _min = min(_min,c);
    _max = max(_max,b);
    _max = max(_max,c);

    if(_min != a && _max != a) {
        return abs(b-a) != abs(c-a);
    }
    if(_min != b && _max != b) {
        return abs(a-b) != abs(c-b);
    }
    if(_min != c && _max != c){ 
        return abs(a-c) != abs(b-c);
    }

}
int main(void) {
    int n;
    string s;
    cin >> n;
    cin >> s;
    vector<int> r, g, b;
    r.reserve(n);
    g.reserve(n);
    b.reserve(n);
    REP(i,n) {
        if(s[i]== 'R') {
            r.push_back(i);
        }else if(s[i]== 'G') {
            g.push_back(i);
        }else {
            b.push_back(i);
        }
    }
    ll ans = 0;
    for(int i : r)
    for(int j : g)
    for(int k : b) {
        if(med3(i,j,k)) ans++;
    }
    cout << ans << endl;

    return 0;
}