#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define _GLIBCXX_DEBUG
#define rep(i, c) for (int i = 0; i < (int)c; i++)
#define debug(x) cout << #x << " is " << x << endl

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

    int R;
    int G;
    int B;

    for (int i = 0; i < S.size(); i++)
    {
        if (S.at(i) == 'R')
        {
            R += 1;
        }
        else if (S.at(i) == 'G')
        {
            G += 1;
        }
        else
        {
            B += 1;
        }
    }

    ll ans = R * G * B;

    for (int i = 0; i < N - 2; i++)
    {
        for (int j = i + 1; j < N - 1; j++)
        {
            int k = 2 * j - i;
            if (k < N && S.at(i) != S.at(j) && S.at(j) != S.at(k) && S.at(k) != S.at(i))
            {
                ans -= 1;
            }
        }
    }

    cout << ans << endl;
}