#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <string>
#include <cstring>
#include <utility>
#include <set>
#include <stack>
#include <climits>
#include <cmath>

#define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define rep1(i,n) for(int i=1, i##_len=(n); i<=i##_len; ++i)
#define reps(i,s,n) for(int i=s, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
#define MEMSET(v, h) memset((v), h, sizeof(v))
typedef long long ll;
const char sp = ' ';


using namespace std;

int main(void){
    ll N;
    string S;
    cin>>N>>S;
    ll r=0, g=0, b=0;
    rep(i, N){
        if(S[i]=='R') r++;
        else if(S[i]=='G') g++;
        else if(S[i]=='B') b++;
    }
    ll count=r*g*b;
    rep(i, N) rep1(d, (N-1-i)/2){
        //cout<<count<<endl;;
        if(S[i]!=S[i+d] && S[i+d]!=S[i+2*d] && S[i]!=S[i+2*d]) count--;
    }
    cout<<count<<endl;
    return 0;
}
