#include <iostream>
#include <vector>
#include <algorithm>
#include <map>

using namespace std;

int main() {
    map<char, int> m;
    m['R'] = 0;
    m['G'] = 1;
    m['B'] = 2;
    int N;
    string S;
    cin >> N >> S;
    vector<bool> rgb(3);
    int count = 0;
    for(int i = 0; i < N; i++) {
        if(S.at(i) == 'R') {
            rgb.at(0) = true;
            rgb.at(1) = false;
            rgb.at(2) = false;
        } else if(S.at(i) == 'G') {
            rgb.at(0) = false;
            rgb.at(1) = true;
            rgb.at(2) = false;
        } else if(S.at(i) == 'B') {
            rgb.at(0) = false;
            rgb.at(1) = false;
            rgb.at(2) = true;
        }
        for(int j = i + 1; j < N; j++) {
            if(rgb.at(m[S.at(j)]) == true) {
                continue;
            }
            rgb.at(m[S.at(j)]) = true;
            for(int k = j + 1; k < N; k++) {
                if(rgb.at(m[S.at(k)]) == false) {
                    if(k - j != j - i) {
                        count++;
                    }
                }
            }
            rgb.at(m[S.at(j)]) = false;
        }
    }
    cout << count << endl;
}