#include <bits/stdc++.h>
#include <numeric>
#define ll long long
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

using namespace std;

//#define DEBUG

#ifdef DEBUG
#define PRINT(A) std::cout << (#A) << ":" << (A) << std::endl;
#else
#define PRINT(A)
#endif



int main() {
    int N; cin >> N;
    string S; cin >> S;
    int Rcount = 0, Gcount = 0, Bcount = 0;
    for(int i = 0; i < N; i++){
        char RGB = S[i];
        if(RGB == 'R'){
            Rcount ++;
        }
        else if(RGB == 'G'){
            Gcount ++;
        }
        else if(RGB == 'B'){
            Bcount ++;
        }
    }
    PRINT(Rcount)
    PRINT(Gcount)
    PRINT(Bcount)

    ll sum = Rcount*Gcount*Bcount;

    for(int i = 0; i < N; i++){
        for(int j = i; j < N; j++){
            if(-i+j*2 >= N) continue;
            char first = S[i];
            char second = S[j];
            char third = S[-i+j*2];
            if(first != second && second != third && third != first){
                sum --;
                // PRINT(first)
                // PRINT(second)
                // PRINT(third)
                PRINT(i)
                PRINT(j)
                PRINT(2*j-i)
            }
        }
    }
   cout << sum << endl;
   
}
