#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for(int (i) = 0; (i) <(int)n; ++(i))
#define rep2(i,s,n) for(int (i) = (s); (i) <=(int)(n); ++(i))

int main() {
    int n;
    string s;
    cin >> n >> s;
    ll r = 0, g = 0, b = 0;

    for(auto c:s) {
        if(c == 'R') ++r;
        else if(c == 'G') ++g;
        else ++b;
    } 
    
    ll total = r * g * b;
   
    int sub = 0;
    rep(i, n){
        for(int j = i+1; j < n; ++j){
            if(s[i] == s[j]) continue;            
            int k = 2*j - i;
            if(k >= n) continue;
            if(s[i] == s[k] || s[j] == s[k]) continue;
            
            ++sub;
            // cout << i << ' ' << j << ' ' << k << endl;
        }
    }
    cout << total - sub << endl;

    
}