#include <iostream>
#include <vector>

using namespace std;

typedef long long ll;

int main()
{
    ios_base::sync_with_stdio(0);
    string s;
    int n;
    cin >> n >> s;
    for (int i = 0; i < n; ++i)
    {
        if (s[i] == 'R')
            s[i] = '0';
        if (s[i] == 'G')
            s[i] = '1';
        if (s[i] == 'B')
            s[i] = '2';
    }
    ll odp = 0;
    vector< vector<ll> > il(n, vector<int>(3, 0));
    ++il[n - 1][s[n - 1] - '0'];
    for (int i = n - 2; i >= 0; --i)
    {
        il[i][0] = il[i + 1][0];
        il[i][1] = il[i + 1][1];
        il[i][2] = il[i + 1][2];
        ++il[i][s[i] - '0'];
    }
    for (int i = 0; i < n; ++i)
    {
        for (int j = i + 1; j < n - 1; ++j)
        {
            if (s[i] == s[j])
                continue;
            int r = 3 - (s[i] - '0') - (s[j] - '0');
            odp += il[j + 1][r];
            if (j + (j - i) < n && s[j + (j - i)] - '0' == r)
                --odp;
        }
    }
    cout << odp;
    return 0;
}
