#include<bits/stdc++.h>
using namespace std;
int main () {
    ios_base::sync_with_stdio(false);
    long long ans = 0;
    int N;
    string S;
    cin>>N>>S;
    int r = 0, g = 0, b = 0;
    for(int i=0;i<N;i++) {
        if (S[i] == 'R') r++;
        if (S[i] == 'G') g++;
        if (S[i] == 'B') b++;
    }
 
    int rgb = 0;
    for(int i=0;i<N;i++) {
        for(int j=0;j<N;j++) {
            int k = i + 2 * j;
            if (k >= N) break;
            if (S[i] != S[i + j] && S[i] != S[k] && S[i + j] != S[k]) rgb++;
        }
    }
    ans = (long long)r*g*b-rgb;
    cout<<ans<<"\n";
    return 0;
}