#include <iostream>
#include <vector>

int main(int argc, char **argv)
{
    unsigned int N;
    std::string S;
    std::cin >> N >> S;

    int r, g, b;
    for(unsigned int i = 0; i < N; i++){
        if(S.at(i) == 'R') r++;
        if(S.at(i) == 'G') g++;
        if(S.at(i) == 'B') b++;
    }
    
    int sum = r * g * b;

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

    std::cout << sum << std::endl;
    
}
