#include<iostream>
#include<string>
#include<vector>
#include<numeric>
#include<set>
#include<algorithm>

using namespace std;

int main() {
    int N;
    string S;
    cin >> N >> S;

    int count_R = count(S.cbegin(), S.cend(), 'R');
    int count_G = count(S.cbegin(), S.cend(), 'G');
    int count_B = count(S.cbegin(), S.cend(), 'B');

    /*cout << count_R << endl;
    cout << count_G << endl;
    cout << count_B << endl;*/

    char ch1;
    char ch2;
    char ch3;
    int count = 0;

    for (int i = 0; i < N; i++) {
        ch1 = S[i];
        for (int j = i + 1; j < N; j++) {
            if (ch1 != S[j]) {
                ch2 = S[j];
                int k = j + (j - i);
                if (k < N) {
                    if ((S[k] != ch1) && (S[k] != ch2))count++;
                }
            }
        }
    }

    cout << count_R * count_G * count_B - count << endl;

    return 0;
}