#include<iostream>
#include<string>
#include<vector>
#include <math.h>

#define LL long long
#define MOD 1000000007
#define rep(i,n) for(int i = 0;i < (n);i++)

using namespace std;

int main() {

    int N;
    string S;
    cin >> N >> S;

    int cnt[3] = {0};
    
    rep(i,N){
        if(S[i] == 'R') cnt[0]++;
        if(S[i] == 'G') cnt[1]++;
        if(S[i] == 'B') cnt[2]++;
    }

    LL ans = 1;
    rep(i,3)ans *= cnt[i]; 

     rep(i,N){
         for(int j = i+1;j < N;j++){
            int k = 2 * j - i;
            if(S[i] == S[j]) continue;
            if(S[j] == S[k]) continue;
            if(S[k] == S[i]) continue;
            if(k < N) ans--;
         }
     }
     cout << ans <<endl;

	return 0;
}






