#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <queue>
#include <algorithm>
#include <utility>
#include <unordered_map>
#include <cmath>
using namespace std;

typedef unsigned int uint;
typedef long long llong;
typedef unsigned long long ullong;
// -2.1e-9 <= int <= 2.1e9
// -9.2e-18 <= long long <= 9.2e18
// 0 <= unsigned int <= 4.2e9
// 0 <= unsigned long long <= 18.4e18

int main()
{
    int N; cin >> N;
    string S; cin >> S;
    vector<int> posR, posG, posB;
    for (size_t i = 0; i<S.size(); i++) {
        if (S[i] == 'R')
            posR.push_back(i);
        else if (S[i] == 'G')
            posG.push_back(i);
        else
            posB.push_back(i);
    }

    int sum = 0;
    vector<int> rgb(3);
    for (auto i: posR) {
        rgb[0] = i;
        for (auto j: posG) {
            rgb[1] = j;
            for (auto k: posB) {
                rgb[2] = k;
                vector<int> rgbSort(rgb);
                sort(rgbSort.begin(), rgbSort.end());
                if ((rgbSort[1] - rgbSort[0]) == (rgbSort[2] - rgbSort[1])) continue;
                sum++;
            }
        }
    }
    cout << sum << endl;
}
