#include <bits/stdc++.h>
using namespace std;

int main() {
    int N;
    cin >> N;
    string S;
    cin >> S;
    int R = 0; int G = 0; int B = 0;
    R = count(S.begin(), S.end(), 'R');
    G = count(S.begin(), S.end(), 'G');
    B = count(S.begin(), S.end(), 'B');
    long long int count = 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[i] != S[j] && S[i] != S[k] && S[j] != S[k]) {
                count--;
            }
        }
    }
    cout << count << endl;
    return 0;
}
