#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <queue>
#include <utility>
#include <map>
#include <bitset>
#include <iomanip>
#define ll long long
using namespace std;
using p = pair<ll, ll>;
ll dx[4] = {-1, 0, 1, 0};
ll dy[4] = {0, 1, 0, -1};

int main(void){
    ll n;
    cin >> n;
    string s;
    cin >> s;
    ll c1 = 0, c2 = 0, c3 = 0;
    for(ll i = 0; i < n; i++){
        if(s[i]=='R') c1++;
        if(s[i]=='G') c2++;
        if(s[i]=='B') c3++;
    }
    ll ans = c1*c2*c3;
    ll count = 0;
    for(ll i = 1; i < n; i++){
        for(ll j = i; j < n; j++){
            if(j-i < 0 || j+i >= n) break;
            if(s[j-i]!=s[j] && s[j]!=s[j+i] && s[j-i]!=s[j+i]){
                count++;
                //cout << s[j-1] << " " << s[j] << " " << s[j+1] << endl;
            }
        }
    }
    cout << ans-count << endl;
    return 0;
}
