#include<iostream>
#include<string>

using namespace std;

int main(){
    int n;
    string S;
    cin >> n;
    cin >> S;
    int r, g, b;
    r = b = g = 0;
    int all = n * (n - 1) * (n - 2) / 6;
    for (int i = 0; i < n; i++)
    {
        if(S[i]=='R')
        {
            r++;    
        }
        else if (S[i]=='G')
        {
            g++;
        }
        else if (S[i]=='B')
        {
            b++;
        }
    }
    all -= r * (r - 1) * (n - r) / 2;
    all -= g * (g - 1) * (n - g) / 2;
    all -= b * (b - 1) * (n - b) / 2;
    all -= r * (r - 1) * (r - 2) / 6;
    all -= g * (g - 1) * (g - 2) / 6;
    all -= b * (b - 1) * (b - 2) / 6;

    for (int i = 0; i < S.size() - 2; i++)
    {
        for (int j = i+1; j < S.size(); j++)
        {
            if (S[i] != S[j])
            {
                int a = j - i;
                int k = i + 2 * a;
                if (k >= S.size())
                {
                    continue;
                }
                else
                {
                    if (S[j] != S[k] && S[k] != S[i])
                    {
                        all--;
                    }
                }
                
            }
        }
        
    }
    cout << all << endl;
    return 0;
}