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

int main(){
    int N;
    cin >> N;
    vector<char> S(N);
    long long count_R = 0, count_G = 0, count_B = 0;
    for (int i = 0; i < N; i++){
        cin >> S.at(i);
        if (S.at(i) == 'R') count_R ++;
        else if (S.at(i) == 'G') count_G ++;
        else if (S.at(i) == 'B') count_B ++;
    }
    long long ans;
    long long decount = 0;
    if (N > 2){
        for (int i = 0; i < N - 2; i++){
            for(int j = i + 1; j < N - 1; j++){
                if ((2 * j - i >= 0) && (2 * j - i < N) ){
                    //cout << "i " << i << " j " << j << " k " << 2*j - i << endl;
                    if ((S.at(i) != S.at(j)) && (S.at(i) != S.at(2 * j - i)) && (S.at(j) != S.at(2 * j - i))){
                        decount++;
                    }
                    else{
                        continue;
                    }
                }
                else{
                    continue;
                }
            }
        }
        ans = count_R * count_G * count_B - decount;
        //cout << count_R << " " << count_G << " " << count_B << " " << decount << endl;
    }
    else{
        ans = 0;
    }
    cout << ans << endl;
}