#include <bits/stdc++.h>
#include <numeric>
using namespace std;
#define ll long long
#define mod 100000007
#define rep(i, n) for (int i = 0; i < n; ++i)
ll lcm(ll a, ll b)
{
    return a * b / __gcd(a, b);
}

int main()
{
    int N;
    cin >> N;
    string S;
    cin >> S;
    int R, G, B;
    R = G = B = 0;
    for (int i = 0; i < N; i++)
    {
        if(S[i] =='R'){
            R++;
        }
        else if(S[i] == 'B'){
            B++;
        }
        else{
            G++;
        }
    }
    ll ans = R*B*G;
    for (int i = 0; i < N;i++)
    {
        for (int j = i+1; j < N;j++)
        {
            int k = 2 * j - i;
            if(k > N - 1){
                break;
            }
            if(S[i] != S[j] && S[j] != S[k] && S[i] != S[k]){
                ans--;
            }
        }
    }
    cout << ans << endl;
}
