#include <iostream>
#include <map>
#include <vector>
using namespace std;

int count(map<char,vector<int>> &dic, char a, char b, char c)
{
    int result = 0;
    for(int x : dic[a])
    {
        vector<int>::iterator y = lower_bound(dic[b].begin(), dic[b].end(), x);
        for(; y != dic[b].end(); ++y)
        {
            vector<int>::iterator z = lower_bound(dic[c].begin(), dic[c].end(), *y);
            for(; z != dic[c].end(); ++z)
            {
                if(*y-x != *z-*y)
                {
                    ++result;
                }
            }
        }
    }
    return result;
}

int main()
{
    int n;
    cin >> n;
    string str;
    cin >> str;
    map<char,vector<int>> dic;
    for(int i = 0; i < n; ++i)
    {
        dic[str[i]].push_back(i);
    }
    int ans = 0;
    ans += count(dic,'R','G','B');
    ans += count(dic,'R','B','G');
    ans += count(dic,'G','R','B');
    ans += count(dic,'G','B','R');
    ans += count(dic,'B','R','G');
    ans += count(dic,'B','G','R');
    cout << ans << endl;
}