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

#define RED 0
#define GREEN 1
#define BLUE 2
#define MAX_N 4000

string s;
int R[MAX_N], G[MAX_N], B[MAX_N], S[MAX_N];
int N, cnt = 0, r = 0, g = 0, b = 0;

void solve(){
    for(int i = 2; i < N; i++){
        for(int j = 0; j < i - 1; j++){
            if(S[i] == S[j]) continue;
            if(S[i] + S[j] == 1){
                if((i - j) % 2 != 0) cnt += B[i - 1] - B[j];
                else cnt += B[i - 1] + B[(i + j) / 2 - 1] - B[(i + j) / 2] - B[j];
            }
            if(S[i] + S[j] == 2){
                if((i - j) % 2 != 0) cnt += G[i - 1] - G[j];
                else cnt += G[i - 1] + G[(i + j) / 2 - 1] - G[(i + j) / 2] - G[j];
            }
            if(S[i] + S[j] == 3){
                if((i - j) % 2 != 0) cnt += R[i - 1] - R[j];
                else cnt += R[i - 1] + R[(i + j) / 2 - 1] - R[(i + j) / 2] - R[j];
            }
        }
    }
    cout << cnt << endl;
    return;
}

int main(){
    cin >> N >> s;
    for (int i = 0; i < N; i++){
        if(s[i] == 'R') {
            r++;
            S[i] = RED;
        }
        if(s[i] == 'G') {
            g++;
            S[i] = GREEN;
        }
        if(s[i] == 'B') {
            b++;
            S[i] = BLUE;
        }
        R[i] = r;
        G[i] = g;
        B[i] = b;
    }
    solve();
}