#include <bits/stdc++.h>
using namespace std;

int main(void){
    long long n,r,g,b;
    string s;
    cin >> n >> s;
    r = count(s.cbegin(), s.cend(), 'R');
    g = count(s.cbegin(), s.cend(), 'G');
    b = count(s.cbegin(), s.cend(), 'B');
    
    long long count = 0;
    for (long long i = 0; i < n; i++){
        for (long long j = i + 1; j <= (n+i-1)/2; j++){
            vector<char> se ={s.at(i), s.at(j), s.at(2*j-i)};
             int coun = 0;
            if(se.at(0)=='R'||se.at(1)=='R'||se.at(2)=='R') coun++;
            if(se.at(0)=='G'||se.at(1)=='G'||se.at(2)=='G') coun++;
            if(se.at(0)=='B'||se.at(1)=='B'||se.at(2)=='B') coun++;
            if(coun == 3) count++;
        }
    }
    long long ans;
    ans = r * g * b - count;
    printf("%lld\n",ans);
}