#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ll long long
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 all = r*b*g;
    ll sub = 0;
    for (int i=0; i<n; i++){
        for(int j=i+1; j<n; j++){
            if(s.at(i) == s.at(j)) continue;
        
        int k = j*2 -i;
        if(k >= n || s.at(k) == s.at(i) || s.at(k) == s.at(j))continue;
        sub++;
    }
   
} cout << all - sub << endl;
}